March 1, 2011

Installing KVM



VMs have made working with multiple OSs a lot easier. And if you are a tinkerer like me, you can’t wait to get your hands on the latest system, and find that you nothing to install it on. Thank goodness for virtual processing. I’ve used serverel VM emulators such as Vmware and Virtualbox and both offer great advantages. Yet there are others, and not all VMs run good on every system. After doing some exploring and getting help some very good linux gurus, I came across KVM.


KVM (kernel-based virtual machine) is a virtual machine program that runs within the linux kernel. When it runs inside the kernel, it is treated like a normal linux process. This setup gives kvm priority when it requests services and execution from the cpu allowing better runtime performance.  KVM would be like any kernel module loaded within the kernel when the a linux system boots.

KVM does not have a gui interface nor does it provide machine emulation. Instead it responds to calls from a VM manager, like qemu/aqemu for resources in order for a VM guest to be created. KVM manages low-level resources like memory, diskspace, cpus etc. The VM manager (qemu/aqemu) takes those resources and creates the guest OS.  

KVM can run on a number of linux operating systems including Mac OSX, open solaris and others. For KVM to run on linux, the kernel must be of version 2.6.20 or later.  If running kvm on Intel or AMD hardware archs, both cpus must support VM extensions. For Intel, the cpu must have the Intel VT extension and for AMD, AMD-V extension. To see if your architecture supports KVM, run this command in your terminal.

grep -E 'vmx|svm' /proc/cpuinfo

If you get any type of output, then your system has support. Look closely at the output at the bottom image. If you see svm, then your AMD has support. Likewise, if you see vmx, then your Intel has support. 

You must also make sure that virtualization is enabled within your system BIOS. In IBM systems, this is enabled by default, for others you have to enable it manually. KVM consists of a loadable kernel module, the kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.

I’m using opensuse 11.3 with  LXDE to demonstrate the installation of kvm. Particularly, opensuse has a huge selection of system management and configuratioin options and can be very intimidating to normal users. The system opensuse runs on has the support for KVM. And after some tinkering, is wasn’t hard to install.

Again, to use kvm you must use a kernel version of 2.6.20 or later. latest kernels have kvm install already. If not you will have to install it manually through your systems repositories or download the source files. In opensuse, I used used YaST2 to download kvm from the repositories and install it. YaST2 works like a charm when it comes to package management. Arguably, it may perhaps be better then ubuntu’s synaptic package manager.  Go to the start menu, select systems, click administratioin, and select YaST. The YaST2 control center pops up. 

In the software section, search for and click “software management”. Once the software manager pops up, in the search tab, type kvm in the search box and click search. In the right window, you should see the options to install kvm select it.

Next you need to install qemu. Type qemu in the search box. Once you see qemu, select it. One you have both packages selected, click “accept”. A dialog box will pop-up showing the packages you installed and any dependencies that must be installed as well as packages that will be changed. One very important dependency is virt-utils. This needs to be install. Go ahead and click continue to install all packages.

Restart your machine to appy all changes. To confirm kvm is loaded within the kernel, open a terminal and type “lsmod”. Look at the list of modules. If you see kvm, then kvm has been loaded. You should also see the kvm module loaded for your cpu arch. In my case I have the kvm-amd module designed for amd arch.

Remember, to setup a virtual machine using kvm, you have to use qemu which is ran in the terminal. If you don’t want to use qemu, you can use aqemu which provides a gui interface to setup guest OSs using utilities provided from qemu.. Aqemu is not included in the opensuse repos, you will have to download the rpm manually.

To download aqemu, link to this site,, and download the rpm package designed for your arch. Go to the folder containing the rpm and click to install. The YaST package manager will open showing all the libraries that will be install along with aqemu. All you need to do is click accept, and the 

installation will execute.

When aqemu is ran for the first time, it must be adjusted for first time use. The aqem settings dialog box will open for you to ajust the program. Select the default settings to continue. You can always go back to the settings if you need to change anything in the future. 

Once the settings have been accepted, the aqemu window will open and you are ready to create your first guest OS. 

Now we need to pick an OS we want to install. You can pick any OS you like, for this tutorial, we will use a particular linux OS that I have found to be very useful on low-end machines, Xubuntu, I am using xubuntu for the reason of it being light weight. I have notice the stronger an operating system is, the longer it will take for it to install under aqemu if it will install at all. If you plan to use KVM as your default VM machine, I recommend using a dual core 64bit system with at least 2GB of ram.  

Insert your Linux OS cd/dvd into the cd/dvd rom. Wait for the media to mount. Then in the aqemu window, scroll to the menu bar, select file and click create a new HDD image. 

This will be a new image drive file, so leave “use base HDD image” unselected. In the “New Image File Name” section box, click the “browse button” and navigate to a place where you want to store the image file. I’ve chosen the aqemu folder and create a subfolder named VMs which is where I will store all my VM images. Name your hdd image file anything you want. I previously named mine zorin OS. Yet since zorin crashed kvm, I decided to delete the VM files pertaining to zorin and re-used the hdd image file I created previously.

When you are done click save which will return you back to the previous aqemu hdd image window. Click create and you now have a 10Gb hdd image file. You can leave the default settings or change them, the choice its yours.. Next, click the VM menu, go to “New VM” and select  “add new VM” and name your VM. 

Once you’ve named your VM, aqemu will show you the system resources that will be used with your VM.

Make sure the “boot priority” is set to CD-ROM and under the “Storage devices” section, CD/DVD-ROM is set to use cdrom, which is the host’s CD-ROM device and “HDA” is set to use the HDD image file that we created. You can change these settings using the above tabs. Click apply to accept the changes. Then on the action menu, click the blue arrow button which will began the guest OS installation.

Here is the xubuntu setup screen running in aqemu as you would see if booting a physical system from the CD-ROM. We will began the installation by selecting “install Xubuntu”. Again this process may take a while depending on the strength of your system. 

We are now preparing the installation of xubuntu. If you have installed linux before, this should be self explanatory. Go ahead and install the system they way you normally would. Keep in mind to be patient. KVM is a new development and is a little rough behind the edges. Plus, we are using the gui form of qemu which could prove to be unstable, so take your time with. 

Here is the fully installed xubuntu system running on kvm. Important note, once the installation completes, you have to change the boot order back to HDD, which will be the HDD image file we created. Admittedly, there is no big performance improvement from the more popular VM emulators like VMware or virtualbox. However it is another way to setup virtual processing. Although it ranks low on the performance scale on this system, I do like the fact of KVM running directly within the kernel which gives the VMs better processing scheduling. I only wished to have an available dual core system to really see the benefits of KVM.  



Click Here!