Red Hat Enterprise Linux 6 does not support Xen-based virtualization. If you upgrade to this operating system, which is now in beta, you'll need to migrate current Xen virtual machines (VMs) to the Kernel-based Virtual Machine (KVM) platform.
Red Hat is working on virt-v2v, a tool to make the Xen-to-KVM virtual machine migration process easier. But today, there is only a manual method. This article explains how it works, but be warned: It's not for those intimidated by the Linux command line.
Preparing a guest for a Xen-to-KVM migration
The first part of the Xen-to-KVM virtual machine migration process concerns configuring the Xen guest. You'll need to update references to the console, because Xen uses the xvc0 device, whereas a KVM virtual machine uses the ttyS0 device. One or more of the following files may refer to the device:
Identify the files that refer to the device, and make the changes.
Next is the disk device, which the VM references in these two files:
If you are going to use virtio drivers in the VM, change the device from /dev/xvda, the Xen disk device, to /dev/vda, a KVM disk device. If not, change it to another KVM disk device, /dev/hda. (Changing the device in /etc/fstab isn't necessary in all situations, but only when you don't set up the VM to use disk labels. You always need to change the device in /boot/grub/device.map, though.)
You'll also have to change the kernel. Xen VMs use a specific Xen kernel, but for a KVM virtual machine, you need to change to a default KVM kernel. First, install the default kernel using the Yum install kernel command. Then update the initrd system, which contains required drivers for booting the kernel. To update initrd, use this command:
mkinitrd -v -f --with=virtio_pci --builtin=xenblk /boot/nameoftheinitrd kernel-version
You can find the real name of the initrd system in /boot, and use the uname --r command to get the current version of the kernel.
Now make sure the /etc/sysconfig/kernel file refers to the new kernel. Do so by including the line DEFAULTKERNEL=kernel in this file.
Finally, use virtio drivers to ensure the best possible performance of the KVM virtual machine. Include the following two lines in /etc/modprobe.conf to load these drivers when booting the VM:
alias scsi_hostadapter virtio_blk
alias eth0 virtio_net
Preparing the host for a Xen-to-KVM migration
After setting up the guest for a Xen-to-KVM virtual machine migration, prepare the virtual host. First, install the standard kernel and reference it in the /etc/sysconfig/kernel file. Then take care of Security-Enhanced Linux, which causes problems in KVM when logical volumes are used as a storage back end. To prevent these issues, use the setenforce 0 command.
The next step is to build a network bridge that Xen can use to access the physical network connection. Create the file /etc/sysconfig/network-scripts/ifcfg-br0, containing the following lines:
Then connect the bridge to your eth0 network card by creating the configuration file /etc/sysconfig/network-scripts/ifcfg-eth0 with the following content:
HWADDR=MAC address of the hardware eth0 card
Doing so allows you to restart the host computer with the new kernel. The Xen-to-KVM virtual machine migration is almost complete, but there are two last important steps. After rebooting, create a new configuration file for the KVM virtual machine you have just transformed. Use the virt-manager utility to specify the following items for the guest:
- the name you want to use to identify the guest;
- the specific CPU architecture that the guest uses;
- OS type and version;
- the storage back end that the Xen machine used;
- network configuration; and
- the amount of memory and number of CPU cores.
Don't start a new installation on the guest machine, as this overwrites all Xen VM configurations.
After creating the new KVM virtual machine configuration file, use the virsh edit command to edit its disk specifications. Find the code that defines the primary disk file in use. It should look like this:
disk type='block' device='disk'
target dev='hda' bus='ide'/
Change the target line to use the virtio driver for the hard disk:
target dev='vda' bus='virtio'/
And you should now have a fully functional KVM virtual machine.
About the expert
Sander van Vugt is an independent trainer and consultant based in the Netherlands. Van Vugt is an expert in Linux high availability, virtualization and performance and has completed several projects that implement all three. He is also the writer of various Linux-related books, such as Beginning the Linux Command Line, Beginning Ubuntu Server Administration and Pro Ubuntu Server Administration.
Dig deeper on Open source virtualization