A year ago I wrote about how to convert from Xen to VMWare (which is a similar process to a Xen virtual-to-physical or V2P conversion). Now I found a much simpler solution, thanks to http://www.zomo.co.uk/2012/04/moving-disks-from-xen-to-kvm/ .
In this example, I’m using LVM disks, but the process is no different from using Xen disk images.
- Install Debian Wheezy into a VMWare virtual machine. Attach a secondary virtual disk (it will be called /dev/sdc from now on) that’s sized about 500 MB larger than your Xen DomU (just to be safe). Fire up the VM. All subsequent commands will be run from inside that VM.
- Check whether your DomU disk has a partition table: ssh root@xen fdisk -l /dev/xenvg/4f89402b-8587-4139-8447-1da6d0571733.disk0. If it does, proceed to step 3. If it does not, proceed to step 4.
- Clone the Xen DomU onto the secondary virtual disk via SSH: ssh root@xen dd bs=1048576 if=/dev/xenvg/4f89402b-8587-4139-8447-1da6d0571733.disk0 | dd bs=1048576 of=/dev/sdc. Proceed to step 7.
- Zero out the beginning of the target disk: dd if=/dev/zero of=/dev/sdc bs=1048576 count=16
- Partition it and add a primary partition 8 MB into the disk: fdisk /dev/sdc, o Enter w Enter, fdisk /dev/sdc, n Enter p Enter 1 Enter 16384 Enter Enter, w Enter
- Clone the Xen DomU onto the secondary virtual disk’s first partition via SSH: ssh root@lara dd bs=1048576 if=/dev/xenvg/4f89402b-8587-4139-8447-1da6d0571733.disk0 | dd bs=1048576 of=/dev/sdc1
- reboot
- Mount the disk: mount -t ext3 /dev/sdc1 /mnt; cd /mnt
- Fix fstab: nano etc/fstab: change root disk from to /dev/sda1
- Fix the virtual console: nano etc/inittab: replace hvc0 with tty1
- Chroot into the disk: mount -t proc none /mnt/proc; mount -t sysfs none /mnt/sys; mount -o bind /dev /mnt/dev; chroot /mnt /bin/bash
- Fix mtab so the Grub installer works: grep -v rootfs /proc/mounts > /etc/mtab
- Install Grub: apt-get install grub2. When the installer asks to which disks to install, deselect all disks.
- Install Grub to MBR: grub-install –force /dev/sdc
- Update Grub configuration: update-grub
- Leave the chroot: exit; umount /mnt/* /mnt
- shutdown
Now you can detach the secondary virtual disk and create a new VM with it. If everything worked correctly, it will boot up.