Sep 302008
 

Kernel-based Virtual Machine (KVM) is a Linux kernel virtualization infrastructure. KVM is a full virtualization solution for Linux on x86 hardware containing virtualization extensions Intel VT (vmx) or AMD-V (svm). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM also requires a modified QEMU although work is underway to get the required changes upstream.

KVM is a free opensource virtualization software and is included in Linux Kernel version 2.6.20 and above. Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.


Install & use KVM in openSUSE

The following procedure will take you through install and setup of KVM and creating/running a Virtual Machine on openSUSE.

Hardware Requirements

KVM depends on the X86 virtualization extensions on your Intel or AMD processor. To check the processor support for KVM,

On an Intel based hardware,

opensuse11:~ # grep vmx /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida

On an AMD based hardware,

opensuse11:~ # grep svm /proc/cpuinfo

Install KVM

Add the following repositories for KVM and QEMU on your openSUSE 11.0

opensuse11:~ # zypper ar http://download.opensuse.org/repositories/Virtualization:/KVM/openSUSE_11.0/ “KVM Virtualization”

opensuse11:~ # zypper ar http://download.opensuse.org/repositories/Virtualization:/Qemu/openSUSE_11.0/ “QEMU Virtualization”

Now, we are ready to install KVM. Click “Computer – Install Software“, enter the password for root when prompted (if you are not a root user).
YaST
In the filter select search, and search for “kvm” and click search. Select “kvm” and “kvm-kmp-default” and click Accept. Here it is important to ensure that the kernel version of your openSUSE 11.0 matches that of the “kvm-kmp-default” package version to get it work properly.

To find the installed version of Linux Kernel on your openSUSE:

saibaba@opensuse11:~> uname -r
2.6.25.16-0.1-default

Now, your “kvm-kmp-default” version (as on my install) should be 75_2.6.25.16_0.1-7.1 where “75” denotes the KVM version and the rest shows the kernel version.

Similary, from YaST search for qemu and select “kqemu-kmp-default” and “qemu” and click Accept. “QEMU” is a CPU emulator and “KQEMU” is the QEMU Accelerator Module increases the speed of QEMU when a PC is emulated on a PC.

This should complete the installation.

Insert KVM Modules

Insert the kvm modules as follows (as root)

For Intel processors

opensuse11:~ # modprobe kvm
opensuse11:~ # modprobe kvm-intel

For AMD processors

opensuse11:~ # modprobe kvm
opensuse11:~ # modprobe kvm-amd

To confirm the modules OK,

opensuse11:~ # lsmod | grep kvm
kvm_intel              67824  0
kvm                   182936  1 kvm_intel

However, this setting lost on a reboot.

To insert this module at boot time, Click Computer – YaST – System – “/etc/sysconfig editor”. This launches the sysconfig editor.

Click “+” next to “system” and then “+” next to Kernel. Click “MODULES_LOADED_ON_BOOT“, in the right-pane, enter “kvm kvm-intel kqemu” without quotes (“kvm kvm-amd kqemu” for AMD) in the setting box and click finish. Click OK on the confirmation window.

Now, we are all set to configure and run a guest OS on your openSUSE.

Create Guest OS Disk image

Create a disk image file on which the guest OS will be installed.

opensuse11:~ # qemu-img create -f qcow /vms/deb_disk.img 10G

In the above “10G” indicates the Virtual Disk Size to be 10GB in size. The /vms/vdisk.img is the disk image name and “qcow” is the file type.

Install Guest OS

opensuse11:~ # qemu-system-x86_64 -hda /vms/deb_disk.img -cdrom /media.iso -boot d  -m 512

where “-m 512″ sets the memory allocation to 512M

“-cdrom /media.iso” is the CD image used to install the guest os
and defaults to the “user” network type which is a simple way for your virtual machine to access to the host, to the internet or to resources available on your local network.

This should start the QEMU console to start the installation. Install the Guest OS as you normally would. Once the installation is complete. Close the console window.

Start guest OS

Start the  Guest OS as follows:

opensuse11:~ # qemu-system-x86_64 -hda /vms/deb_disk.img


This starts the guest OS installed on /vms/deb_disk.img with the default user network settings which is a simple way for your virtual machine to access to the host, to the internet or to resources available on your local network. The above command is equivalent to

opensuse11:~ # qemu-system-x86_64 -hda /vms/deb_disk.img -net nic -net user

There you go, you have your Guest OS up and running. Multiple Guest OSs can be installed as above and run simultaneously based on the system performance level.