github.com/yoctocloud/packer@v0.6.2-0.20160520224004-e11a0a18423f/website/source/docs/builders/virtualbox-ovf.html.md (about) 1 --- 2 description: | 3 This VirtualBox Packer builder is able to create VirtualBox virtual machines and 4 export them in the OVF format, starting from an existing OVF/OVA (exported 5 virtual machine image). 6 layout: docs 7 page_title: 'VirtualBox Builder (from an OVF/OVA)' 8 ... 9 10 # VirtualBox Builder (from an OVF/OVA) 11 12 Type: `virtualbox-ovf` 13 14 This VirtualBox Packer builder is able to create 15 [VirtualBox](https://www.virtualbox.org/) virtual machines and export them in 16 the OVF format, starting from an existing OVF/OVA (exported virtual machine 17 image). 18 19 When exporting from VirtualBox make sure to choose OVF Version 2, since Version 20 1 is not compatible and will generate errors like this: 21 22 ==> virtualbox-ovf: Progress state: VBOX_E_FILE_ERROR 23 ==> virtualbox-ovf: VBoxManage: error: Appliance read failed 24 ==> virtualbox-ovf: VBoxManage: error: Error reading "source.ova": element "Section" has no "type" attribute, line 21 25 ==> virtualbox-ovf: VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Appliance, interface IAppliance 26 ==> virtualbox-ovf: VBoxManage: error: Context: "int handleImportAppliance(HandlerArg*)" at line 304 of file VBoxManageAppliance.cpp 27 28 The builder builds a virtual machine by importing an existing OVF or OVA file. 29 It then boots this image, runs provisioners on this new VM, and exports that VM 30 to create the image. The imported machine is deleted prior to finishing the 31 build. 32 33 ## Basic Example 34 35 Here is a basic example. This example is functional if you have an OVF matching 36 the settings here. 37 38 ``` {.javascript} 39 { 40 "type": "virtualbox-ovf", 41 "source_path": "source.ovf", 42 "ssh_username": "packer", 43 "ssh_password": "packer", 44 "shutdown_command": "echo 'packer' | sudo -S shutdown -P now" 45 } 46 ``` 47 48 It is important to add a `shutdown_command`. By default Packer halts the virtual 49 machine and the file system may not be sync'd. Thus, changes made in a 50 provisioner might not be saved. 51 52 ## Configuration Reference 53 54 There are many configuration options available for the VirtualBox builder. They 55 are organized below into two categories: required and optional. Within each 56 category, the available options are alphabetized and described. 57 58 In addition to the options listed here, a 59 [communicator](/docs/templates/communicator.html) can be configured for this 60 builder. 61 62 ### Required: 63 64 - `source_path` (string) - The path to an OVF or OVA file that acts as the 65 source of this build. 66 67 - `ssh_username` (string) - The username to use to SSH into the machine once 68 the OS is installed. 69 70 ### Optional: 71 72 - `boot_command` (array of strings) - This is an array of commands to type 73 when the virtual machine is first booted. The goal of these commands should 74 be to type just enough to initialize the operating system installer. Special 75 keys can be typed as well, and are covered in the section below on the 76 boot command. If this is not specified, it is assumed the installer will 77 start itself. 78 79 - `boot_wait` (string) - The time to wait after booting the initial virtual 80 machine before typing the `boot_command`. The value of this should be 81 a duration. Examples are "5s" and "1m30s" which will cause Packer to wait 82 five seconds and one minute 30 seconds, respectively. If this isn't 83 specified, the default is 10 seconds. 84 85 - `export_opts` (array of strings) - Additional options to pass to the 86 `VBoxManage export`. This can be useful for passing product information to 87 include in the resulting appliance file. 88 89 - `floppy_files` (array of strings) - A list of files to place onto a floppy 90 disk that is attached when the VM is booted. This is most useful for 91 unattended Windows installs, which look for an `Autounattend.xml` file on 92 removable media. By default, no floppy will be attached. All files listed in 93 this setting get placed into the root directory of the floppy and the floppy 94 is attached as the first floppy device. Currently, no support exists for 95 creating sub-directories on the floppy. Wildcard characters (\*, ?, 96 and \[\]) are allowed. Directory names are also allowed, which will add all 97 the files found in the directory to the floppy. 98 99 - `format` (string) - Either "ovf" or "ova", this specifies the output format 100 of the exported virtual machine. This defaults to "ovf". 101 102 - `guest_additions_mode` (string) - The method by which guest additions are 103 made available to the guest for installation. Valid options are "upload", 104 "attach", or "disable". If the mode is "attach" the guest additions ISO will 105 be attached as a CD device to the virtual machine. If the mode is "upload" 106 the guest additions ISO will be uploaded to the path specified by 107 `guest_additions_path`. The default value is "upload". If "disable" is used, 108 guest additions won't be downloaded, either. 109 110 - `guest_additions_path` (string) - The path on the guest virtual machine 111 where the VirtualBox guest additions ISO will be uploaded. By default this 112 is "VBoxGuestAdditions.iso" which should upload into the login directory of 113 the user. This is a [configuration 114 template](/docs/templates/configuration-templates.html) where the `Version` 115 variable is replaced with the VirtualBox version. 116 117 - `guest_additions_sha256` (string) - The SHA256 checksum of the guest 118 additions ISO that will be uploaded to the guest VM. By default the 119 checksums will be downloaded from the VirtualBox website, so this only needs 120 to be set if you want to be explicit about the checksum. 121 122 - `guest_additions_url` (string) - The URL to the guest additions ISO 123 to upload. This can also be a file URL if the ISO is at a local path. By 124 default the VirtualBox builder will go and download the proper guest 125 additions ISO from the internet. 126 127 - `headless` (boolean) - Packer defaults to building VirtualBox virtual 128 machines by launching a GUI that shows the console of the machine 129 being built. When this value is set to true, the machine will start without 130 a console. 131 132 - `http_directory` (string) - Path to a directory to serve using an 133 HTTP server. The files in this directory will be available over HTTP that 134 will be requestable from the virtual machine. This is useful for hosting 135 kickstart files and so on. By default this is "", which means no HTTP server 136 will be started. The address and port of the HTTP server will be available 137 as variables in `boot_command`. This is covered in more detail below. 138 139 - `http_port_min` and `http_port_max` (integer) - These are the minimum and 140 maximum port to use for the HTTP server started to serve the 141 `http_directory`. Because Packer often runs in parallel, Packer will choose 142 a randomly available port in this range to run the HTTP server. If you want 143 to force the HTTP server to be on one port, make this minimum and maximum 144 port the same. By default the values are 8000 and 9000, respectively. 145 146 - `import_flags` (array of strings) - Additional flags to pass to 147 `VBoxManage import`. This can be used to add additional command-line flags 148 such as `--eula-accept` to accept a EULA in the OVF. 149 150 - `import_opts` (string) - Additional options to pass to the 151 `VBoxManage import`. This can be useful for passing "keepallmacs" or 152 "keepnatmacs" options for existing ovf images. 153 154 - `output_directory` (string) - This is the path to the directory where the 155 resulting virtual machine will be created. This may be relative or absolute. 156 If relative, the path is relative to the working directory when `packer` 157 is executed. This directory must not exist or be empty prior to running 158 the builder. By default this is "output-BUILDNAME" where "BUILDNAME" is the 159 name of the build. 160 161 - `shutdown_command` (string) - The command to use to gracefully shut down the 162 machine once all the provisioning is done. By default this is an empty 163 string, which tells Packer to just forcefully shut down the machine unless a 164 shutdown command takes place inside script so this may safely be omitted. If 165 one or more scripts require a reboot it is suggested to leave this blank 166 since reboots may fail and specify the final shutdown command in your 167 last script. 168 169 - `shutdown_timeout` (string) - The amount of time to wait after executing the 170 `shutdown_command` for the virtual machine to actually shut down. If it 171 doesn't shut down in this time, it is an error. By default, the timeout is 172 "5m", or five minutes. 173 174 - `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and 175 maximum port to use for the SSH port on the host machine which is forwarded 176 to the SSH port on the guest machine. Because Packer often runs in parallel, 177 Packer will choose a randomly available port in this range to use as the 178 host port. 179 180 - `ssh_skip_nat_mapping` (boolean) - Defaults to false. When enabled, Packer 181 does not setup forwarded port mapping for SSH requests and uses `ssh_port` 182 on the host to communicate to the virtual machine 183 184 - `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to 185 execute in order to further customize the virtual machine being created. The 186 value of this is an array of commands to execute. The commands are executed 187 in the order defined in the template. For each command, the command is 188 defined itself as an array of strings, where each string represents a single 189 argument on the command-line to `VBoxManage` (but excluding 190 `VBoxManage` itself). Each arg is treated as a [configuration 191 template](/docs/templates/configuration-templates.html), where the `Name` 192 variable is replaced with the VM name. More details on how to use 193 `VBoxManage` are below. 194 195 - `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`, 196 except that it is run after the virtual machine is shutdown, and before the 197 virtual machine is exported. 198 199 - `virtualbox_version_file` (string) - The path within the virtual machine to 200 upload a file that contains the VirtualBox version that was used to create 201 the machine. This information can be useful for provisioning. By default 202 this is ".vbox\_version", which will generally be upload it into the 203 home directory. 204 205 - `vm_name` (string) - This is the name of the virtual machine when it is 206 imported as well as the name of the OVF file when the virtual machine 207 is exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is the 208 name of the build. 209 210 - `vrdp_port_min` and `vrdp_port_max` (integer) - The minimum and maximum port 211 to use for VRDP access to the virtual machine. Packer uses a randomly chosen 212 port in this range that appears available. By default this is 5900 to 6000. 213 The minimum and maximum ports are inclusive. 214 215 ## Guest Additions 216 217 Packer will automatically download the proper guest additions for the version of 218 VirtualBox that is running and upload those guest additions into the virtual 219 machine so that provisioners can easily install them. 220 221 Packer downloads the guest additions from the official VirtualBox website, and 222 verifies the file with the official checksums released by VirtualBox. 223 224 After the virtual machine is up and the operating system is installed, Packer 225 uploads the guest additions into the virtual machine. The path where they are 226 uploaded is controllable by `guest_additions_path`, and defaults to 227 "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home 228 directory of the SSH user. 229 230 ## VBoxManage Commands 231 232 In order to perform extra customization of the virtual machine, a template can 233 define extra calls to `VBoxManage` to perform. 234 [VBoxManage](https://www.virtualbox.org/manual/ch08.html) is the command-line 235 interface to VirtualBox where you can completely control VirtualBox. It can be 236 used to do things such as set RAM, CPUs, etc. 237 238 Extra VBoxManage commands are defined in the template in the `vboxmanage` 239 section. An example is shown below that sets the memory and number of CPUs 240 within the virtual machine: 241 242 ``` {.javascript} 243 { 244 "vboxmanage": [ 245 ["modifyvm", "{{.Name}}", "--memory", "1024"], 246 ["modifyvm", "{{.Name}}", "--cpus", "2"] 247 ] 248 } 249 ``` 250 251 The value of `vboxmanage` is an array of commands to execute. These commands are 252 executed in the order defined. So in the above example, the memory will be set 253 followed by the CPUs. 254 255 Each command itself is an array of strings, where each string is an argument to 256 `VBoxManage`. Each argument is treated as a [configuration 257 template](/docs/templates/configuration-templates.html). The only available 258 variable is `Name` which is replaced with the unique name of the VM, which is 259 required for many VBoxManage calls.