github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/website/source/docs/builders/virtualbox-ovf.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "VirtualBox Builder (from an OVF/OVA)" 4 --- 5 6 # VirtualBox Builder (from an OVF/OVA) 7 8 Type: `virtualbox-ovf` 9 10 This VirtualBox builder is able to create [VirtualBox](https://www.virtualbox.org/) 11 virtual machines and export them in the OVF format, starting from an 12 existing OVF/OVA (exported virtual machine image). 13 14 The builder builds a virtual machine by importing an existing OVF or OVA 15 file. It then boots this image, runs provisioners on this new VM, and 16 exports that VM to create the image. The imported machine is deleted prior 17 to finishing the build. 18 19 ## Basic Example 20 21 Here is a basic example. This example is functional if you have an OVF matching 22 the settings here. 23 24 <pre class="prettyprint"> 25 { 26 "type": "virtualbox-ovf", 27 "source_path": "source.ovf", 28 "ssh_username": "packer", 29 "ssh_password": "packer", 30 "ssh_wait_timeout": "30s", 31 "shutdown_command": "echo 'packer' | sudo -S shutdown -P now" 32 } 33 </pre> 34 35 It is important to add a `shutdown_command`. By default Packer halts the 36 virtual machine and the file system may not be sync'd. Thus, changes made in a 37 provisioner might not be saved. 38 39 ## Configuration Reference 40 41 There are many configuration options available for the VirtualBox builder. 42 They are organized below into two categories: required and optional. Within 43 each category, the available options are alphabetized and described. 44 45 Required: 46 47 * `source_path` (string) - The path to an OVF or OVA file that acts as 48 the source of this build. 49 50 * `ssh_username` (string) - The username to use to SSH into the machine 51 once the OS is installed. 52 53 Optional: 54 55 * `floppy_files` (array of strings) - A list of files to put onto a floppy 56 disk that is attached when the VM is booted for the first time. This is 57 most useful for unattended Windows installs, which look for an 58 `Autounattend.xml` file on removable media. By default no floppy will 59 be attached. The files listed in this configuration will all be put 60 into the root directory of the floppy disk; sub-directories are not supported. 61 62 * `format` (string) - Either "ovf" or "ova", this specifies the output 63 format of the exported virtual machine. This defaults to "ovf". 64 65 * `guest_additions_mode` (string) - The method by which guest additions 66 are made available to the guest for installation. Valid options are 67 "upload", "attach", or "disable". The functions of each of these should be 68 self-explanatory. The default value is "upload". If "disable" is used, 69 guest additions won't be downloaded, either. 70 71 * `guest_additions_path` (string) - The path on the guest virtual machine 72 where the VirtualBox guest additions ISO will be uploaded. By default this 73 is "VBoxGuestAdditions.iso" which should upload into the login directory 74 of the user. This is a [configuration template](/docs/templates/configuration-templates.html) 75 where the `Version` variable is replaced with the VirtualBox version. 76 77 * `guest_additions_sha256` (string) - The SHA256 checksum of the guest 78 additions ISO that will be uploaded to the guest VM. By default the 79 checksums will be downloaded from the VirtualBox website, so this only 80 needs to be set if you want to be explicit about the checksum. 81 82 * `guest_additions_url` (string) - The URL to the guest additions ISO 83 to upload. This can also be a file URL if the ISO is at a local path. 84 By default the VirtualBox builder will go and download the proper 85 guest additions ISO from the internet. 86 87 * `headless` (bool) - Packer defaults to building VirtualBox 88 virtual machines by launching a GUI that shows the console of the 89 machine being built. When this value is set to true, the machine will 90 start without a console. 91 92 * `output_directory` (string) - This is the path to the directory where the 93 resulting virtual machine will be created. This may be relative or absolute. 94 If relative, the path is relative to the working directory when `packer` 95 is executed. This directory must not exist or be empty prior to running the builder. 96 By default this is "output-BUILDNAME" where "BUILDNAME" is the name 97 of the build. 98 99 * `shutdown_command` (string) - The command to use to gracefully shut down 100 the machine once all the provisioning is done. By default this is an empty 101 string, which tells Packer to just forcefully shut down the machine. 102 103 * `shutdown_timeout` (string) - The amount of time to wait after executing 104 the `shutdown_command` for the virtual machine to actually shut down. 105 If it doesn't shut down in this time, it is an error. By default, the timeout 106 is "5m", or five minutes. 107 108 * `ssh_host_port_min` and `ssh_host_port_max` (uint) - The minimum and 109 maximum port to use for the SSH port on the host machine which is forwarded 110 to the SSH port on the guest machine. Because Packer often runs in parallel, 111 Packer will choose a randomly available port in this range to use as the 112 host port. 113 114 * `ssh_key_path` (string) - Path to a private key to use for authenticating 115 with SSH. By default this is not set (key-based auth won't be used). 116 The associated public key is expected to already be configured on the 117 VM being prepared by some other process (kickstart, etc.). 118 119 * `ssh_password` (string) - The password for `ssh_username` to use to 120 authenticate with SSH. By default this is the empty string. 121 122 * `ssh_port` (int) - The port that SSH will be listening on in the guest 123 virtual machine. By default this is 22. 124 125 * `ssh_wait_timeout` (string) - The duration to wait for SSH to become 126 available. By default this is "20m", or 20 minutes. Note that this should 127 be quite long since the timer begins as soon as the virtual machine is booted. 128 129 * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to 130 execute in order to further customize the virtual machine being created. 131 The value of this is an array of commands to execute. The commands are executed 132 in the order defined in the template. For each command, the command is 133 defined itself as an array of strings, where each string represents a single 134 argument on the command-line to `VBoxManage` (but excluding `VBoxManage` 135 itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html), 136 where the `Name` variable is replaced with the VM name. More details on how 137 to use `VBoxManage` are below. 138 139 * `virtualbox_version_file` (string) - The path within the virtual machine 140 to upload a file that contains the VirtualBox version that was used to 141 create the machine. This information can be useful for provisioning. 142 By default this is ".vbox_version", which will generally upload it into 143 the home directory. 144 145 * `vm_name` (string) - This is the name of the virtual machine when it is 146 imported as well as the name of the OVF file when the virtual machine is 147 exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is 148 the name of the build. 149 150 ## Guest Additions 151 152 Packer will automatically download the proper guest additions for the 153 version of VirtualBox that is running and upload those guest additions into 154 the virtual machine so that provisioners can easily install them. 155 156 Packer downloads the guest additions from the official VirtualBox website, 157 and verifies the file with the official checksums released by VirtualBox. 158 159 After the virtual machine is up and the operating system is installed, 160 Packer uploads the guest additions into the virtual machine. The path where 161 they are uploaded is controllable by `guest_additions_path`, and defaults 162 to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the 163 home directory of the SSH user. 164 165 ## VBoxManage Commands 166 167 In order to perform extra customization of the virtual machine, a template 168 can define extra calls to `VBoxManage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html) 169 is the command-line interface to VirtualBox where you can completely control 170 VirtualBox. It can be used to do things such as set RAM, CPUs, etc. 171 172 Extra VBoxManage commands are defined in the template in the `vboxmanage` section. 173 An example is shown below that sets the memory and number of CPUs within the 174 virtual machine: 175 176 <pre class="prettyprint"> 177 { 178 "vboxmanage": [ 179 ["modifyvm", "{{.Name}}", "--memory", "1024"], 180 ["modifyvm", "{{.Name}}", "--cpus", "2"] 181 ] 182 } 183 </pre> 184 185 The value of `vboxmanage` is an array of commands to execute. These commands 186 are executed in the order defined. So in the above example, the memory will be 187 set followed by the CPUs. 188 189 Each command itself is an array of strings, where each string is an argument 190 to `VBoxManage`. Each argument is treated as a 191 [configuration template](/docs/templates/configuration-templates.html). 192 The only available variable is `Name` which is replaced with the unique 193 name of the VM, which is required for many VBoxManage calls.