mitchellh/packer — pull request #1395 by matthbak (2014-08-07 11:17:55+00:00)
Title: Allow for optional hardware virtualisation 

I have a requirement to run qemu on a Xen domain with no hardware virtualisation available so I don't want to use kvm or xen. I've also disabled SDL in headless mode and added the net device as done in https://github.com/benh57/packer to get packer qemu working on Oracle Linux 6.

Typical builder json file would look like this and is modelled on a CentOS 6 system.

[[[
{
"builders":
[
{
"type": "qemu",
"qemu_binary": "/usr/libexec/qemu-kvm",
"qemuargs": [
[ "-no-kvm","" ]
],
"iso_url": "http://kernel.us.oracle.com/osinstall/OracleLinux/OL6/U4/x86_64/OracleLinux-R6-U4-Server-x86_64-dvd.iso",
"iso_checksum": "4ecb72ade0186afe2f95ffc8273fc146e177e2f9",
"iso_checksum_type": "sha1",
"output_directory": "bakery_output_oel64",
"shutdown_command": "shutdown -P now",
"disk_size": 10000,
"format": "raw",
"headless": true,
"accelerator": "none",
"http_directory": "httpdir",
"http_port_min": 10082,
"http_port_max": 10089,
"ssh_host_port_min": 2222,
"ssh_host_port_max": 2229,
"ssh_username": "root",
"ssh_password": "root",
"ssh_port": 22,
"ssh_wait_timeout": "90m",
"vm_name": "oel6.4-vanilla-bakery",
"net_device": "virtio-net-pci",
"disk_interface": "virtio",
"boot_wait": "5s",
"boot_command":
[
" ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/kickstart.cfg"
]
}
]
}
]]]

Kickstart file looks like:

[[[
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp
rootpw root
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone UTC
bootloader

text
skipx
zerombr

clearpart --all --initlabel
part / --size=1 --grow
part swap --recommended

reboot

%packages --nobase
at
acpid
cronie-anacron
crontabs
logrotate
mailx
mlocate
openssh-clients
openssh-server
rsync
tmpwatch
which
wget
yum
-biosdevname
-prelink
%end

%post

# speed up SSH login by avoiding DNS lookup
echo "UseDNS no" >> /etc/ssh/sshd_config

# disable IPv6, http://wiki.centos.org/FAQ/CentOS6#head-d47139912868bcb9d754441ecb6a8a10d41781df
echo "# Disable IPv6" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf
sync
%end
]]]