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