github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/website/source/docs/builders/virtualbox-iso.html.md (about) 1 --- 2 description: | 3 The VirtualBox Packer builder is able to create VirtualBox virtual machines and 4 export them in the OVF format, starting from an ISO image. 5 layout: docs 6 page_title: 'VirtualBox Builder (from an ISO)' 7 ... 8 9 # VirtualBox Builder (from an ISO) 10 11 Type: `virtualbox-iso` 12 13 The VirtualBox Packer builder is able to create 14 [VirtualBox](https://www.virtualbox.org/) virtual machines and export them in 15 the OVF format, starting from an ISO image. 16 17 The builder builds a virtual machine by creating a new virtual machine from 18 scratch, booting it, installing an OS, provisioning software within the OS, then 19 shutting it down. The result of the VirtualBox builder is a directory containing 20 all the files necessary to run the virtual machine portably. 21 22 ## Basic Example 23 24 Here is a basic example. This example is not functional. It will start the OS 25 installer but then fail because we don't provide the preseed file for Ubuntu to 26 self-install. Still, the example serves to show the basic configuration: 27 28 ``` {.javascript} 29 { 30 "type": "virtualbox-iso", 31 "guest_os_type": "Ubuntu_64", 32 "iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso", 33 "iso_checksum": "769474248a3897f4865817446f9a4a53", 34 "iso_checksum_type": "md5", 35 "ssh_username": "packer", 36 "ssh_password": "packer", 37 "shutdown_command": "echo 'packer' | sudo -S shutdown -P now" 38 } 39 ``` 40 41 It is important to add a `shutdown_command`. By default Packer halts the virtual 42 machine and the file system may not be sync'd. Thus, changes made in a 43 provisioner might not be saved. 44 45 ## Configuration Reference 46 47 There are many configuration options available for the VirtualBox builder. They 48 are organized below into two categories: required and optional. Within each 49 category, the available options are alphabetized and described. 50 51 In addition to the options listed here, a 52 [communicator](/docs/templates/communicator.html) can be configured for this 53 builder. 54 55 ### Required: 56 57 - `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO 58 files are so large, this is required and Packer will verify it prior to 59 booting a virtual machine with the ISO attached. The type of the checksum is 60 specified with `iso_checksum_type`, documented below. At least one of 61 `iso_checksum` and `iso_checksum_url` must be defined. This has precedence 62 over `iso_checksum_url` type. 63 64 - `iso_checksum_type` (string) - The type of the checksum specified in 65 `iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or 66 "sha512" currently. While "none" will skip checksumming, this is not 67 recommended since ISO files are generally large and corruption does happen 68 from time to time. 69 70 - `iso_checksum_url` (string) - A URL to a GNU or BSD style checksum file 71 containing a checksum for the OS ISO file. At least one of `iso_checksum` 72 and `iso_checksum_url` must be defined. This will be ignored if 73 `iso_checksum` is non empty. 74 75 - `iso_url` (string) - A URL to the ISO containing the installation image. 76 This URL can be either an HTTP URL or a file URL (or path to a file). If 77 this is an HTTP URL, Packer will download it and cache it between runs. 78 79 - `ssh_username` (string) - The username to use to SSH into the machine once 80 the OS is installed. 81 82 - `ssh_password` (string) - The password to use to SSH into the machine once 83 the OS is installed. 84 85 ### Optional: 86 87 - `boot_command` (array of strings) - This is an array of commands to type 88 when the virtual machine is first booted. The goal of these commands should 89 be to type just enough to initialize the operating system installer. Special 90 keys can be typed as well, and are covered in the section below on the 91 boot command. If this is not specified, it is assumed the installer will 92 start itself. 93 94 - `boot_wait` (string) - The time to wait after booting the initial virtual 95 machine before typing the `boot_command`. The value of this should be 96 a duration. Examples are "5s" and "1m30s" which will cause Packer to wait 97 five seconds and one minute 30 seconds, respectively. If this isn't 98 specified, the default is 10 seconds. 99 100 - `disk_size` (integer) - The size, in megabytes, of the hard disk to create 101 for the VM. By default, this is 40000 (about 40 GB). 102 103 - `export_opts` (array of strings) - Additional options to pass to the 104 [VBoxManage export](https://www.virtualbox.org/manual/ch08.html#vboxmanage-export). 105 This can be useful for passing product information to include in the 106 resulting appliance file. Packer JSON configuration file example: 107 108 ``` {.json} 109 { 110 "type": "virtualbox-iso", 111 "export_opts": 112 [ 113 "--manifest", 114 "--vsys", "0", 115 "--description", "{{user `vm_description`}}", 116 "--version", "{{user `vm_version`}}" 117 ], 118 "format": "ova", 119 } 120 ``` 121 122 A VirtualBox [VM description](https://www.virtualbox.org/manual/ch08.html#idm3756) 123 may contain arbitrary strings; the GUI interprets HTML formatting. 124 However, the JSON format does not allow arbitrary newlines within a 125 value. Add a multi-line description by preparing the string in the 126 shell before the packer call like this (shell `>` continuation 127 character snipped for easier copy & paste): 128 129 ``` {.shell} 130 131 vm_description='some 132 multiline 133 description' 134 135 vm_version='0.2.0' 136 137 packer build \ 138 -var "vm_description=${vm_description}" \ 139 -var "vm_version=${vm_version}" \ 140 "packer_conf.json" 141 ``` 142 143 - `floppy_files` (array of strings) - A list of files to place onto a floppy 144 disk that is attached when the VM is booted. This is most useful for 145 unattended Windows installs, which look for an `Autounattend.xml` file on 146 removable media. By default, no floppy will be attached. All files listed in 147 this setting get placed into the root directory of the floppy and the floppy 148 is attached as the first floppy device. Currently, no support exists for 149 creating sub-directories on the floppy. Wildcard characters (\*, ?, 150 and \[\]) are allowed. Directory names are also allowed, which will add all 151 the files found in the directory to the floppy. 152 153 - `floppy_dirs` (array of strings) - A list of directories to place onto 154 the floppy disk recursively. This is similar to the `floppy_files` option 155 except that the directory structure is preserved. This is useful for when 156 your floppy disk includes drivers or if you just want to organize its 157 contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed. 158 159 - `format` (string) - Either "ovf" or "ova", this specifies the output format 160 of the exported virtual machine. This defaults to "ovf". 161 162 - `guest_additions_mode` (string) - The method by which guest additions are 163 made available to the guest for installation. Valid options are "upload", 164 "attach", or "disable". If the mode is "attach" the guest additions ISO will 165 be attached as a CD device to the virtual machine. If the mode is "upload" 166 the guest additions ISO will be uploaded to the path specified by 167 `guest_additions_path`. The default value is "upload". If "disable" is used, 168 guest additions won't be downloaded, either. 169 170 - `guest_additions_path` (string) - The path on the guest virtual machine 171 where the VirtualBox guest additions ISO will be uploaded. By default this 172 is "VBoxGuestAdditions.iso" which should upload into the login directory of 173 the user. This is a [configuration 174 template](/docs/templates/configuration-templates.html) where the `Version` 175 variable is replaced with the VirtualBox version. 176 177 - `guest_additions_sha256` (string) - The SHA256 checksum of the guest 178 additions ISO that will be uploaded to the guest VM. By default the 179 checksums will be downloaded from the VirtualBox website, so this only needs 180 to be set if you want to be explicit about the checksum. 181 182 - `guest_additions_url` (string) - The URL to the guest additions ISO 183 to upload. This can also be a file URL if the ISO is at a local path. By 184 default, the VirtualBox builder will attempt to find the guest additions ISO 185 on the local file system. If it is not available locally, the builder will 186 download the proper guest additions ISO from the internet. 187 188 - `guest_os_type` (string) - The guest OS type being installed. By default 189 this is "other", but you can get *dramatic* performance improvements by 190 setting this to the proper value. To view all available values for this run 191 `VBoxManage list ostypes`. Setting the correct value hints to VirtualBox how 192 to optimize the virtual hardware to work best with that operating system. 193 194 - `hard_drive_interface` (string) - The type of controller that the primary 195 hard drive is attached to, defaults to "ide". When set to "sata", the drive 196 is attached to an AHCI SATA controller. When set to "scsi", the drive is 197 attached to an LsiLogic SCSI controller. 198 199 - `hard_drive_nonrotational` (boolean) - Forces some guests (i.e. Windows 7+) 200 to treat disks as SSDs and stops them from performing disk fragmentation. 201 202 - `hard_drive_discard` (boolean) - When this value is set to true, a VDI 203 image will be shrunk in response to the trim command from the guest OS. 204 The size of the cleared area must be at least 1MB. 205 206 - `headless` (boolean) - Packer defaults to building VirtualBox virtual 207 machines by launching a GUI that shows the console of the machine 208 being built. When this value is set to true, the machine will start without 209 a console. 210 211 - `http_directory` (string) - Path to a directory to serve using an 212 HTTP server. The files in this directory will be available over HTTP that 213 will be requestable from the virtual machine. This is useful for hosting 214 kickstart files and so on. By default this is "", which means no HTTP server 215 will be started. The address and port of the HTTP server will be available 216 as variables in `boot_command`. This is covered in more detail below. 217 218 - `http_port_min` and `http_port_max` (integer) - These are the minimum and 219 maximum port to use for the HTTP server started to serve the 220 `http_directory`. Because Packer often runs in parallel, Packer will choose 221 a randomly available port in this range to run the HTTP server. If you want 222 to force the HTTP server to be on one port, make this minimum and maximum 223 port the same. By default the values are 8000 and 9000, respectively. 224 225 - `iso_interface` (string) - The type of controller that the ISO is attached 226 to, defaults to "ide". When set to "sata", the drive is attached to an AHCI 227 SATA controller. 228 229 - `iso_target_path` (string) - The path where the iso should be saved after 230 download. By default will go in the packer cache, with a hash of the 231 original filename as its name. 232 233 - `iso_urls` (array of strings) - Multiple URLs for the ISO to download. 234 Packer will try these in order. If anything goes wrong attempting to 235 download or while downloading a single URL, it will move on to the next. All 236 URLs must point to the same file (same checksum). By default this is empty 237 and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified. 238 239 - `keep_registered` (boolean) - Set this to `true` if you would like to keep 240 the VM registered with virtualbox. Defaults to `false`. 241 242 - `output_directory` (string) - This is the path to the directory where the 243 resulting virtual machine will be created. This may be relative or absolute. 244 If relative, the path is relative to the working directory when `packer` 245 is executed. This directory must not exist or be empty prior to running 246 the builder. By default this is "output-BUILDNAME" where "BUILDNAME" is the 247 name of the build. 248 249 - `post_shutdown_delay` (string) - The amount of time to wait after shutting 250 down the virtual machine. If you get the error `Error removing floppy 251 controller`, you might need to set this to `5m` or so. By default, the 252 delay is `0s`, or disabled. 253 254 - `shutdown_command` (string) - The command to use to gracefully shut down the 255 machine once all the provisioning is done. By default this is an empty 256 string, which tells Packer to just forcefully shut down the machine unless a 257 shutdown command takes place inside script so this may safely be omitted. If 258 one or more scripts require a reboot it is suggested to leave this blank 259 since reboots may fail and specify the final shutdown command in your 260 last script. 261 262 - `shutdown_timeout` (string) - The amount of time to wait after executing the 263 `shutdown_command` for the virtual machine to actually shut down. If it 264 doesn't shut down in this time, it is an error. By default, the timeout is 265 `5m`, or five minutes. 266 267 - `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and 268 maximum port to use for the SSH port on the host machine which is forwarded 269 to the SSH port on the guest machine. Because Packer often runs in parallel, 270 Packer will choose a randomly available port in this range to use as the 271 host port. By default this is 2222 to 4444. 272 273 - `ssh_skip_nat_mapping` (boolean) - Defaults to false. When enabled, Packer 274 does not setup forwarded port mapping for SSH requests and uses `ssh_port` 275 on the host to communicate to the virtual machine 276 277 - `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to 278 execute in order to further customize the virtual machine being created. The 279 value of this is an array of commands to execute. The commands are executed 280 in the order defined in the template. For each command, the command is 281 defined itself as an array of strings, where each string represents a single 282 argument on the command-line to `VBoxManage` (but excluding 283 `VBoxManage` itself). Each arg is treated as a [configuration 284 template](/docs/templates/configuration-templates.html), where the `Name` 285 variable is replaced with the VM name. More details on how to use 286 `VBoxManage` are below. 287 288 - `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`, 289 except that it is run after the virtual machine is shutdown, and before the 290 virtual machine is exported. 291 292 - `virtualbox_version_file` (string) - The path within the virtual machine to 293 upload a file that contains the VirtualBox version that was used to create 294 the machine. This information can be useful for provisioning. By default 295 this is ".vbox\_version", which will generally be upload it into the 296 home directory. 297 298 - `vm_name` (string) - This is the name of the OVF file for the new virtual 299 machine, without the file extension. By default this is "packer-BUILDNAME", 300 where "BUILDNAME" is the name of the build. 301 302 - `vrdp_bind_address` (string / IP address) - The IP address that should be binded 303 to for VRDP. By default packer will use 127.0.0.1 for this. If you wish to bind 304 to all interfaces use 0.0.0.0 305 306 - `vrdp_port_min` and `vrdp_port_max` (integer) - The minimum and maximum port 307 to use for VRDP access to the virtual machine. Packer uses a randomly chosen 308 port in this range that appears available. By default this is 5900 to 6000. 309 The minimum and maximum ports are inclusive. 310 311 312 ## Boot Command 313 314 The `boot_command` configuration is very important: it specifies the keys to 315 type when the virtual machine is first booted in order to start the OS 316 installer. This command is typed after `boot_wait`, which gives the virtual 317 machine some time to actually load the ISO. 318 319 As documented above, the `boot_command` is an array of strings. The strings are 320 all typed in sequence. It is an array only to improve readability within the 321 template. 322 323 The boot command is "typed" character for character over a VNC connection to the 324 machine, simulating a human actually typing the keyboard. There are a set of 325 special keys available. If these are in your boot command, they will be replaced 326 by the proper key: 327 328 - `<bs>` - Backspace 329 330 - `<del>` - Delete 331 332 - `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress. 333 334 - `<esc>` - Simulates pressing the escape key. 335 336 - `<tab>` - Simulates pressing the tab key. 337 338 - `<f1>` - `<f12>` - Simulates pressing a function key. 339 340 - `<up>` `<down>` `<left>` `<right>` - Simulates pressing an arrow key. 341 342 - `<spacebar>` - Simulates pressing the spacebar. 343 344 - `<insert>` - Simulates pressing the insert key. 345 346 - `<home>` `<end>` - Simulates pressing the home and end keys. 347 348 - `<pageUp>` `<pageDown>` - Simulates pressing the page up and page down keys. 349 350 - `<leftAlt>` `<rightAlt>` - Simulates pressing the alt key. 351 352 - `<leftCtrl>` `<rightCtrl>` - Simulates pressing the ctrl key. 353 354 - `<leftShift>` `<rightShift>` - Simulates pressing the shift key. 355 356 - `<leftAltOn>` `<rightAltOn>` - Simulates pressing and holding the alt key. 357 358 - `<leftCtrlOn>` `<rightCtrlOn>` - Simulates pressing and holding the ctrl key. 359 360 - `<leftShiftOn>` `<rightShiftOn>` - Simulates pressing and holding the shift key. 361 362 - `<leftAltOff>` `<rightAltOff>` - Simulates releasing a held alt key. 363 364 - `<leftCtrlOff>` `<rightCtrlOff>` - Simulates releasing a held ctrl key. 365 366 - `<leftShiftOff>` `<rightShiftOff>` - Simulates releasing a held shift key. 367 368 - `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before 369 sending any additional keys. This is useful if you have to generally wait 370 for the UI to update before typing more. 371 372 When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them, 373 otherwise they will be held down until the machine reboots. Use lowercase 374 characters as well inside modifiers. 375 376 For example: to simulate ctrl+c use `<leftCtrlOn>c<leftCtrlOff>`. 377 378 In addition to the special keys, each command to type is treated as a 379 [configuration template](/docs/templates/configuration-templates.html). The 380 available variables are: 381 382 - `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server 383 that is started serving the directory specified by the `http_directory` 384 configuration parameter. If `http_directory` isn't specified, these will be 385 blank! 386 387 Example boot command. This is actually a working boot command used to start an 388 Ubuntu 12.04 installer: 389 390 ``` {.text} 391 [ 392 "<esc><esc><enter><wait>", 393 "/install/vmlinuz noapic ", 394 "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", 395 "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", 396 "hostname={{ .Name }} ", 397 "fb=false debconf/frontend=noninteractive ", 398 "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", 399 "keyboard-configuration/variant=USA console-setup/ask_detect=false ", 400 "initrd=/install/initrd.gz -- <enter>" 401 ] 402 ``` 403 404 ## Guest Additions 405 406 Packer will automatically download the proper guest additions for the version of 407 VirtualBox that is running and upload those guest additions into the virtual 408 machine so that provisioners can easily install them. 409 410 Packer downloads the guest additions from the official VirtualBox website, and 411 verifies the file with the official checksums released by VirtualBox. 412 413 After the virtual machine is up and the operating system is installed, Packer 414 uploads the guest additions into the virtual machine. The path where they are 415 uploaded is controllable by `guest_additions_path`, and defaults to 416 "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home 417 directory of the SSH user. 418 419 ## VBoxManage Commands 420 421 In order to perform extra customization of the virtual machine, a template can 422 define extra calls to `VBoxManage` to perform. 423 [VBoxManage](https://www.virtualbox.org/manual/ch08.html) is the command-line 424 interface to VirtualBox where you can completely control VirtualBox. It can be 425 used to do things such as set RAM, CPUs, etc. 426 427 Extra VBoxManage commands are defined in the template in the `vboxmanage` 428 section. An example is shown below that sets the memory and number of CPUs 429 within the virtual machine: 430 431 ``` {.javascript} 432 { 433 "vboxmanage": [ 434 ["modifyvm", "{{.Name}}", "--memory", "1024"], 435 ["modifyvm", "{{.Name}}", "--cpus", "2"] 436 ] 437 } 438 ``` 439 440 The value of `vboxmanage` is an array of commands to execute. These commands are 441 executed in the order defined. So in the above example, the memory will be set 442 followed by the CPUs. 443 444 Each command itself is an array of strings, where each string is an argument to 445 `VBoxManage`. Each argument is treated as a [configuration 446 template](/docs/templates/configuration-templates.html). The only available 447 variable is `Name` which is replaced with the unique name of the VM, which is 448 required for many VBoxManage calls.