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: |
|
2020-09-09 19:42:37 -04:00
|
|
|
The Qemu Packer builder is able to create KVM virtual machine images.
|
2020-03-18 18:46:47 -04:00
|
|
|
page_title: QEMU - Builders
|
2020-04-02 19:39:47 -04:00
|
|
|
sidebar_title: 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`
|
|
|
|
|
2020-09-14 15:19:19 -04:00
|
|
|
The Qemu Packer builder is able to create [KVM](http://www.linux-kvm.org) virtual
|
2020-09-09 19:42:37 -04:00
|
|
|
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
|
2020-09-09 19:42:37 -04:00
|
|
|
necessary to run the virtual machine on KVM.
|
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
|
|
|
|
2020-07-31 11:32:08 -04:00
|
|
|
<Tabs>
|
|
|
|
<Tab heading="JSON">
|
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2013-09-02 23:23:52 -04:00
|
|
|
{
|
2020-03-18 18:46:47 -04:00
|
|
|
"builders": [
|
2013-09-02 23:23:52 -04:00
|
|
|
{
|
|
|
|
"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",
|
2020-07-31 11:32:08 -04:00
|
|
|
"iso_checksum": "md5:af4a1640c0c6f348c6c41f1ea9e192a2",
|
2013-09-02 23:23:52 -04:00
|
|
|
"output_directory": "output_centos_tdhtest",
|
2018-07-09 07:46:15 -04:00
|
|
|
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
|
2019-11-04 17:28:48 -05:00
|
|
|
"disk_size": "5000M",
|
2013-09-02 23:23:52 -04:00
|
|
|
"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
|
|
|
|
2020-07-31 11:32:08 -04:00
|
|
|
</Tab>
|
|
|
|
<Tab heading="HCL2">
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
source "qemu" "example" {
|
|
|
|
iso_url = "http://mirror.raystedman.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso"
|
|
|
|
iso_checksum = "md5:af4a1640c0c6f348c6c41f1ea9e192a2"
|
|
|
|
output_directory = "output_centos_tdhtest"
|
|
|
|
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
|
|
|
|
disk_size = "5000M"
|
|
|
|
format = "qcow2"
|
|
|
|
accelerator = "kvm"
|
|
|
|
http_directory = "path/to/httpdir"
|
|
|
|
ssh_username = "root"
|
|
|
|
ssh_password = "s0m3password"
|
|
|
|
ssh_timeout = "20m"
|
|
|
|
vm_name = "tdhtest"
|
|
|
|
net_device = "virtio-net"
|
|
|
|
disk_interface = "virtio"
|
|
|
|
boot_wait = "10s"
|
|
|
|
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6-ks.cfg<enter><wait>"]
|
|
|
|
}
|
|
|
|
|
|
|
|
build {
|
|
|
|
sources = ["source.qemu.example"]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
|
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
|
2020-03-31 17:40:07 -04:00
|
|
|
[Community Templates](/community-tools#templates)
|
2018-10-16 12:42:35 -04:00
|
|
|
for a practical usage example.
|
2013-09-02 23:23:52 -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-19 09:57:58 -04:00
|
|
|
## Qemu Specific Configuration Reference
|
|
|
|
|
|
|
|
There are many configuration options available for the builder. In addition to
|
|
|
|
the items listed here, you will want to look at the general configuration
|
|
|
|
references for [ISO](#iso-configuration),
|
|
|
|
[HTTP](#http-directory-configuration),
|
|
|
|
[Floppy](#floppy-configuration),
|
|
|
|
[Boot](#boot-configuration),
|
|
|
|
[Shutdown](#shutdown-configuration),
|
|
|
|
[Communicator](#communicator-configuration)
|
|
|
|
configuration references, which are
|
|
|
|
necessary for this build to succeed and can be found further down the page.
|
|
|
|
|
|
|
|
### Optional:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/qemu/Config-not-required.mdx'
|
2019-06-12 12:38:37 -04:00
|
|
|
|
2019-06-19 09:57:58 -04:00
|
|
|
## ISO Configuration
|
2019-06-12 12:38:37 -04:00
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/ISOConfig.mdx'
|
2019-06-12 12:38:37 -04:00
|
|
|
|
2014-05-04 13:47:40 -04:00
|
|
|
### Required:
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/ISOConfig-required.mdx'
|
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
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/ISOConfig-not-required.mdx'
|
2018-01-31 15:45:38 -05:00
|
|
|
|
2019-06-19 09:57:58 -04:00
|
|
|
## Http directory configuration
|
2019-06-13 05:18:04 -04:00
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig.mdx'
|
2020-03-18 18:46:47 -04:00
|
|
|
|
2019-06-13 05:18:04 -04:00
|
|
|
### Optional:
|
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx'
|
2019-06-13 05:18:04 -04:00
|
|
|
|
2019-06-19 09:57:58 -04:00
|
|
|
## Floppy configuration
|
2019-06-13 08:29:25 -04:00
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/FloppyConfig.mdx'
|
2019-06-13 08:29:25 -04:00
|
|
|
|
|
|
|
### Optional:
|
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/FloppyConfig-not-required.mdx'
|
2019-06-13 08:29:25 -04:00
|
|
|
|
2020-09-14 15:19:19 -04:00
|
|
|
### CD configuration
|
|
|
|
|
2020-11-17 20:18:45 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/CDConfig.mdx'
|
2020-09-14 15:19:19 -04:00
|
|
|
|
|
|
|
#### Optional:
|
|
|
|
|
2020-11-17 20:07:02 -05:00
|
|
|
@include 'packer-plugin-sdk/multistep/commonsteps/CDConfig-not-required.mdx'
|
2020-09-14 15:19:19 -04:00
|
|
|
|
2019-06-19 09:57:58 -04:00
|
|
|
## Shutdown configuration
|
2018-04-25 10:50:58 -04:00
|
|
|
|
2019-06-12 12:38:37 -04:00
|
|
|
### Optional:
|
2018-12-26 01:49:42 -05:00
|
|
|
|
2020-11-12 17:44:02 -05:00
|
|
|
@include 'packer-plugin-sdk/shutdowncommand/ShutdownConfig-not-required.mdx'
|
2019-06-19 09:57:58 -04:00
|
|
|
|
2020-06-02 05:56:36 -04:00
|
|
|
## Communicator configuration
|
|
|
|
|
|
|
|
### Optional common fields:
|
|
|
|
|
2020-12-01 18:30:31 -05:00
|
|
|
@include 'packer-plugin-sdk/communicator/Config-not-required.mdx'
|
2020-06-02 05:56:36 -04:00
|
|
|
|
|
|
|
@include 'builder/qemu/CommConfig-not-required.mdx'
|
|
|
|
|
|
|
|
### Optional SSH fields:
|
|
|
|
|
2020-12-01 18:30:31 -05:00
|
|
|
@include 'packer-plugin-sdk/communicator/SSH-not-required.mdx'
|
2020-06-02 05:56:36 -04:00
|
|
|
|
2020-12-01 18:30:31 -05:00
|
|
|
@include 'packer-plugin-sdk/communicator/SSH-Private-Key-File-not-required.mdx'
|
2020-09-09 10:41:16 -04:00
|
|
|
|
2020-06-02 05:56:36 -04:00
|
|
|
### Optional WinRM fields:
|
|
|
|
|
2020-12-01 18:30:31 -05:00
|
|
|
@include 'packer-plugin-sdk/communicator/WinRM-not-required.mdx'
|
2020-06-02 05:56:36 -04:00
|
|
|
|
2019-06-19 09:57:58 -04:00
|
|
|
## Boot Configuration
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2020-11-12 17:44:02 -05:00
|
|
|
@include 'packer-plugin-sdk/bootcommand/VNCConfig.mdx'
|
2020-03-24 19:48:37 -04:00
|
|
|
|
2020-11-12 17:44:02 -05:00
|
|
|
@include 'packer-plugin-sdk/bootcommand/BootConfig.mdx'
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2019-06-13 10:08:15 -04:00
|
|
|
### Optional:
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2020-11-12 17:44:02 -05:00
|
|
|
@include 'packer-plugin-sdk/bootcommand/VNCConfig-not-required.mdx'
|
2020-03-24 19:48:37 -04:00
|
|
|
|
2020-11-12 17:44:02 -05:00
|
|
|
@include 'packer-plugin-sdk/bootcommand/BootConfig-not-required.mdx'
|
2016-12-20 20:22:47 -05:00
|
|
|
|
2019-06-19 09:57:58 -04:00
|
|
|
### Communicator Configuration
|
|
|
|
|
|
|
|
#### Optional:
|
|
|
|
|
2020-12-01 18:30:31 -05:00
|
|
|
@include 'packer-plugin-sdk/communicator/Config-not-required.mdx'
|
2017-10-12 01:58:03 -04:00
|
|
|
|
2016-12-20 20:22:47 -05:00
|
|
|
### Troubleshooting
|
|
|
|
|
2020-09-16 14:52:19 -04:00
|
|
|
#### Invalid Keymaps
|
|
|
|
|
2016-12-20 20:22:47 -05:00
|
|
|
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.
|
2020-09-16 14:52:19 -04:00
|
|
|
|
|
|
|
#### Corrupted image after Packer calls qemu-img convert on OSX
|
|
|
|
|
|
|
|
Due to an upstream bug with `qemu-img convert` on OSX, sometimes the qemu-img
|
|
|
|
convert call will create a corrupted image. If this is an issue for you, make
|
|
|
|
sure that the the output format (provided using the option `format`) matches
|
|
|
|
the input file's format and file extension, and Packer will
|
|
|
|
perform a simple copy operation instead. You will also want to set
|
|
|
|
`"skip_compaction": true,` and `"disk_compression": false` to skip a final
|
|
|
|
image conversion at the end of the build. See
|
2020-12-04 16:00:53 -05:00
|
|
|
https://bugs.launchpad.net/qemu/+bug/1776920 for more details.
|