Convert a VMware virtual machine to KVM

Just a quick note to myself, about the process of Converting a VMware Virtual Machine machine to KVM.

Copy the VMDK files

Locate all the VMDK files, and copy to the new server.

rsync -av --numeric-ids --progress -e "ssh -T -c arcfour -o Compression=no -x" vmware-server:/local/vm/X/ /mnt/tmp/

Using the -c option to select the cipher for ssh will increase network throughput and reduce CPU usage (useful over internal LANs).

Converting from VMDK to RAW

The basic command will look like this,

qemu-img convert x.vmdk x.raw

But if you have multiple VMDK files, you can convert them all in a batch with this command

find . -name "*-s0*.vmdk" -exec qemu-img convert '{}' '{}.raw' \;

 Concatenate all the files

You can dump the files to a single RAW file or directly to a LVM volume or in my case a DRBD resource. And i use pv (pipe view) to have some indication on the process.

cat my-vm-disk2-s001.vmdk.raw \
    my-vm-disk2-s002.vmdk.raw \
    my-vm-disk2-s003.vmdk.raw \
    my-vm-disk2-s004.vmdk.raw \
    my-vm-disk2-s005.vmdk.raw \
    my-vm-disk2-s006.vmdk.raw | pv -Werp > \
    [/dev/drbd/by-res/my-vm-vdb | /dev/VolumeGroup/LV-vm1 | file.raw]

If you you know the total size of the image you can use the -s switch with pv to watch the progress bar fill.

Extra: Switching from IDE to VIRTIO

This one i have learned when i had to convert a XEN vm to KVM, so i had to do a bunch of adjustment to the vm to make it work on KVM, one of them is to re-build the kernel initrd.

  • First make sure you have a generic kernel on them VM
  • (This one i’m not sure, but i did it any way) – in the file /boot/grub/, change any reference from xvdX to vdX
    # this device map was generated by anaconda                                     
     (hd0)     /dev/vda
  • Add virtio_blk to initrd using mkinitrd (!!! your kernel version number may be different)
    cd /boot
     mv initrd-2.6.18-308.8.2.el5.img initrd-2.6.18-308.8.2.el5.img.bak
     mkinitrd -f --with=virtio_blk --with=virtio_pci --builtin=xenblk initrd-2.6.18-308.8.2.el5.img 2.6.18-308.8.2.el5
  • Add virtio_blk to “/etc/modprobe.conf” file, should look like
    alias scsi_hostadapter virtio_blk
  • To add console support, edit “/etc/inittab” file and find the following section
    # FROM this
    # Run gettys in standard runlevels
    co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
    #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
    # should look like
    # Run gettys in standard runlevels
    #co:2345:respawn:/sbin/agetty xvc0 9600 vt100-nav
    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


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *