This guide is based on Ubuntu 12.04 and assumes that you already have a working virtualization environment based on KVM / libvirt, e.g. by following this tutorial.


To automate the installation of virtual machines with vmbuilder first install python-vm-builder

sudo apt-get install python-vm-builder

Optimize settings

Vmbuilder by default uses virtio for the network interface but not for the virtual hard disk which makes the virtual machines very slow. To fix this edit /etc/vmbuilder/libvirt/libvirtxml.tmpl and change the line


Since my virtual machines require a pointopoint entry in /etc/network/interfaces I also edit
/etc/vmbuilder/ubuntu/interfaces.tmpl and add an additional line pointopoint underneath gateway. This will set pointopoint to the gateway address that I specify with vmbuilder.

pointopoint $gw

As a last ugly rather hack I edit /usr/share/pyshared/VMBuilder/plugins/kvm/ and change the default file image type from qcow2 to raw to improve the disk throughput.

filetype = 'raw'

Instead of editing you could also use the qemu-img command after running vmbuilder to convert the qcow2 image to raw (or just keep qcow2 if you are fine with it).

Run vmbuilder

Now run vmbuilder to install a virtual machine with Ubuntu 12.04 (adjust the parameter settings as needed of course):

sudo vmbuilder kvm ubuntu --suite precise --flavour virtual --arch amd64 --libvirt qemu:///system --hostname gonzo --ip --net --mask --bcast --gw --domain --user john --name john --pass 12345 --verbose --rootsize=20480 --swapsize=2048 --mem 1024 --cpus 1 --addpkg=openssh-server --addpkg=vim --addpkg=acpid --dest=/var/lib/libvirt/images/gonzo/

For any new VM repeat the command with the right hostname and IP’s.


You have to be very careful with not overwritting existing images with vmbuilder (happens when you use the -o parameter), all files in the destination folder will be deleted. That’s why i am using the hostname for the destination directory to have a unique subfolder. The other parameters are very well explained in the Ubuntu Server guide at

One bug remains though, occasionally I receive grub error messages and the virtual machine does not start, there is a bug report about the issue at In this case it helps to just delete the VM and try it again using the exactly same command.