github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/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 * `boot_command` (array of strings) - This is an array of commands to type 56 when the virtual machine is first booted. The goal of these commands should 57 be to type just enough to initialize the operating system installer. Special 58 keys can be typed as well, and are covered in the section below on the boot 59 command. If this is not specified, it is assumed the installer will start 60 itself. 61 62 * `boot_wait` (string) - The time to wait after booting the initial virtual 63 machine before typing the `boot_command`. The value of this should be 64 a duration. Examples are "5s" and "1m30s" which will cause Packer to wait 65 five seconds and one minute 30 seconds, respectively. If this isn't specified, 66 the default is 10 seconds. 67 68 * `export_opts` (array of strings) - Additional options to pass to the `VBoxManage export`. 69 This can be useful for passing product information to include in the resulting 70 appliance file. 71 72 * `floppy_files` (array of strings) - A list of files to place onto a floppy 73 disk that is attached when the VM is booted. This is most useful 74 for unattended Windows installs, which look for an `Autounattend.xml` file 75 on removable media. By default, no floppy will be attached. All files 76 listed in this setting get placed into the root directory of the floppy 77 and the floppy is attached as the first floppy device. Currently, no 78 support exists for creating sub-directories on the floppy. Wildcard 79 characters (*, ?, and []) are allowed. Directory names are also allowed, 80 which will add all the files found in the directory to the floppy. 81 82 * `format` (string) - Either "ovf" or "ova", this specifies the output 83 format of the exported virtual machine. This defaults to "ovf". 84 85 * `guest_additions_mode` (string) - The method by which guest additions 86 are made available to the guest for installation. Valid options are 87 "upload", "attach", or "disable". The functions of each of these should be 88 self-explanatory. The default value is "upload". If "disable" is used, 89 guest additions won't be downloaded, either. 90 91 * `guest_additions_path` (string) - The path on the guest virtual machine 92 where the VirtualBox guest additions ISO will be uploaded. By default this 93 is "VBoxGuestAdditions.iso" which should upload into the login directory 94 of the user. This is a [configuration template](/docs/templates/configuration-templates.html) 95 where the `Version` variable is replaced with the VirtualBox version. 96 97 * `guest_additions_sha256` (string) - The SHA256 checksum of the guest 98 additions ISO that will be uploaded to the guest VM. By default the 99 checksums will be downloaded from the VirtualBox website, so this only 100 needs to be set if you want to be explicit about the checksum. 101 102 * `guest_additions_url` (string) - The URL to the guest additions ISO 103 to upload. This can also be a file URL if the ISO is at a local path. 104 By default the VirtualBox builder will go and download the proper 105 guest additions ISO from the internet. 106 107 * `headless` (boolean) - Packer defaults to building VirtualBox 108 virtual machines by launching a GUI that shows the console of the 109 machine being built. When this value is set to true, the machine will 110 start without a console. 111 112 * `http_directory` (string) - Path to a directory to serve using an HTTP 113 server. The files in this directory will be available over HTTP that will 114 be requestable from the virtual machine. This is useful for hosting 115 kickstart files and so on. By default this is "", which means no HTTP 116 server will be started. The address and port of the HTTP server will be 117 available as variables in `boot_command`. This is covered in more detail 118 below. 119 120 * `http_port_min` and `http_port_max` (integer) - These are the minimum and 121 maximum port to use for the HTTP server started to serve the `http_directory`. 122 Because Packer often runs in parallel, Packer will choose a randomly available 123 port in this range to run the HTTP server. If you want to force the HTTP 124 server to be on one port, make this minimum and maximum port the same. 125 By default the values are 8000 and 9000, respectively. 126 127 * `import_flags` (array of strings) - Additional flags to pass to 128 `VBoxManage import`. This can be used to add additional command-line flags 129 such as `--eula-accept` to accept a EULA in the OVF. 130 131 * `import_opts` (string) - Additional options to pass to the `VBoxManage import`. 132 This can be useful for passing "keepallmacs" or "keepnatmacs" options for existing 133 ovf images. 134 135 * `output_directory` (string) - This is the path to the directory where the 136 resulting virtual machine will be created. This may be relative or absolute. 137 If relative, the path is relative to the working directory when `packer` 138 is executed. This directory must not exist or be empty prior to running the builder. 139 By default this is "output-BUILDNAME" where "BUILDNAME" is the name 140 of the build. 141 142 * `shutdown_command` (string) - The command to use to gracefully shut down 143 the machine once all the provisioning is done. By default this is an empty 144 string, which tells Packer to just forcefully shut down the machine. 145 146 * `shutdown_timeout` (string) - The amount of time to wait after executing 147 the `shutdown_command` for the virtual machine to actually shut down. 148 If it doesn't shut down in this time, it is an error. By default, the timeout 149 is "5m", or five minutes. 150 151 * `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and 152 maximum port to use for the SSH port on the host machine which is forwarded 153 to the SSH port on the guest machine. Because Packer often runs in parallel, 154 Packer will choose a randomly available port in this range to use as the 155 host port. 156 157 * `ssh_key_path` (string) - Path to a private key to use for authenticating 158 with SSH. By default this is not set (key-based auth won't be used). 159 The associated public key is expected to already be configured on the 160 VM being prepared by some other process (kickstart, etc.). 161 162 * `ssh_password` (string) - The password for `ssh_username` to use to 163 authenticate with SSH. By default this is the empty string. 164 165 * `ssh_port` (integer) - The port that SSH will be listening on in the guest 166 virtual machine. By default this is 22. 167 168 * `ssh_wait_timeout` (string) - The duration to wait for SSH to become 169 available. By default this is "20m", or 20 minutes. Note that this should 170 be quite long since the timer begins as soon as the virtual machine is booted. 171 172 * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to 173 execute in order to further customize the virtual machine being created. 174 The value of this is an array of commands to execute. The commands are executed 175 in the order defined in the template. For each command, the command is 176 defined itself as an array of strings, where each string represents a single 177 argument on the command-line to `VBoxManage` (but excluding `VBoxManage` 178 itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html), 179 where the `Name` variable is replaced with the VM name. More details on how 180 to use `VBoxManage` are below. 181 182 * `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`, 183 except that it is run after the virtual machine is shutdown, and before the 184 virtual machine is exported. 185 186 * `virtualbox_version_file` (string) - The path within the virtual machine 187 to upload a file that contains the VirtualBox version that was used to 188 create the machine. This information can be useful for provisioning. 189 By default this is ".vbox_version", which will generally be upload it into 190 the home directory. 191 192 * `vm_name` (string) - This is the name of the virtual machine when it is 193 imported as well as the name of the OVF file when the virtual machine is 194 exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is 195 the name of the build. 196 197 ## Guest Additions 198 199 Packer will automatically download the proper guest additions for the 200 version of VirtualBox that is running and upload those guest additions into 201 the virtual machine so that provisioners can easily install them. 202 203 Packer downloads the guest additions from the official VirtualBox website, 204 and verifies the file with the official checksums released by VirtualBox. 205 206 After the virtual machine is up and the operating system is installed, 207 Packer uploads the guest additions into the virtual machine. The path where 208 they are uploaded is controllable by `guest_additions_path`, and defaults 209 to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the 210 home directory of the SSH user. 211 212 ## VBoxManage Commands 213 214 In order to perform extra customization of the virtual machine, a template 215 can define extra calls to `VBoxManage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html) 216 is the command-line interface to VirtualBox where you can completely control 217 VirtualBox. It can be used to do things such as set RAM, CPUs, etc. 218 219 Extra VBoxManage commands are defined in the template in the `vboxmanage` section. 220 An example is shown below that sets the memory and number of CPUs within the 221 virtual machine: 222 223 <pre class="prettyprint"> 224 { 225 "vboxmanage": [ 226 ["modifyvm", "{{.Name}}", "--memory", "1024"], 227 ["modifyvm", "{{.Name}}", "--cpus", "2"] 228 ] 229 } 230 </pre> 231 232 The value of `vboxmanage` is an array of commands to execute. These commands 233 are executed in the order defined. So in the above example, the memory will be 234 set followed by the CPUs. 235 236 Each command itself is an array of strings, where each string is an argument 237 to `VBoxManage`. Each argument is treated as a 238 [configuration template](/docs/templates/configuration-templates.html). 239 The only available variable is `Name` which is replaced with the unique 240 name of the VM, which is required for many VBoxManage calls.