[CentOS] ESX to KVM on CentOS (was:Re: How to list virt machine size with virsh?)

Fri Dec 9 16:12:06 UTC 2011
James Hogarth <james.hogarth at gmail.com>

> James, I'd be interested in knowing some of how you handled the ESX to KVM migration, and some caveats you might have found along the way.

This is from our internal wiki from notes I wrote at the time - will
be pretty busy here between now and christmas but happy to answer any
specific issues...  this should be fine for an initial start at
conversion points.... Note that was last edited 11/8/2010 so v2v tools
might be quicker from the non-existence they had back then ;)


Copy the disk image from vmware to kvm host

Stop the guest in VMware so that no data is being written to the disk
image and the file is not locked by any processes.
Rsync on the virtualserver from the ESX serevr to the local drive
rsync -h --progress
root at ostesx0[1-7]:'/vmfs/volumes/ost*/<guestname>/*-flat.vmdk'
On the KVM host after the disk is copied over convert it to a RAW
image. <something>.img should match the name of the disk that was
defined in the XML previously.
cd /var/lib/libvirt/images
qemu-img convert <something>-flat.vmdk -O raw <something>.img
Changes required in the guest

Boot with Centos Live CD - the template defined previously includes
the Centos LiveCD and booting from the CD so just start the VM guest.
Mount the disk in the live session
As the root user:
mkdir -p /media/guestdisk
mount /dev/vda1 /media/guestdisk
Chroot into the mounted disk
mount -o bind /dev /media/guestdisk/dev
mount -o bind /sys /media/guestdisk/sys
mount -o bind /proc /media/guestdisk/proc
chroot /media/guestdisk /bin/bash
Rebuild initrd with the virtio modules
mkinitrd -f --with=virtio_blk --with=virtio_pci
/boot/initrd-<mostrecentkernel>.img <mostrecentkernel>
You can get the most recent kernel version by:

ls -ltr /boot/vmlinuz* | tail -n 1
The output will look like:

-rw-r--r-- 1 root root 1954652 May 13 18:38 /boot/vmlinuz-2.6.18-194.3.1.el5
Where in the case given the kernel version would then be 2.6.18-194.3.1.el5

Remove VMwareTools
rpm -e VMwareTools
Check it is removed by:

rpm -qa | grep -i vmware
Then remove the vmware auto configure trickery in /etc/rc.local

vi /etc/rc.local

remove this block of text:

if [ -e /etc/vmware-tools/not_configured ]; then
    echo vmware-tools not configured for running kernel
    echo running vmware-config-tools.pl
    /usr/bin/vmware-config-tools.pl -d
    echo vmware-tools now compiled for running kernel
    echo restarting system
Check for any /etc/fstab changes needed
Change /boot/grub/devices.map
vi /boot/grub/devices.map

change /dev/sda to /dev/vda
Exit the chroot (exit or ctrl+D)
Ensure grub installed correctly on disk image
/media/guestdisk/sbin/grub-install --root-directory=/media/guestdisk /dev/vda
Unmount the disk and poweroff
umount /media/guestdisk/proc
umount /media/guestdisk/dev
umount /media/guestdisk/sys