Installing KVM Guests With virt-install On Ubuntu 11.04 Server
Author: Falko Timme
Follow me on Twitter
Unlike virt-manager, virt-install is a command line tool that allows you to create KVM guests on a headless server. You may ask yourself: "But I can use vmbuilder to do this, why do I need virt-install?" The difference between virt-install and vmbuilder is that vmbuilder is for creating Ubuntu-based guests, whereas virt-install lets you install all kinds of operating systems (e.g. Linux, Windows, Solaris, FreeBSD, OpenBSD) and distributions in a guest, just like virt-manager. This article shows how you can use it on an Ubuntu 11.04 KVM server.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
I'm assuming that KVM is already installed (e.g. as shown here: Virtualization With KVM On Ubuntu 11.04). My KVM host has the IP address 192.168.0.100.
I will show how to install a CentOS 5.6 guest in this tutorial.
We also need an Ubuntu 11.04 desktop so that we can connect to the graphical console of our KVM guests. It doesn't matter if the desktop is installed on the Ubuntu 11.04 KVM server or on a remote system (there are small differences if the desktop is installed on the KVM host compared to a remote desktop, but I will outline these differences, so read carefully).
2 Installing virt-install
Ubuntu 11.04 KVM Host:
Open a terminal and install virt-install:
sudo apt-get install virtinst
3 Installing virt-manager On Your Ubuntu 11.04 Desktop
Ubuntu 11.04 Desktop:
We need a means of connecting to the graphical console of our guests - we can use virt-viewer or virt-manager (see KVM Guest Management With Virt-Manager On Ubuntu 8.10) for this. I'm assuming that you're using an Ubuntu 11.04 desktop (it doesn't matter if it is a remote desktop of if the desktop is installed on the Ubuntu 11.04 KVM server!).
I suggest you use virt-manager instead of virt-viewer because virt-manager lets you also create and delete virtual machines and do other tasks. virt-manager can be installed as follows:
sudo apt-get install virt-manager
4 Creating A CentOS 5.6 Guest
Ubuntu 11.04 KVM Host:
Now let's go back to our Ubuntu 11.04 KVM host.
Take a look at
to learn how to use it.
We will create our image-based virtual machines in the directory /var/lib/libvirt/images/ which was created automatically when we installed KVM.
To create a CentOS 5.6 guest (in bridging mode) with the name vm10, 512MB of RAM, two virtual CPUs, and the disk image /var/lib/libvirt/images/vm10.img (with a size of 12GB), insert the CentOS DVD into the CD drive and run
sudo virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /dev/cdrom --vnc --noautoconsole --os-type linux --accelerate --network=bridge:br0 --hvm
Of course, you can also create an ISO image of the CentOS DVD (please create it in the /var/lib/libvirt/images/ directory because later on I will show how to create virtual machines through virt-manager from your Ubuntu desktop, and virt-manager will look for ISO images in the /var/lib/libvirt/images/ directory)...
sudo dd if=/dev/cdrom of=/var/lib/libvirt/images/CentOS-5.6-x86_64-bin-DVD.iso
... and use the ISO image in the virt-install command:
sudo virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/CentOS-5.6-x86_64-bin-DVD.iso --vnc --noautoconsole --os-type linux --accelerate --network=bridge:br0 --hvm
The output is as follows:
administrator@server1:~$ sudo virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/CentOS-5.6-x86_64-bin-DVD.iso --vnc --noautoconsole --os-type linux --accelerate --network=bridge:br0 --hvm
Allocating 'vm10.img' | 12 GB 00:00
Creating domain... | 0 B 00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.