Migrating a VM from VirtualBox to QEMU can be a bit tricky if you don’t have large amounts of extra disk space. VirtualBox’s default disk format (VDI) is not supported by QEMU, so you have to first copy the VDI to a format that QEMU supports. If you have a large sparse VDI, however, it is not immediately clear how to clone the VDI to a format supported by QEMU without creating an image that takes up as much space as the VDI’s capacity. Using Virtual Box’s
clonemedium tool will create a target image as large as the original, and
modifymedium cannot shrink disk images, so another approach is needed.
One way to get a raw disk image that QEMU supports from a large, sparse VDI is as follows:
Shrink the filesystem on the VDI to minimize unused disk space. (The best way to do this depends on the filesystem type. Booting a GParted Live CD is one approach that can handle most filesystems.)
Create a target raw disk image for QEMU:
qemu-img create target.img 285G
Set the size to whatever the size of the shrunken filesystem is or larger.
Clone the VDI to the new image, using Virtual Box’s tools:
vboxmanage clonemedium source.vdi target.img --existing
VirtualBox will clone the VDI disk to fill the target image. Any data beyond the size of the target image will not be copied, but that is okay.
Attach the new disk image to QEMU and boot. If your disk was formatted using a GPT, your operating system may need to repair the disk, as the secondary GPT at the end of the disk will not have been copied. Once the OS re-creates the secondary GPT, the new disk would work fine, and you should be able to delete the original VDI.