FreeSysAdmin.org
Virtual Machines: QEMU
Not logged in

Virtual Machines | Virtual Machines: QEMU | Virtual Machines: Linux-VServer | Virtual Machines: Use Cases


Setup of QEMU/KVM virtual machines

This page details the setup of standard base OpenSysAdmin.com QEMU / kQEMU / Kernel Virtual Machine (KVM) system images for various operating system distributions. For premade images see Virtual Machines.

Install of QEMU/KVM

Many distributions come with the kvm utilities (on debian, apt-get install kvm) and kvm built into their kernels. If you build custom kernels, you should also install the latest kvm utilities from http://kvm.qumranet.com/kvmwiki/Downloads .

Image File Creation

For all base images, the naming convention OS-DIST-RELEASE-ARCH.qcow is used. We use qcow1 instead of qcow2 for greatest compatibility. Here is a table of valid values:

OS

To create the image, do:

qemu-img create -f qcow OS-DIST-RELEASE-ARCH.qcow 40G

OS Install

Download the appropriate CD images (.iso files). If there is a choice of "server" or "minimal" versions, choose those. Make sure you have KVM (if your system supports hardware virtualization) or kQEMU (if not) installed.

The command you use to start the install is dependent on your architecture and whether or not your CPU supports hardware-based virtualization.

You want to do the minimal possible install that still has networking. In general this means deselecting all package clusters, and if there is a "custom" packages selection option going to those screens as well and deselecting everything there as well.

The host name should be the same as the image name, except without the ".qcow" extension.

The "root" password should be set to "SysAdmin".

On amd64 with Debian, you will need to use LILO instead of GRUB if GRUB install fails.

Packages

After the install is done, quit of of QEMU/KVM, and then restart the virtual machine without the "-cdrom cd.iso" and "-boot d" flags. We are now going to remove some packages we don't need, upgrade packages to the latest levels (which may include security fixes), and install some additional packages. Specifically:

Debian Etch

Edit the "/etc/apt/sources.list" file to not include the CD you installed from.

apt-get remove --purge ntp ntpdate

aptitude update
aptitude dist-upgrade
aptitude install screen ssh aria2 lftp lynx subversion wget ipsec-tools openssl openvpn racoon
aptitude clean

Fedora 7

rpm -e ntp
yum upgrade
yum install screen ssh aria2 lftp lynx subversion wget ipsec-tools openssl openvpn racoon
yum clean all

Configuration

Here each virtual machine is configured so the network is sane, serial console booting is possible ("-nographic" option to kvm/qemu), and the time is kept as sane as possible.

Debian Etch

Administravia

Serial Console

GRUB /boot/grub/menu.lst
LILO /etc/lilo.conf

Networking

On the host (bare metal) machine, do:

## Bridge interface (also serves as primary network interface) auto br0 iface br0 inet static address 18.85.22.58 netmask 255.255.255.0 broadcast 18.85.22.255 gateway 18.85.22.1 dns-nameservers 18.85.2.138 18.85.2.171 dns-search laptop.org media.mit.edu mit.edu bridge_ports eth0 bridge_stp off bridge_maxwait 5

And from now on start up the virtual machine with these additional flags:

-net nic,vlan=0,model=rtl8139 -net tap,vlan=0

So for example a complete invocation would look like:

qemu-system-x86_64 \
 -hda pedal.qcow \
 -nographic \
 -m 2000 \
 -net nic,vlan=0,model=rtl8139 \
 -net tap,vlan=0

You should now see an "eth0" device inside your virtual machine that can be used like a normal eth0 interface.

Fedora 7

Administravia

Serial Console

/etc/inittab - Add this line

s0:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt100

Also comment out ^!2-6*

/etc/crontab - Add these lines

* * * * * root (rm /etc/adjtime 2>/dev/null; sleep 15; hwclock -s --utc)
* * * * * root (rm /etc/adjtime 2>/dev/null; sleep 45; hwclock -s --utc)

GRUB /boot/grub/menu.lst

Networking

todo

Last Steps

Discussion

If you have questions or comments on this document, please post them to the Setup of QEMU/KVM virtual machines doc/images thread in the "General Help" section of the QEMU Forums.


Daniel Joseph Barnhart Clark is a supporter of Free Software Activism and the evolution of System Administration as a profession. As a hobby he maintains OpenSysAdmin.com and works on interesting Sys Admin problems; by day he is the System Administrator for One Laptop per Child. He encourages everyone to obtain low-cost (think monthly) warm fuzzies by becoming a member of the Free Software Foundation.