github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/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.3-server-amd64.iso", 30 "iso_checksum": "2cbe868812a871242cdcdd8f2fd6feb9", 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_urls` (array of strings) - Multiple URLs for the ISO to download. 160 Packer will try these in order. If anything goes wrong attempting to download 161 or while downloading a single URL, it will move on to the next. All URLs 162 must point to the same file (same checksum). By default this is empty 163 and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified. 164 165 * `output_directory` (string) - This is the path to the directory where the 166 resulting virtual machine will be created. This may be relative or absolute. 167 If relative, the path is relative to the working directory when `packer` 168 is executed. This directory must not exist or be empty prior to running the builder. 169 By default this is "output-BUILDNAME" where "BUILDNAME" is the name 170 of the build. 171 172 * `shutdown_command` (string) - The command to use to gracefully shut down 173 the machine once all the provisioning is done. By default this is an empty 174 string, which tells Packer to just forcefully shut down the machine. 175 176 * `shutdown_timeout` (string) - The amount of time to wait after executing 177 the `shutdown_command` for the virtual machine to actually shut down. 178 If it doesn't shut down in this time, it is an error. By default, the timeout 179 is "5m", or five minutes. 180 181 * `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and 182 maximum port to use for the SSH port on the host machine which is forwarded 183 to the SSH port on the guest machine. Because Packer often runs in parallel, 184 Packer will choose a randomly available port in this range to use as the 185 host port. 186 187 * `ssh_key_path` (string) - Path to a private key to use for authenticating 188 with SSH. By default this is not set (key-based auth won't be used). 189 The associated public key is expected to already be configured on the 190 VM being prepared by some other process (kickstart, etc.). 191 192 * `ssh_password` (string) - The password for `ssh_username` to use to 193 authenticate with SSH. By default this is the empty string. 194 195 * `ssh_port` (integer) - The port that SSH will be listening on in the guest 196 virtual machine. By default this is 22. 197 198 * `ssh_wait_timeout` (string) - The duration to wait for SSH to become 199 available. By default this is "20m", or 20 minutes. Note that this should 200 be quite long since the timer begins as soon as the virtual machine is booted. 201 202 * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to 203 execute in order to further customize the virtual machine being created. 204 The value of this is an array of commands to execute. The commands are executed 205 in the order defined in the template. For each command, the command is 206 defined itself as an array of strings, where each string represents a single 207 argument on the command-line to `VBoxManage` (but excluding `VBoxManage` 208 itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html), 209 where the `Name` variable is replaced with the VM name. More details on how 210 to use `VBoxManage` are below. 211 212 * `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`, 213 except that it is run after the virtual machine is shutdown, and before the 214 virtual machine is exported. 215 216 * `virtualbox_version_file` (string) - The path within the virtual machine 217 to upload a file that contains the VirtualBox version that was used to 218 create the machine. This information can be useful for provisioning. 219 By default this is ".vbox_version", which will generally be upload it into 220 the home directory. 221 222 * `vm_name` (string) - This is the name of the OVF file for the new virtual 223 machine, without the file extension. By default this is "packer-BUILDNAME", 224 where "BUILDNAME" is the name of the build. 225 226 ## Boot Command 227 228 The `boot_command` configuration is very important: it specifies the keys 229 to type when the virtual machine is first booted in order to start the 230 OS installer. This command is typed after `boot_wait`, which gives the 231 virtual machine some time to actually load the ISO. 232 233 As documented above, the `boot_command` is an array of strings. The 234 strings are all typed in sequence. It is an array only to improve readability 235 within the template. 236 237 The boot command is "typed" character for character over a VNC connection 238 to the machine, simulating a human actually typing the keyboard. There are 239 a set of special keys available. If these are in your boot command, they 240 will be replaced by the proper key: 241 242 * `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress. 243 244 * `<esc>` - Simulates pressing the escape key. 245 246 * `<tab>` - Simulates pressing the tab key. 247 248 * `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending any additional keys. This 249 is useful if you have to generally wait for the UI to update before typing more. 250 251 In addition to the special keys, each command to type is treated as a 252 [configuration template](/docs/templates/configuration-templates.html). 253 The available variables are: 254 255 * `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server 256 that is started serving the directory specified by the `http_directory` 257 configuration parameter. If `http_directory` isn't specified, these will 258 be blank! 259 260 Example boot command. This is actually a working boot command used to start 261 an Ubuntu 12.04 installer: 262 263 <pre class="prettyprint"> 264 [ 265 "<esc><esc><enter><wait>", 266 "/install/vmlinuz noapic ", 267 "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", 268 "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", 269 "hostname={{ .Name }} ", 270 "fb=false debconf/frontend=noninteractive ", 271 "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", 272 "keyboard-configuration/variant=USA console-setup/ask_detect=false ", 273 "initrd=/install/initrd.gz -- <enter>" 274 ] 275 </pre> 276 277 ## Guest Additions 278 279 Packer will automatically download the proper guest additions for the 280 version of VirtualBox that is running and upload those guest additions into 281 the virtual machine so that provisioners can easily install them. 282 283 Packer downloads the guest additions from the official VirtualBox website, 284 and verifies the file with the official checksums released by VirtualBox. 285 286 After the virtual machine is up and the operating system is installed, 287 Packer uploads the guest additions into the virtual machine. The path where 288 they are uploaded is controllable by `guest_additions_path`, and defaults 289 to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the 290 home directory of the SSH user. 291 292 ## VBoxManage Commands 293 294 In order to perform extra customization of the virtual machine, a template 295 can define extra calls to `VBoxManage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html) 296 is the command-line interface to VirtualBox where you can completely control 297 VirtualBox. It can be used to do things such as set RAM, CPUs, etc. 298 299 Extra VBoxManage commands are defined in the template in the `vboxmanage` section. 300 An example is shown below that sets the memory and number of CPUs within the 301 virtual machine: 302 303 <pre class="prettyprint"> 304 { 305 "vboxmanage": [ 306 ["modifyvm", "{{.Name}}", "--memory", "1024"], 307 ["modifyvm", "{{.Name}}", "--cpus", "2"] 308 ] 309 } 310 </pre> 311 312 The value of `vboxmanage` is an array of commands to execute. These commands 313 are executed in the order defined. So in the above example, the memory will be 314 set followed by the CPUs. 315 316 Each command itself is an array of strings, where each string is an argument 317 to `VBoxManage`. Each argument is treated as a 318 [configuration template](/docs/templates/configuration-templates.html). 319 The only available variable is `Name` which is replaced with the unique 320 name of the VM, which is required for many VBoxManage calls.