Migrating a VM from Xen to KVM

written by Christian Schell

My company is migrating to a new infrastructure for its virtual machines and switching from XenServer to KVM. This week we had to tackle the migration of existing Xen-VMs to the new hypervisor – turned out that this has been trickier than I thought it would be!

This is a description of how we migrate VMs from a XenServer to an Ubuntu 14.10 with KVM. The VMs run with Debian.

Get the image to the destination server

You have to get an image from the Xen VM. Our machines are snapshotted every night (using NAUBackup), so for my test vm "TestVM01" I already had the appropriate .xva image.

The next step is to transfer that image to the destination server running KVM. Before you transfer the image you might want to zip it first:

To be honest, I have no idea how the script works. There are a some similar scripts out there that claim to do the same – of those I tried, only this worked for me.

Prepare the image

Access the image

Xen doesn't need Grub as bootloader, so we have to install it. To do so, we have to be able to access the file system, so we have to mount the vm's system partition first and wire up basic system folders so we can chroot into it:

You now need to connect to the vm as quickly as you can via VNC (get the port using virsh vncdisplay TestVM01). In my cases I had to press e in the bootloader and remove the lines containing loop1 in order to get Debian booting. Did the VM boot successfully you need to reinstall grub again:

grub-install /dev/vda
update-grub

That did the trick for me! If you have any thoughts or tipps on this, please let me know!