github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/website/source/docs/builders/qemu.html.markdown (about) 1 --- 2 layout: "docs" 3 page_title: "QEMU Builder" 4 description: |- 5 The Qemu Packer builder is able to create KVM and Xen virtual machine images. Support for Xen is experimental at this time. 6 --- 7 8 # QEMU Builder 9 10 Type: `qemu` 11 12 The Qemu Packer builder is able to create [KVM](http://www.linux-kvm.org) 13 and [Xen](http://www.xenproject.org) virtual machine images. Support 14 for Xen is experimental at this time. 15 16 The builder builds a virtual machine by creating a new virtual machine 17 from scratch, booting it, installing an OS, rebooting the machine with the 18 boot media as the virtual hard drive, provisioning software within 19 the OS, then shutting it down. The result of the Qemu builder is a directory 20 containing the image file necessary to run the virtual machine on KVM or Xen. 21 22 ## Basic Example 23 24 Here is a basic example. This example is functional so long as you fixup 25 paths to files, URLS for ISOs and checksums. 26 27 ```javascript 28 { 29 "builders": 30 [ 31 { 32 "type": "qemu", 33 "iso_url": "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.5-x86_64-minimal.iso", 34 "iso_checksum": "0d9dc37b5dd4befa1c440d2174e88a87", 35 "iso_checksum_type": "md5", 36 "output_directory": "output_centos_tdhtest", 37 "ssh_wait_timeout": "30s", 38 "shutdown_command": "shutdown -P now", 39 "disk_size": 5000, 40 "format": "qcow2", 41 "headless": false, 42 "accelerator": "kvm", 43 "http_directory": "httpdir", 44 "http_port_min": 10082, 45 "http_port_max": 10089, 46 "ssh_host_port_min": 2222, 47 "ssh_host_port_max": 2229, 48 "ssh_username": "root", 49 "ssh_password": "s0m3password", 50 "ssh_port": 22, 51 "ssh_wait_timeout": "90m", 52 "vm_name": "tdhtest", 53 "net_device": "virtio-net", 54 "disk_interface": "virtio", 55 "boot_wait": "5s", 56 "boot_command": 57 [ 58 "<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>" 59 ] 60 } 61 ] 62 } 63 ``` 64 65 A working CentOS 6.x kickstart file can be found 66 [at this URL](https://gist.github.com/mitchellh/7328271/#file-centos6-ks-cfg), adapted from an unknown source. 67 Place this file in the http directory with the proper name. For the 68 example above, it should go into "httpdir" with a name of "centos6-ks.cfg". 69 70 ## Configuration Reference 71 72 There are many configuration options available for the Qemu builder. 73 They are organized below into two categories: required and optional. Within 74 each category, the available options are alphabetized and described. 75 76 ### Required: 77 78 * `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO 79 files are so large, this is required and Packer will verify it prior 80 to booting a virtual machine with the ISO attached. The type of the 81 checksum is specified with `iso_checksum_type`, documented below. 82 83 * `iso_checksum_type` (string) - The type of the checksum specified in 84 `iso_checksum`. Valid values are "md5", "sha1", "sha256", or "sha512" currently. 85 86 * `iso_url` (string) - A URL to the ISO containing the installation image. 87 This URL can be either an HTTP URL or a file URL (or path to a file). 88 If this is an HTTP URL, Packer will download it and cache it between 89 runs. 90 91 * `ssh_username` (string) - The username to use to SSH into the machine 92 once the OS is installed. 93 94 ### Optional: 95 96 * `accelerator` (string) - The accelerator type to use when running the VM. 97 This may have a value of either "none", "kvm", "tcg", or "xen" and you must have that 98 support in on the machine on which you run the builder. By default "kvm" 99 is used. 100 101 * `boot_command` (array of strings) - This is an array of commands to type 102 when the virtual machine is first booted. The goal of these commands should 103 be to type just enough to initialize the operating system installer. Special 104 keys can be typed as well, and are covered in the section below on the boot 105 command. If this is not specified, it is assumed the installer will start 106 itself. 107 108 * `boot_wait` (string) - The time to wait after booting the initial virtual 109 machine before typing the `boot_command`. The value of this should be 110 a duration. Examples are "5s" and "1m30s" which will cause Packer to wait 111 five seconds and one minute 30 seconds, respectively. If this isn't specified, 112 the default is 10 seconds. 113 114 * `disk_size` (integer) - The size, in megabytes, of the hard disk to create 115 for the VM. By default, this is 40000 (about 40 GB). 116 117 * `disk_interface` (string) - The interface to use for the disk. Allowed 118 values include any of "ide," "scsi" or "virtio." Note also that any boot 119 commands or kickstart type scripts must have proper adjustments for 120 resulting device names. The Qemu builder uses "virtio" by default. 121 122 * `disk_cache` (string) - The cache mode to use for disk. Allowed values 123 values include any of "writethrough", "writeback", "none", "unsafe" or 124 "directsync". 125 126 * `floppy_files` (array of strings) - A list of files to place onto a floppy 127 disk that is attached when the VM is booted. This is most useful 128 for unattended Windows installs, which look for an `Autounattend.xml` file 129 on removable media. By default, no floppy will be attached. All files 130 listed in this setting get placed into the root directory of the floppy 131 and the floppy is attached as the first floppy device. Currently, no 132 support exists for creating sub-directories on the floppy. Wildcard 133 characters (*, ?, and []) are allowed. Directory names are also allowed, 134 which will add all the files found in the directory to the floppy. 135 136 * `format` (string) - Either "qcow2" or "raw", this specifies the output 137 format of the virtual machine image. This defaults to "qcow2". 138 139 * `headless` (boolean) - Packer defaults to building virtual machines by 140 launching a GUI that shows the console of the machine being built. 141 When this value is set to true, the machine will start without a console. 142 143 * `http_directory` (string) - Path to a directory to serve using an HTTP 144 server. The files in this directory will be available over HTTP that will 145 be requestable from the virtual machine. This is useful for hosting 146 kickstart files and so on. By default this is "", which means no HTTP 147 server will be started. The address and port of the HTTP server will be 148 available as variables in `boot_command`. This is covered in more detail 149 below. 150 151 * `http_port_min` and `http_port_max` (integer) - These are the minimum and 152 maximum port to use for the HTTP server started to serve the `http_directory`. 153 Because Packer often runs in parallel, Packer will choose a randomly available 154 port in this range to run the HTTP server. If you want to force the HTTP 155 server to be on one port, make this minimum and maximum port the same. 156 By default the values are 8000 and 9000, respectively. 157 158 * `iso_urls` (array of strings) - Multiple URLs for the ISO to download. 159 Packer will try these in order. If anything goes wrong attempting to download 160 or while downloading a single URL, it will move on to the next. All URLs 161 must point to the same file (same checksum). By default this is empty 162 and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified. 163 164 * `machine_type` (string) - The type of machine emulation to use. Run 165 your qemu binary with the flags `-machine help` to list available types 166 for your system. This defaults to "pc". 167 168 * `net_device` (string) - The driver to use for the network interface. Allowed 169 values "ne2k_pci," "i82551," "i82557b," "i82559er," "rtl8139," "e1000," 170 "pcnet" or "virtio." The Qemu builder uses "virtio" by default. 171 172 * `output_directory` (string) - This is the path to the directory where the 173 resulting virtual machine will be created. This may be relative or absolute. 174 If relative, the path is relative to the working directory when `packer` 175 is executed. This directory must not exist or be empty prior to running the builder. 176 By default this is "output-BUILDNAME" where "BUILDNAME" is the name 177 of the build. 178 179 * `qemuargs` (array of array of strings) - Allows complete control over 180 the qemu command line (though not, at this time, qemu-img). Each array 181 of strings makes up a command line switch that overrides matching default 182 switch/value pairs. Any value specified as an empty string is ignored. 183 All values after the switch are concatenated with no separater. 184 185 ~> **Warning:** The qemu command line allows extreme flexibility, so beware of 186 conflicting arguments causing failures of your run. For instance, using 187 --no-acpi could break the ability to send power signal type commands (e.g., 188 shutdown -P now) to the virtual machine, thus preventing proper shutdown. To 189 see the defaults, look in the packer.log file and search for the 190 qemu-system-x86 command. The arguments are all printed for review. 191 192 The following shows a sample usage: 193 194 ```javascript 195 // ... 196 "qemuargs": [ 197 [ "-m", "1024M" ], 198 [ "--no-acpi", "" ], 199 [ 200 "-netdev", 201 "user,id=mynet0,", 202 "hostfwd=hostip:hostport-guestip:guestport", 203 "" 204 ], 205 [ "-device", "virtio-net,netdev=mynet0" ] 206 ] 207 // ... 208 ``` 209 210 would produce the following (not including other defaults supplied by the builder and not otherwise conflicting with the qemuargs): 211 212 <pre class="prettyprint"> 213 qemu-system-x86 -m 1024m --no-acpi -netdev user,id=mynet0,hostfwd=hostip:hostport-guestip:guestport -device virtio-net,netdev=mynet0" 214 </pre> 215 216 * `qemu_binary` (string) - The name of the Qemu binary to look for. This 217 defaults to "qemu-system-x86_64", but may need to be changed for some 218 platforms. For example "qemu-kvm", or "qemu-system-i386" may be a better 219 choice for some systems. 220 221 * `shutdown_command` (string) - The command to use to gracefully shut down 222 the machine once all the provisioning is done. By default this is an empty 223 string, which tells Packer to just forcefully shut down the machine. 224 225 * `shutdown_timeout` (string) - The amount of time to wait after executing 226 the `shutdown_command` for the virtual machine to actually shut down. 227 If it doesn't shut down in this time, it is an error. By default, the timeout 228 is "5m", or five minutes. 229 230 * `ssh_host_port_min` and `ssh_host_port_max` (uint) - The minimum and 231 maximum port to use for the SSH port on the host machine which is forwarded 232 to the SSH port on the guest machine. Because Packer often runs in parallel, 233 Packer will choose a randomly available port in this range to use as the 234 host port. 235 236 * `ssh_key_path` (string) - Path to a private key to use for authenticating 237 with SSH. By default this is not set (key-based auth won't be used). 238 The associated public key is expected to already be configured on the 239 VM being prepared by some other process (kickstart, etc.). 240 241 * `ssh_password` (string) - The password for `ssh_username` to use to 242 authenticate with SSH. By default this is the empty string. 243 244 * `ssh_port` (integer) - The port that SSH will be listening on in the guest 245 virtual machine. By default this is 22. The Qemu builder will map, via 246 port forward, a port on the host machine to the port listed here so 247 machines outside the installing VM can access the VM. 248 249 * `ssh_wait_timeout` (string) - The duration to wait for SSH to become 250 available. By default this is "20m", or 20 minutes. Note that this should 251 be quite long since the timer begins as soon as the virtual machine is booted. 252 253 * `vm_name` (string) - This is the name of the image (QCOW2 or IMG) file for 254 the new virtual machine, without the file extension. By default this is 255 "packer-BUILDNAME", where "BUILDNAME" is the name of the build. 256 257 * `vnc_port_min` and `vnc_port_max` (integer) - The minimum and 258 maximum port to use for the VNC port on the host machine which is forwarded 259 to the VNC port on the guest machine. Because Packer often runs in parallel, 260 Packer will choose a randomly available port in this range to use as the 261 host port. 262 263 * `disk_image` (boolean) - Packer defaults to building from an ISO file, 264 this parameter controls whether the ISO URL supplied is actually a bootable 265 QEMU image. When this value is set to true, the machine will clone the 266 source, resize it according to `disk_size` and boot the image. 267 268 ## Boot Command 269 270 The `boot_command` configuration is very important: it specifies the keys 271 to type when the virtual machine is first booted in order to start the 272 OS installer. This command is typed after `boot_wait`, which gives the 273 virtual machine some time to actually load the ISO. 274 275 As documented above, the `boot_command` is an array of strings. The 276 strings are all typed in sequence. It is an array only to improve readability 277 within the template. 278 279 The boot command is "typed" character for character over a VNC connection 280 to the machine, simulating a human actually typing the keyboard. There are 281 a set of special keys available. If these are in your boot command, they 282 will be replaced by the proper key: 283 284 * `<bs>` - Backspace 285 286 * `<del>` - Delete 287 288 * `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress. 289 290 * `<esc>` - Simulates pressing the escape key. 291 292 * `<tab>` - Simulates pressing the tab key. 293 294 * `<f1>` - `<f12>` - Simulates pressing a function key. 295 296 * `<up>` `<down>` `<left>` `<right>` - Simulates pressing an arrow key. 297 298 * `<spacebar>` - Simulates pressing the spacebar. 299 300 * `<insert>` - Simulates pressing the insert key. 301 302 * `<home>` `<end>` - Simulates pressing the home and end keys. 303 304 * `<pageUp>` `<pageDown>` - Simulates pressing the page up and page down keys. 305 306 * `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending any additional keys. This 307 is useful if you have to generally wait for the UI to update before typing more. 308 309 In addition to the special keys, each command to type is treated as a 310 [configuration template](/docs/templates/configuration-templates.html). 311 The available variables are: 312 313 * `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server 314 that is started serving the directory specified by the `http_directory` 315 configuration parameter. If `http_directory` isn't specified, these will 316 be blank! 317 318 Example boot command. This is actually a working boot command used to start 319 an CentOS 6.4 installer: 320 321 ```javascript 322 "boot_command": 323 [ 324 "<tab><wait>", 325 " ks=http://10.0.2.2:{{ .HTTPPort }}/centos6-ks.cfg<enter>" 326 ] 327 ```