Like many other IT professionals, I recently found myself re-evaluating my virtualisation options, especially my choice of hypervisor. Since I’m a habitual Linux user, the rigidity and platform restrictions of ESXi got to me too much, so I’ve started making the move from ESXi 5.1 to Linux KVM running on Ubuntu 12.04.3. However, this requires getting my existing machines off my ESXi install onto my KVM hypervisor. Although there is a vmware2libvirt python script in the virt-goodies package, I never got good results from it, so I decided to build them manually.
First, from the vSphere client, export your machine as an OVF “folder of files”. This will produce an ovf file and a vmdk virtual disk. Copy the disk to your hypervisor however appropriate. You’re going to want to convert the vmdk file into something a little more qemu-friendly, so we’re going to use qcow2. qemu provides a handy command called qemu-img that can convert disk images between different formats. The syntax looks like:
qemu-img convert -p -f vmdk -O qcow2 /path/to/vmdk-disk /path/to/new-disk
Unfortunately, running that on Ubuntu 12.04.3 results in an invalid argument error. This is actually because Ubuntu ships with an old version of qemu, which doesn’t support vmdk’s properly. So, jump on qemu’s website and grab the newest version, right? (currently 1.6.1) Wrong. Running the same command on qemu 1.6.1 gets you an error stating that this version of qemu does not support vmdk version 3. That’s because you need qemu 1.5.3.
So, from the top, the process is:
- Export to OVF and copy the resulting vmdk to the hypervisor
get the right version of qemu for vmdk conversions:
cd /tmp && wget http://wiki.qemu-project.org/download/qemu-1.5.3.tar.bz2
- Extract it:
tar xvjf qemu-1.5.3.tar.bz2 && cd qemu-1.5.3
- Configure and build
./configure && make qemu-img
- Now you’re ready to convert:
./qemu-img convert -p -f vmdk -O qcow2 /path/to/vmdk-disk /path/to/new-disk
Now, simply use virt-manager (or your favourite VM management tool) to create a new machine, using the newly converted qcow2 disk as the machine’s disk. You can use the .ovf file from the original export to check out all the hardware details of the VMware VM, and change the new VM settings to match. Now, with a new qcow2 disk, you get all the benefits of online snapshotting and improved performance of the qcow2 format.