Recently, I had cause to convert a
VirtualBox virtual machine to one
compatible with QEMU and
KVM. A
quick search found me multiple methods for converting an image QEMU
-> VirtualBox but nothing helping me to go from VirtualBox ->
QEMU. After asking on the PLUG
mailing list, I got some help and managed to convert it without any
issues. In order to do it, you’ll need the vditool tool contained
in the virtualbox-ose package available from the Debian
repositories. Here’s how I got it working:
1. vditool COPYDD vbox-image.vdi raw-image.img
2. qemu-img convert -f raw raw-image.img -O qcow2 qemu-image.qcow
The first step copies the contents of the image (*.vdi is the
VirtualBox filesystem image extension) to a raw disk image. Be
advised: this file will be the full size of the virtual hard
drive. That means that, unlike *.vdi and *.qcow formats, if the
virtual disk has a maximum capacity of 8Gb, the raw image will be
8Gb in size regardless of how full the disk is. Once you have the
raw image, run the second step which uses the QEMU disk image
manipulation tool, qemu-img, to convert the raw image into the
QCOW2 format. The new QEMU image will be much smaller than the raw
image was and it can be made smaller by passing qemu-img the -c
option to enable transparent compression. However, seeing as how
this just uses zlib on
each cluster,
this might introduce more overhead to I/O than is desired and will
most likely degrade your overall VM performance.
UPDATE: 2010-05-14 It looks like vditool is no longer
available. It also seems like you could use the VBoxManage tool
included with VirtualBox to do the conversion but that option has
also been removed. The good news is that qemu-img now has support
for *.vdi files and can be used directly.