Installing KVM Guests With virt-install On Ubuntu 8.10 Server
Author: Falko Timme
Last edited 02/09/2009
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 8.10 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 8.10). My KVM host has the IP address 192.168.0.100.
I will show how to install a CentOS 5.2 guest in this tutorial.
We also need an Ubuntu 8.10 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 8.10 KVM server or on a remote system.
2 Installing virt-install
Open a terminal and install virt-install:
sudo apt-get install python-virtinst
3 Installing virt-viewer Or virt-manager On Your Ubuntu 8.10 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 8.10 desktop (it doesn't matter if it is a remote desktop of if the desktop is installed on the Ubuntu 8.10 KVM server!).
If you want to use virt-viewer, run
sudo apt-get install virt-viewer
If you want to use virt-manager, run
sudo apt-get install virt-manager
4 Creating A CentOS 5.2 Guest
Take a look at
to learn how to use it.
To create a CentOS 5.2 guest (in bridging mode) with the name vm10, 512MB of RAM, two virtual CPUs, and the disk image ~/vm10.qcow2 (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 -f ~/vm10.qcow2 -s 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...
sudo dd if=/dev/cdrom of=~/CentOS-5.2-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 -f ~/vm10.qcow2 -s 12 -c ~/CentOS-5.2-x86_64-bin-DVD.iso --vnc --noautoconsole --os-type linux --accelerate --network=bridge:br0 --hvm
(I've left out the --os-variant=centos5 switch because virt-install was complaining that it doesn't know the operating system variant centos5, although the man pages says something else. Anyway, the installation worked flawlessly even without that switch.)
5 Connecting To The Guest
The KVM guest will now boot from the CentOS 5.2 DVD and start the graphical CentOS installer - that's why we need to connect to the graphical console of the guest. You can either do this with virt-manager (see KVM Guest Management With Virt-Manager On Ubuntu 8.10) or with virt-viewer. I will show how to do this with virt-viewer.
If virt-viewer is installed on the KVM server, you can run
sudo virt-viewer vm10
If virt-viewer is installed on a remote Ubuntu desktop, run
sudo virt-viewer --connect qemu+ssh://email@example.com/system vm10
(Replace 192.168.0.100 with the IP address or hostname of the KVM host. Please note that the root account must be enabled on the KVM host, and that root logins must be allowed on the KVM host. To enable the root login on an Ubuntu system, run
sudo passwd root
To check if root logins are allowed check the directive PermitRootLogin in /etc/ssh/sshd_config - you might have to restart the SSH daemon afterwards. )
You should now be connected to the graphical console of the guest and see the CentOS installer:
Now install CentOS as you would normally do on a physical system. Please note that at the end of the installation, the CentOS system needs a reboot. The guest will then stop, so you need to start it again, either with virt-manager or like this on the KVM host's command line:
sudo virsh --connect qemu:///system
Afterwards, you can connect to the guest again with virt-viewer or virt-manager and complete the installation.
6 Cloning Guests
The python-virtinst package comes with a second tool, virt-clone, that lets you clone guests. To clone vm10 and name the clone vm11 with the disk image ~/vm11.qcow2, you simply run
sudo virt-clone --connect qemu:///system -o vm10 -n vm11 -f ~/vm11.qcow2
Afterwards, you can start vm11 with virt-manager or like this...
sudo virsh --connect qemu:///system
... and connect to it using virt-manager or virt-viewer.
- KVM (Ubuntu Community Documentation): https://help.ubuntu.com/community/KVM
- Ubuntu: http://www.ubuntu.com/