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