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