I recently updated some CentOS machines to version 5.4, which finally comes with KVM in addition to Xen. I wanted to boot up a few Ubuntu VMs using this new tool. There are a handful of resources out there that show how to use virt-install to create a Ubuntu guest on a KVM machine, but they all seem to assume you want to run a VNC session to use a graphical installer.
If you want to fully automate the installation process, the first thing you should do is switch to a text-based console. Here’s how to do it (at least on CentOS 5.4, KVM, using virt-install):
virt-install --connect qemu:///system --name vm01 --ram 512 --vcpus=2 --disk path=/vm/vm01/vm01.qcow2,size=12 --location http://ubuntu.osuosl.org/ubuntu/dists/hardy/main/installer-amd64 --os-variant ubuntuhardy --accelerate --network bridge:br0 --nographics --extra-args console=ttyS0
Some notes about my setup:
I already set up bridged networking – this varies from distribution to distribution, but should be something similar. I’m specifically pulling Ubuntu 8.04 (Hardy Heron) installer images from a nearby mirror. You’ll likely want to change the URL to a mirror close to you, and possibly change it to a different release of Ubuntu. I’ve setup the path /vm/vm_name/vm_name.qcow2 as the location for my VM image on disk, you may want to change this to use something like LVM or to match your own preferred path of choice.