Migrate Xen to KVM

Migrate Xen to KVM

From Consultancy.EdVoncken.NET

Jump to: navigation, search


I used the excellent tutorial by nixCraft as a starting point when migrating several Xen PV virtual machines (CentOS 5.x x86_64) to KVM.

My VMs use raw LVM volumes instead of normal files; this was done for performance reasons. I have multi-terabyte VMs that simply would not work as a file-backed Xen VM.

Initial approach:

  • Prepare the guest for migration
  • Prepare the host for migration
  • Migrate
  • Done!

Prepare the guest for migration

Create an LVM snapshot

The test-VM is called "guest", stored as an LVM volume: /dev/vg_md1/lv_domU_guest. First, shut down the VM and create a snapshot (4GB should be enough to hold changes):

 xm shutdown guest
 lvcreate -L 4G -n lv_snap_guest -s /dev/vg_md1/lv_domU_guest

Modify the Xen configuration file (/etc/xen/guest) so the VM starts from the snapshot instead of the original volume:

 disk = [ 'phy:/dev/vg_md1/lv_domU_guest,xvda,w', ]

Changed to read:

 disk = [ 'phy:/dev/vg_md1/lv_snap_guest,xvda,w', ]

Start the VM guest from the LVM snapshot to see if it still boots properly:

 xm create guest

Voila! The LVM snapshot will be used for testing. If things go wrong, simply remove the snapshot and revert the changes.

Reconfigure the guest for KVM

Log on to the guest, and make the following modifications:

  • Install a non-Xen kernel (yum install kernel) and make it the default in /etc/grub.conf
  • Disable the Xen serial console in /etc/inittab:
 #co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav

Shut down the guest:

 xm shutdown guest

Prepare the host for KVM

Install KVM

Install KVM plus a standard, non-Xen kernel on the host and make it the default in Grub:

 yum install kernel kvm virt-manager libvirt libvirt-python python-virtinst
 vi /etc/grub.conf

Reboot the host to the non-Xen kernel.

Reconfigure host network

Set up network bridging on all relevant interfaces.

Test the migration

Start the guest under KVM:

 /usr/libexec/qemu-kvm -hda /dev/vg_md1/lv_snap_guest -net nic,model=e1000,macaddr=00:16:3e:c0:ff:ee -net tap -m 2048 -vnc :0

Connect to the VNC console using vncviewer:

 vncviewer localhost:0

You should see the guest booting under KVM.

Actual migration