Wednesday, December 23, 2009

xen2kvm: Change a xen VM to run on KVM

If you want to move a guest running on a Xen host to a KVM host you can do the following:

1. Create a place-holder guest on the KVM host, note its mac address and shut it down.

2. Make the following changes to the Xen guest while its still running on the xen host:

  • Replace the xen kernel with a normal kernel: "yum install kernel"
  • Verify /etc/grub.conf will boot the new non-xen kernel by default
  • Comment out the following line in /etc/inittab:
    co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
    
  • Uncomment the following lines in /etc/inittab:
     1:2345:respawn:/sbin/mingetty tty1
     2:2345:respawn:/sbin/mingetty tty2
     3:2345:respawn:/sbin/mingetty tty3
     4:2345:respawn:/sbin/mingetty tty4
     5:2345:respawn:/sbin/mingetty tty5
     6:2345:respawn:/sbin/mingetty tty6
    
  • Modify /etc/sysconfig/network-scripts/ifcfg-eth0 to insert the MAC address from the place holder guest.
  • Shut the Xen guest down

3. Move the disk file from the Xen host to the KVM host:

  scp $USER@xen-host:/var/lib/xen/images/guest.img \
      $USER@kvm-host:/var/lib/libvirt/images/guest.img
In the above step you should be overwriting the disk file for the place-holder guest with the Xen guest's disk file.

4. Boot the guest on KVM.

I have tested the above on RHEL 5.4 and Fedora 12.

Thank you Chris Tyler for suggesting this approach in your blog.

Fedora 13 is scheduled to have a Xen to KVM migration script, so we'll see if the above is still necessary in May 2011.

No comments: