Converting from VMware to Linux KVM

Many environments are either using virtualized servers, or are planning to convert.  However, not every install needs all the features of VMware.  Or perhaps you want to add a test VM server to augment your production VMware cluster.  KVM, included in Linux distributions using kernel 2.6.20 and later, may meet your needs. This includes RHEL 6, Ubuntu 9.10, etc. It replaces the Xen VM packages used as a hypervisor in earlier Linux distributions. It is positioned as a server-virtualization platform, and has enhanced-performance paravirtual network and disk drivers for guest operating systems.

Red Hat has documentation on how to install/configure it under a standard RHEL 6 build. However, some of the tools are still being modified, and not all of the documentation matches the current reality.  Read their documentation first.

Required Packages

Not all Linux distributions install the KVM packages by default.  Under Red Hat, you can add the packages via yum:

yum install kvm virt-manager libvirt libvirt-python python-virtinst libvirt-client

VM Images: Flat files versus Volume groups

By default, KVM stores disk images as flat files in /var. This is reasonable for most workstation installs, where performance and VM expandability aren’t an issue.  The installation will automatically configure the proper SELinux context for the directory.

% ls -Zd /var/lib/libvirt/images
drwx--x--x. root root system_u:object_r:virt_image_t:s0 /var/lib/libvirt/images/

However, if your system has /var as its own partition, it may be too small to hold the VM disk images. You can resize the volume, create an additional volume for this mountpoint, or store the images elsewhere. If you store them on another partition, remember to set the SELinux context.

semanage fcontext -a -t virt_image_t "/data/libvirt/images(/.*)?"
restorecon -F -R -v /data/libvirt/images

As an alternative to flat files, you can create logical volumes in LVM, dedicating a volume per VM.  This allows you to easily expand your virtual disks as needed, and provides a performance benefit. Both the virt-manager GUI and the virt-install command-line support LVM-based storage.

% virsh vol-info --pool VolGroup00 vm_rhel6-32
Name:           vm_rhel6-32
Type:           block
Capacity:       10.00 GB
Allocation:     10.00 GB

Moving a VMware VM into KVM

The VMware “flat” .vmdk files can be read directly by QEMU/KVM, which allows you to import a disk image directly into KVM using the virt-install(1) with the “–import” option. However, moving this image to a logical volume may improve performance. You’ll need to confirm the image is a “raw” format, and the virtual disk’s exact size.

# qemu-img info /var/libvirt/images/RHEL5_32bit-flat.vmdk
image: /var/libvirt/images/RHEL5_32bit-flat.vmdk
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 10G

Next, create a logical volume of the same size, then use dd(1) to copy the disk image to the volume.

lvcreate -L10GB -n vm_rhel5-32 vg_kvms
dd if=/var/libvirt/images/RHEL5_32bit-flat.vmdk of=/dev/vg_kvms/vm_rhel5-32 bs=1M

If you’ve already created a VM using the disk image, you can either recreate the virtual host, or just edit the existing definition.

virsh dumpxml rhel5-32 > /tmp/rhel5-32.orig
virsh edit rhel5-32

Change the disk entry as needed, particularly the “type” and “source”:

Original:

   <disk type='file' device='disk'>
     <driver name='qemu' type='raw' cache='none'/>
     <source file='/var/libvirt/images/RHEL5_32bit-flat.vmdk'/>
     <target dev='hda' bus='ide'/>
     <address type='drive' controller='0' bus='0' unit='0'/>
   </disk>

New:

   <disk type='block' device='disk'>
     <driver name='qemu' type='raw' cache='none'/>
     <source dev='/dev/vg_kvms/vm_rhel5-32'/>
     <target dev='hda' bus='ide'/>
     <alias name='ide0-0-0'/>
     <address type='drive' controller='0' bus='0' unit='0'/>
   </disk>

Once you’re up and running, remove the VMware tools and re-enable the ACPI daemon, or else the host-based shutdown/reboot options won’t work.

/usr/sbin/vmware-uninstall.pl
chkconfig acpid on

While not as full-featured as VMware ESX, KVM can more meet the virtualization needs of smaller shops.

Comments (0)

› No comments yet.

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Pingbacks (0)

› No pingbacks yet.