Thursday, December 25, 2008

Converting split vmdk files to qcow2

I've been playing around with VM environments recently.  I've got some legacy golden VMs created with VMWare server that I'd like to run under the Linux KVM environment.  There are a couple of challenges here:

1) convert disk format
2) make the VM boot under the different VM environment

For now, I'm addressing item #1.  The standard recipe is to run qemu-img on the .vmdk file to create a qcow2 disk image.  Unfortunately this doesn't work in my scenario because I'm using a vmdk split into sparse (2GB) files, which causes the standard invocation to fail.

Assuming that you have access to both a set of VMWare and QEMU binaries available, this can be achieved with a two step process:

1) convert from split files into single, growable image file.  Invocation for this is:

vmware-vdiskmanager -r "source.vmdk" -t 0 "temp.vmdk"

The option "-t 0" tells vdiskmanager to create a destination disk image which is growable and monolithic

2) use the standard approach to convert the monolithic file into a .qcow2:

qemu-img convert -f vmdk -O qcow2 "temp.vmdk" "destination.qcow2"

At this point, you have a disk image that will be accessible by software looking for a qcow2 format file.  After verifying that you can access it, feel free to delete the temporary file temp.vmdk.