github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/website/source/docs/builders/virtualbox-iso.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "VirtualBox Builder (from an ISO)" 4 --- 5 6 # VirtualBox Builder (from an ISO) 7 8 Type: `virtualbox-iso` 9 10 The 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 ISO image. 13 14 The builder builds a virtual machine by creating a new virtual machine 15 from scratch, booting it, installing an OS, provisioning software within 16 the OS, then shutting it down. The result of the VirtualBox builder is a directory 17 containing all the files necessary to run the virtual machine portably. 18 19 ## Basic Example 20 21 Here is a basic example. This example is not functional. It will start the 22 OS installer but then fail because we don't provide the preseed file for 23 Ubuntu to self-install. Still, the example serves to show the basic configuration: 24 25 <pre class="prettyprint"> 26 { 27 "type": "virtualbox-iso", 28 "guest_os_type": "Ubuntu_64", 29 "iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso", 30 "iso_checksum": "769474248a3897f4865817446f9a4a53", 31 "iso_checksum_type": "md5", 32 "ssh_username": "packer", 33 "ssh_password": "packer", 34 "ssh_wait_timeout": "30s", 35 "shutdown_command": "echo 'packer' | sudo -S shutdown -P now" 36 } 37 </pre> 38 39 It is important to add a `shutdown_command`. By default Packer halts the 40 virtual machine and the file system may not be sync'd. Thus, changes made in a 41 provisioner might not be saved. 42 43 ## Configuration Reference 44 45 There are many configuration options available for the VirtualBox builder. 46 They are organized below into two categories: required and optional. Within 47 each category, the available options are alphabetized and described. 48 49 ### Required: 50 51 * `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO 52 files are so large, this is required and Packer will verify it prior 53 to booting a virtual machine with the ISO attached. The type of the 54 checksum is specified with `iso_checksum_type`, documented below. 55 56 * `iso_checksum_type` (string) - The type of the checksum specified in 57 `iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or 58 "sha512" currently. While "none" will skip checksumming, this is not 59 recommended since ISO files are generally large and corruption does happen 60 from time to time. 61 62 * `iso_url` (string) - A URL to the ISO containing the installation image. 63 This URL can be either an HTTP URL or a file URL (or path to a file). 64 If this is an HTTP URL, Packer will download it and cache it between 65 runs. 66 67 * `ssh_username` (string) - The username to use to SSH into the machine 68 once 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 boot 76 command. If this is not specified, it is assumed the installer will start 77 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 specified, 83 the default is 10 seconds. 84 85 * `disk_size` (integer) - The size, in megabytes, of the hard disk to create 86 for the VM. By default, this is 40000 (about 40 GB). 87 88 * `export_opts` (array of strings) - Additional options to pass to the `VBoxManage export`. 89 This can be useful for passing product information to include in the resulting 90 appliance file. 91 92 * `floppy_files` (array of strings) - A list of files to place onto a floppy 93 disk that is attached when the VM is booted. This is most useful 94 for unattended Windows installs, which look for an `Autounattend.xml` file 95 on removable media. By default, no floppy will be attached. All files 96 listed in this setting get placed into the root directory of the floppy 97 and the floppy is attached as the first floppy device. Currently, no 98 support exists for creating sub-directories on the floppy. Wildcard 99 characters (*, ?, and []) are allowed. Directory names are also allowed, 100 which will add all the files found in the directory to the floppy. 101 102 * `format` (string) - Either "ovf" or "ova", this specifies the output 103 format of the exported virtual machine. This defaults to "ovf". 104 105 * `guest_additions_mode` (string) - The method by which guest additions 106 are made available to the guest for installation. Valid options are 107 "upload", "attach", or "disable". The functions of each of these should be 108 self-explanatory. The default value is "upload". If "disable" is used, 109 guest additions won't be downloaded, either. 110 111 * `guest_additions_path` (string) - The path on the guest virtual machine 112 where the VirtualBox guest additions ISO will be uploaded. By default this 113 is "VBoxGuestAdditions.iso" which should upload into the login directory 114 of the user. This is a [configuration template](/docs/templates/configuration-templates.html) 115 where the `Version` 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 120 needs 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. 124 By default, the VirtualBox builder will attempt to find the guest additions 125 ISO on the local file system. If it is not available locally, the builder 126 will download the proper guest additions ISO from the internet. 127 128 * `guest_os_type` (string) - The guest OS type being installed. By default 129 this is "other", but you can get _dramatic_ performance improvements by 130 setting this to the proper value. To view all available values for this 131 run `VBoxManage list ostypes`. Setting the correct value hints to VirtualBox 132 how to optimize the virtual hardware to work best with that operating 133 system. 134 135 * `hard_drive_interface` (string) - The type of controller that the primary 136 hard drive is attached to, defaults to "ide". When set to "sata", the 137 drive is attached to an AHCI SATA controller. 138 139 * `headless` (boolean) - Packer defaults to building VirtualBox 140 virtual machines by launching a GUI that shows the console of the 141 machine being built. When this value is set to true, the machine will 142 start without a console. 143 144 * `http_directory` (string) - Path to a directory to serve using an HTTP 145 server. The files in this directory will be available over HTTP that will 146 be requestable from the virtual machine. This is useful for hosting 147 kickstart files and so on. By default this is "", which means no HTTP 148 server will be started. The address and port of the HTTP server will be 149 available as variables in `boot_command`. This is covered in more detail 150 below. 151 152 * `http_port_min` and `http_port_max` (integer) - These are the minimum and 153 maximum port to use for the HTTP server started to serve the `http_directory`. 154 Because Packer often runs in parallel, Packer will choose a randomly available 155 port in this range to run the HTTP server. If you want to force the HTTP 156 server to be on one port, make this minimum and maximum port the same. 157 By default the values are 8000 and 9000, respectively. 158 159 * `iso_interface` (string) - The type of controller that the ISO is attached 160 to, defaults to "ide". When set to "sata", the drive is attached to an 161 AHCI SATA controller. 162 163 * `iso_urls` (array of strings) - Multiple URLs for the ISO to download. 164 Packer will try these in order. If anything goes wrong attempting to download 165 or while downloading a single URL, it will move on to the next. All URLs 166 must point to the same file (same checksum). By default this is empty 167 and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified. 168 169 * `output_directory` (string) - This is the path to the directory where the 170 resulting virtual machine will be created. This may be relative or absolute. 171 If relative, the path is relative to the working directory when `packer` 172 is executed. This directory must not exist or be empty prior to running the builder. 173 By default this is "output-BUILDNAME" where "BUILDNAME" is the name 174 of the build. 175 176 * `shutdown_command` (string) - The command to use to gracefully shut down 177 the machine once all the provisioning is done. By default this is an empty 178 string, which tells Packer to just forcefully shut down the machine. 179 180 * `shutdown_timeout` (string) - The amount of time to wait after executing 181 the `shutdown_command` for the virtual machine to actually shut down. 182 If it doesn't shut down in this time, it is an error. By default, the timeout 183 is "5m", or five minutes. 184 185 * `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and 186 maximum port to use for the SSH port on the host machine which is forwarded 187 to the SSH port on the guest machine. Because Packer often runs in parallel, 188 Packer will choose a randomly available port in this range to use as the 189 host port. 190 191 * `ssh_key_path` (string) - Path to a private key to use for authenticating 192 with SSH. By default this is not set (key-based auth won't be used). 193 The associated public key is expected to already be configured on the 194 VM being prepared by some other process (kickstart, etc.). 195 196 * `ssh_password` (string) - The password for `ssh_username` to use to 197 authenticate with SSH. By default this is the empty string. 198 199 * `ssh_port` (integer) - The port that SSH will be listening on in the guest 200 virtual machine. By default this is 22. 201 202 * `ssh_wait_timeout` (string) - The duration to wait for SSH to become 203 available. By default this is "20m", or 20 minutes. Note that this should 204 be quite long since the timer begins as soon as the virtual machine is booted. 205 206 * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to 207 execute in order to further customize the virtual machine being created. 208 The value of this is an array of commands to execute. The commands are executed 209 in the order defined in the template. For each command, the command is 210 defined itself as an array of strings, where each string represents a single 211 argument on the command-line to `VBoxManage` (but excluding `VBoxManage` 212 itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html), 213 where the `Name` variable is replaced with the VM name. More details on how 214 to use `VBoxManage` are below. 215 216 * `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`, 217 except that it is run after the virtual machine is shutdown, and before the 218 virtual machine is exported. 219 220 * `virtualbox_version_file` (string) - The path within the virtual machine 221 to upload a file that contains the VirtualBox version that was used to 222 create the machine. This information can be useful for provisioning. 223 By default this is ".vbox_version", which will generally be upload it into 224 the home directory. 225 226 * `vm_name` (string) - This is the name of the OVF file for the new virtual 227 machine, without the file extension. By default this is "packer-BUILDNAME", 228 where "BUILDNAME" is the name of the build. 229 230 ## Boot Command 231 232 The `boot_command` configuration is very important: it specifies the keys 233 to type when the virtual machine is first booted in order to start the 234 OS installer. This command is typed after `boot_wait`, which gives the 235 virtual machine some time to actually load the ISO. 236 237 As documented above, the `boot_command` is an array of strings. The 238 strings are all typed in sequence. It is an array only to improve readability 239 within the template. 240 241 The boot command is "typed" character for character over a VNC connection 242 to the machine, simulating a human actually typing the keyboard. There are 243 a set of special keys available. If these are in your boot command, they 244 will be replaced by the proper key: 245 246 * `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress. 247 248 * `<esc>` - Simulates pressing the escape key. 249 250 * `<tab>` - Simulates pressing the tab key. 251 252 * `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending any additional keys. This 253 is useful if you have to generally wait for the UI to update before typing more. 254 255 In addition to the special keys, each command to type is treated as a 256 [configuration template](/docs/templates/configuration-templates.html). 257 The available variables are: 258 259 * `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server 260 that is started serving the directory specified by the `http_directory` 261 configuration parameter. If `http_directory` isn't specified, these will 262 be blank! 263 264 Example boot command. This is actually a working boot command used to start 265 an Ubuntu 12.04 installer: 266 267 <pre class="prettyprint"> 268 [ 269 "<esc><esc><enter><wait>", 270 "/install/vmlinuz noapic ", 271 "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", 272 "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", 273 "hostname={{ .Name }} ", 274 "fb=false debconf/frontend=noninteractive ", 275 "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", 276 "keyboard-configuration/variant=USA console-setup/ask_detect=false ", 277 "initrd=/install/initrd.gz -- <enter>" 278 ] 279 </pre> 280 281 ## Guest Additions 282 283 Packer will automatically download the proper guest additions for the 284 version of VirtualBox that is running and upload those guest additions into 285 the virtual machine so that provisioners can easily install them. 286 287 Packer downloads the guest additions from the official VirtualBox website, 288 and verifies the file with the official checksums released by VirtualBox. 289 290 After the virtual machine is up and the operating system is installed, 291 Packer uploads the guest additions into the virtual machine. The path where 292 they are uploaded is controllable by `guest_additions_path`, and defaults 293 to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the 294 home directory of the SSH user. 295 296 ## VBoxManage Commands 297 298 In order to perform extra customization of the virtual machine, a template 299 can define extra calls to `VBoxManage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html) 300 is the command-line interface to VirtualBox where you can completely control 301 VirtualBox. It can be used to do things such as set RAM, CPUs, etc. 302 303 Extra VBoxManage commands are defined in the template in the `vboxmanage` section. 304 An example is shown below that sets the memory and number of CPUs within the 305 virtual machine: 306 307 <pre class="prettyprint"> 308 { 309 "vboxmanage": [ 310 ["modifyvm", "{{.Name}}", "--memory", "1024"], 311 ["modifyvm", "{{.Name}}", "--cpus", "2"] 312 ] 313 } 314 </pre> 315 316 The value of `vboxmanage` is an array of commands to execute. These commands 317 are executed in the order defined. So in the above example, the memory will be 318 set followed by the CPUs. 319 320 Each command itself is an array of strings, where each string is an argument 321 to `VBoxManage`. Each argument is treated as a 322 [configuration template](/docs/templates/configuration-templates.html). 323 The only available variable is `Name` which is replaced with the unique 324 name of the VM, which is required for many VBoxManage calls.