Migrating CentOS Linux installed Xen instance to KVM is really tricky. This note contains one of the way to migrate.
Here I have used SolusVM for Xen based instances and Proxmox for KVM based instances.
PS: This will work with Linux Only. For eg. I have used CentOS6 linux
Here are the steps to migrate:
1. Get Image of Xen VM:
If it is a Image file already then no issues. In case of it is Logical Volume then need to create image from the volume.
First need to find the volume for specific VM. Then shutdown the VM
Create image of the volume using below command:
dd if=/dev/mapper/vm<number> of=xenvm.img bs=1M
2. Copy that image to Proxmox or KVM installed node to the appropriate storage.
3. Create blank disk for KVM on Proxmox Node
dd if=/dev/zero of=kvmvm.raw bs=1M count=12288
4. Need to create Partitioning like Xen VM. So as we have only one Partition in Xen VM. We will just create one Partition inside the kvmvm image.
parted kvmvm.raw
(parted)$ mklabel msdos
(parted)$ mkpart primary ext3 0 12288M
(parted)$ set 1 boot on
(parted)$ quit
5. Load dm-mod module
modprobe dm-mod
6. Create drivers to access partition inside kvmvm.raw
losetup /dev/loop0 kvmvm.raw
kpartx -a /dev/loop0
Now you can access partition1 inside kvmvm.raw using /dev/mapper/loop0p1
7. Time to push the image of XenVM on partition1 of kvmvm.raw using dd
dd if=xenvm.img of=/dev/mapper/loop0p1 bs=1M
8. Run Filesystem check on ext3 filesystem to correct the errors.
fsck -f /dev/mapper/loop0p1
9. Create VM in Proxmox also use harddrive image as raw and now qcow2. Replace that VM’s image file with kvmvm.raw.
10. Now if we boot Proxmox VM, it wont boot successfully. We will need to install or update grub first. To do so use CentOS / Ubuntu installation CD image and boot VM into rescue mode with chroot enabled. VM’s drive will be mounted on /mnt/sysimage
11. Install grub
chroot /mnt/sysimage
grub
grub> root (hd0,0)
grub> find /boot/grub/stage1
grub> setup (hd0)
12. Change in /boot/grub/grub.conf.
Remove console=hvc0 xencons=tty0 from line number 5 starts with kernel.
And change root device from /dev/xvda1 to /dev/sda1
It’s kernel line should look like below:
kernel /boot/vmlinuz-2.6.32-279.el6.x86_64 root=/dev/sda1 ro
Please note that Kernel version may change as per your OS.
13. Change in /etc/fstab
Replace /dev/xvda to /dev/sda.
14. Reboot now.