2013-09-02 23:23:52 -04:00
|
|
|
---
|
2018-04-13 22:48:19 -04:00
|
|
|
modeline: |
|
|
|
|
vim: set ft=pandoc:
|
2017-06-14 21:04:16 -04:00
|
|
|
description: |
|
|
|
|
The Qemu Packer builder is able to create KVM and Xen virtual machine images.
|
2015-07-22 22:31:00 -04:00
|
|
|
layout: docs
|
2017-06-14 21:04:16 -04:00
|
|
|
page_title: 'QEMU - Builders'
|
|
|
|
sidebar_current: 'docs-builders-qemu'
|
2017-03-25 18:13:52 -04:00
|
|
|
---
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2013-11-05 18:34:09 -05:00
|
|
|
# QEMU Builder
|
2013-09-02 23:23:52 -04:00
|
|
|
|
|
|
|
Type: `qemu`
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The Qemu Packer builder is able to create [KVM](http://www.linux-kvm.org) and
|
2017-09-29 15:42:32 -04:00
|
|
|
[Xen](http://www.xenproject.org) virtual machine images.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The builder builds a virtual machine by creating a new virtual machine from
|
|
|
|
scratch, booting it, installing an OS, rebooting the machine with the boot media
|
|
|
|
as the virtual hard drive, provisioning software within the OS, then shutting it
|
|
|
|
down. The result of the Qemu builder is a directory containing the image file
|
|
|
|
necessary to run the virtual machine on KVM or Xen.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Here is a basic example. This example is functional so long as you fixup paths
|
|
|
|
to files, URLS for ISOs and checksums.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
``` json
|
2013-09-02 23:23:52 -04:00
|
|
|
{
|
|
|
|
"builders":
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "qemu",
|
2018-03-28 14:22:20 -04:00
|
|
|
"iso_url": "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso",
|
|
|
|
"iso_checksum": "af4a1640c0c6f348c6c41f1ea9e192a2",
|
2013-09-02 23:23:52 -04:00
|
|
|
"iso_checksum_type": "md5",
|
|
|
|
"output_directory": "output_centos_tdhtest",
|
2018-07-09 07:46:15 -04:00
|
|
|
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
|
2013-09-02 23:23:52 -04:00
|
|
|
"disk_size": 5000,
|
|
|
|
"format": "qcow2",
|
|
|
|
"accelerator": "kvm",
|
2018-10-16 12:42:35 -04:00
|
|
|
"http_directory": "path/to/httpdir",
|
2013-09-02 23:23:52 -04:00
|
|
|
"ssh_username": "root",
|
|
|
|
"ssh_password": "s0m3password",
|
2018-10-16 12:42:35 -04:00
|
|
|
"ssh_timeout": "20m",
|
2013-09-02 23:23:52 -04:00
|
|
|
"vm_name": "tdhtest",
|
2013-10-09 08:11:10 -04:00
|
|
|
"net_device": "virtio-net",
|
2013-09-03 11:08:04 -04:00
|
|
|
"disk_interface": "virtio",
|
2018-10-16 12:42:35 -04:00
|
|
|
"boot_wait": "10s",
|
2017-03-25 18:13:52 -04:00
|
|
|
"boot_command": [
|
2014-06-20 08:14:15 -04:00
|
|
|
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"
|
2013-09-02 23:23:52 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2018-10-16 12:42:35 -04:00
|
|
|
This is an example only, and will time out waiting for SSH because we have not
|
|
|
|
provided a kickstart file. You must add a valid kickstart file to the
|
|
|
|
"http_directory" and then provide the file in the "boot_command" in order for
|
|
|
|
this build to run. We recommend you check out the
|
|
|
|
[Community Templates](https://www.packer.io/community-tools.html#templates)
|
|
|
|
for a practical usage example.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
|
|
|
## Configuration Reference
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
There are many configuration options available for the Qemu builder. They are
|
|
|
|
organized below into two categories: required and optional. Within each
|
|
|
|
category, the available options are alphabetized and described.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2015-06-23 17:44:57 -04:00
|
|
|
In addition to the options listed here, a
|
2015-07-22 22:31:00 -04:00
|
|
|
[communicator](/docs/templates/communicator.html) can be configured for this
|
|
|
|
builder.
|
2015-06-23 17:44:57 -04:00
|
|
|
|
2016-05-20 13:01:41 -04:00
|
|
|
Note that you will need to set `"headless": true` if you are running Packer
|
|
|
|
on a Linux server without X11; or if you are connected via ssh to a remote
|
|
|
|
Linux server and have not enabled X11 forwarding (`ssh -X`).
|
|
|
|
|
2019-06-12 12:38:37 -04:00
|
|
|
|
|
|
|
## ISO Configuration Reference
|
|
|
|
|
|
|
|
<%= partial "partials/common/ISOConfig" %>
|
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
### Required:
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2019-06-12 12:38:37 -04:00
|
|
|
<%= partial "partials/common/ISOConfig-required" %>
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
### Optional:
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2019-06-12 12:38:37 -04:00
|
|
|
<%= partial "partials/common/ISOConfig-not-required" %>
|
2018-01-31 15:45:38 -05:00
|
|
|
|
2019-06-13 05:18:04 -04:00
|
|
|
## Http directory configuration reference
|
|
|
|
|
|
|
|
<%= partial "partials/common/HTTPConfig" %>
|
|
|
|
### Optional:
|
|
|
|
|
|
|
|
<%= partial "partials/common/HTTPConfig-not-required" %>
|
|
|
|
|
|
|
|
## Qemu Configuration Reference
|
2018-04-25 10:50:58 -04:00
|
|
|
|
2019-06-12 12:38:37 -04:00
|
|
|
### Optional:
|
|
|
|
<%= partial "partials/builder/qemu/Config-not-required" %>
|
|
|
|
DADA
|
2018-12-26 01:49:42 -05:00
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
- `boot_command` (array of strings) - This is an array of commands to type
|
2015-07-22 23:25:58 -04:00
|
|
|
when the virtual machine is first booted. The goal of these commands should
|
|
|
|
be to type just enough to initialize the operating system installer. Special
|
|
|
|
keys can be typed as well, and are covered in the section below on the
|
|
|
|
boot command. If this is not specified, it is assumed the installer will
|
|
|
|
start itself.
|
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
- `boot_wait` (string) - The time to wait after booting the initial virtual
|
2015-07-22 23:25:58 -04:00
|
|
|
machine before typing the `boot_command`. The value of this should be
|
2018-04-21 20:50:40 -04:00
|
|
|
a duration. Examples are `5s` and `1m30s` which will cause Packer to wait
|
2015-07-22 23:25:58 -04:00
|
|
|
five seconds and one minute 30 seconds, respectively. If this isn't
|
2018-04-21 20:50:40 -04:00
|
|
|
specified, the default is `10s` or 10 seconds.
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2018-04-21 20:50:40 -04:00
|
|
|
- `floppy_dirs` (array of strings) - A list of directories to place onto
|
|
|
|
the floppy disk recursively. This is similar to the `floppy_files` option
|
|
|
|
except that the directory structure is preserved. This is useful for when
|
|
|
|
your floppy disk includes drivers or if you just want to organize it's
|
|
|
|
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
|
|
|
|
The maximum summary size of all files in the listed directories are the
|
|
|
|
same as in `floppy_files`.
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
- `floppy_files` (array of strings) - A list of files to place onto a floppy
|
2015-07-22 23:25:58 -04:00
|
|
|
disk that is attached when the VM is booted. This is most useful for
|
|
|
|
unattended Windows installs, which look for an `Autounattend.xml` file on
|
|
|
|
removable media. By default, no floppy will be attached. All files listed in
|
|
|
|
this setting get placed into the root directory of the floppy and the floppy
|
|
|
|
is attached as the first floppy device. Currently, no support exists for
|
|
|
|
creating sub-directories on the floppy. Wildcard characters (\*, ?,
|
|
|
|
and \[\]) are allowed. Directory names are also allowed, which will add all
|
2017-03-06 13:25:32 -05:00
|
|
|
the files found in the directory to the floppy. The summary size of the
|
|
|
|
listed files must not exceed 1.44 MB. The supported ways to move large
|
2017-06-14 21:04:16 -04:00
|
|
|
files into the OS are using `http_directory` or [the file provisioner](https://www.packer.io/docs/provisioners/file.html).
|
2015-07-22 23:25:58 -04:00
|
|
|
|
|
|
|
|
2013-09-02 23:23:52 -04:00
|
|
|
## Boot Command
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The `boot_command` configuration is very important: it specifies the keys to
|
|
|
|
type when the virtual machine is first booted in order to start the OS
|
|
|
|
installer. This command is typed after `boot_wait`, which gives the virtual
|
|
|
|
machine some time to actually load the ISO.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
As documented above, the `boot_command` is an array of strings. The strings are
|
|
|
|
all typed in sequence. It is an array only to improve readability within the
|
|
|
|
template.
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The boot command is "typed" character for character over a VNC connection to the
|
2017-01-14 20:56:04 -05:00
|
|
|
machine, simulating a human actually typing the keyboard.
|
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
-> Keystrokes are typed as separate key up/down events over VNC with a
|
|
|
|
default 100ms delay. The delay alleviates issues with latency and CPU
|
2018-08-22 14:25:43 -04:00
|
|
|
contention. You can tune this delay on a per-builder basis by specifying
|
|
|
|
"boot_key_interval" in your Packer template, for example:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"type": "qemu",
|
2018-08-23 16:16:01 -04:00
|
|
|
"boot_key_interval": "10ms"
|
2018-08-22 14:25:43 -04:00
|
|
|
...
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-04-13 19:48:26 -04:00
|
|
|
<%= partial "partials/builders/boot-command" %>
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Example boot command. This is actually a working boot command used to start an
|
|
|
|
CentOS 6.4 installer:
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2017-06-14 21:04:16 -04:00
|
|
|
``` json
|
2017-03-25 18:13:52 -04:00
|
|
|
{
|
|
|
|
"boot_command": [
|
|
|
|
"<tab><wait>",
|
|
|
|
" ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter>"
|
|
|
|
]
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2016-12-20 20:22:47 -05:00
|
|
|
|
2017-10-12 01:58:03 -04:00
|
|
|
For more examples of various boot commands, see the sample projects from our
|
2017-10-13 21:59:58 -04:00
|
|
|
[community templates page](/community-tools.html#templates).
|
2017-10-12 01:58:03 -04:00
|
|
|
|
2016-12-20 20:22:47 -05:00
|
|
|
### Troubleshooting
|
|
|
|
|
|
|
|
Some users have experienced errors complaining about invalid keymaps. This
|
|
|
|
seems to be related to having a `common` directory or file in the directory
|
|
|
|
they've run Packer in, like the packer source directory. This appears to be an
|
|
|
|
upstream bug with qemu, and the best solution for now is to remove the
|
|
|
|
file/directory or run in another directory.
|
2018-03-09 18:33:28 -05:00
|
|
|
|
|
|
|
Some users have reported issues with incorrect keymaps using qemu version 2.11.
|
|
|
|
This is a bug with qemu, and the solution is to upgrade, or downgrade to 2.10.1
|
|
|
|
or earlier.
|