Fun with KVM on Squeeze

Have recently received a server from a friend which I’m going to be using to replace my existing one. It’s currently running a handful of virtual hosts with Xen using paravirtualisation. The new server has hardware virtualisation so I thought I would try KVM as it seems more in vogue these days. There is a useful KVM/Debian Squeeze Howto on which gave me a good grounding on most things.

It seems quite good so far, but not without some minor issues.

Boot order

I experienced a problem between the cgroups and libvirt-bin. By default it seems that cgroups (/etc/init.d/cgred) starts before libvirt-bin and this stopped my virtual machines from starting up. It gave the following errors trying to start the “test1” virtual machine (VM).

warning : qemudParsePCIDeviceStrs:1422 : Unexpected exit status '1', qemu probably failed
error : qemuSetupCgroup:3416 : Unable to create cgroup for test1: No such file or directory
error : qemuRemoveCgroup:3501 : internal error Unable to find cgroup for test1#012
warning : qemudShutdownVMDaemon:4067 : Failed to remove cgroup for test1

Not being too knowledgeable with the new dependency based boot system it took me a while to work out how to get it to change the order but eventually I edited /etc/init.d/libvirt.bin and changed the line

# Required-Start:    $network $remote_fs $syslog


# Required-Start:    $network $remote_fs $syslog cgred

Then you need to apply this change with the following command:

insserv libvirt-bin

This makes the dependency make sure it starts after cgred. Whether this is the “official” way I don’t know, but this now works correctly for me.

Starting VM at boot

By default new virtual machines do not start with the computer but this can be enabled:

virsh autostart <vmname>

as well as disabled

virsh autostart <vmname> --disable

Shutting down VMs on reboot/shutdown

As I only have on server I will be wanting to (at least try to) shut down virtual machines when I shutdown or reboot rather than killing them which seems to happen by default. An entry on Vivek’s blog has a script which can do this. It has been noted in the comments that this does not get called with the new Debian dependency boot scripts.

I have, for now hacked my libvirt-bin init.d script, amendnig the “stop” section to call this script just before the libvirt daemon is shutdown.

Not the most elegant, but works for now. I’ll have to try and tidy that up.