Installing KVM Guests With virt-install On Ubuntu 12.10 Server
Author: Falko Timme
Follow me on Twitter
Last edited 11/27/2012
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 12.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 12.10). My KVM host has the IP address 192.168.0.100.
I will show how to install a CentOS 6.3 guest in this tutorial.
We also need an Ubuntu 12.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 12.10 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 12.10 Host:
Open a terminal and install virt-install:
sudo apt-get install virtinst
3 Installing virt-manager On Your Ubuntu 12.10 Desktop
Ubuntu 12.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 12.10 desktop (it doesn't matter if it is a remote desktop of if the desktop is installed on the Ubuntu 12.10 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 6.3 Guest
Ubuntu 12.10 KVM Host:
Now let's go back to our Ubuntu 12.10 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 6.3 guest (in bridging mode) with the name vm10, 1024MB 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 1024 --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-6.3-x86_64-bin-DVD1.iso
... and use the ISO image in the virt-install command:
sudo virt-install --connect qemu:///system -n vm10 -r 1024 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/CentOS-6.3-x86_64-bin-DVD1.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 1024 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/CentOS-6.3-x86_64-bin-DVD1.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.