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