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