KVM Virtualization 101


For those of you who are familiar with virtualization, KVM is a hypervisor which is built into the Linux Kernel. This allows a Linux desktop or server to simulate multiple pieces of hardware, which can then have different operating systems installed. KVM uses the QEMU virtual machine format. QEMU may be familiar to those of you who have used video game emulators. KVM is essentially an advanced CPU emulator built into the Linux kernel.




To install kvm on Red Hat Enterprise 5.4 or above box use the following. This will install all of the necessary software to use KVM

yum install @kvm


To install kvm on a Fedora use the following. This will install all of the necessary software to use KVM and many utilities

yum install @Virtualization


Create New Virtual Machines

The fastest and easiest way to use KVM is using virt-manager. From the command line run the following. This program allows you to connect to hypervisors on the local system and can connect to hypervisors on other physical machines using ssh. The virt-manager program has several wizards for creating virtual machines which should be easy to use for anyone familiar with VMware or VirtualBox virt-manager


Convert from VMware Virtual Machines

Another way to create virtual machines is to convert them from VMware images. The directory in the command below includes the VMware .vmx file and all the .vmdk referenced in the .vmx file.

virt-convert -i vmx -o virt-image scott-vmx/ scott-kvm/


Remember: VMware images must first be converted to a single file, pre-allocated disk format. Also the .vmx file must be changed to match the new names of the .vmdk files, or the files must be renamed back to the original name. The vmware-vdiskmanager utility cannot convert disks in place. This must be done on the VMware server before it is moved to the KVM server.

vmware-vdiskmanager -r scott.vmdk -t 2 scott-padf.vmdk


Now, it is time to make the newly imported virtual machine recognized by the KVM hypervisor

virt-image scott-kvm/scott.virt-image.xml


Basic Commands

To list all of the virtual machines which are running on a system use virsh

virsh list


It is a good idea to backup the configuration for any virtual machines that are created in a format that is easy to import later. I normally save this virsh XML to a file in the directory with the virtual machine. This keeps everything together just like a VMware virtual machine.

virsh dumpxml > scott-kvm/scott.xml


Finally, once a machine is defined and running, it is a good idea to make it autostart on boot if desired. Notice that the files that are created and removed from /etc/libvirt/qemu/autostart

virsh autostart scott



Once you have backed up the configuration for one of your new virtual machines, try to remove it and re-add it with the virsh define and undefine commands

virsh undefine scott


Now look at your list of virtual mchines

virsh list


Redefine the machine using your backed up XML file

virsh define scott-kvm/scott.xml


Now look at your list of virtual mchines again

virsh list


Leave a Reply

Your email address will not be published. Required fields are marked *