How to convert VirtualBox vdi to KVM qcow2

It is very easy to convert a VirtualBox .vdi disk images to KVM qcow2 file. You have to use the RAW file format as an intermediate.

1 – Make sure the VirtualBox machine is shutdown.

2 – Convert the vdi to a raw disk images. Note: vdi are compressed and raw images are not and so you will need to leave enough disk space for entire uncompressed disk.

VBoxManage clonehd --format RAW vm.vdi vm.img

3 – Then on your KVM host:

qemu-img convert -f raw vm.img -O qcow2 vm.qcow2

Hope this is helpful.

9 thoughts on “How to convert VirtualBox vdi to KVM qcow2

    1. qemu-img understands only ‘plain’ VDI images without snapshots. So in my case I had to create ‘plain VDI’ image first:

      $ cd ~/VirtualBox VMs/Linuxes/sles11x64/Snapshots
      $ ls -lt (pick the latest)
      $ VBoxManage clonehd –format VDI “{d30c5f02-1d3c-45a0-a631-254b865b0dfd}.vdi” bsles11x64_current.vdi

  1. Curious, when I convert the vdi to qcow2 image, I started with a 28g .vdi image and ended with a 3.5g .qcow2 image. When I start the qcow2 image my partition sizes are the same as on the vdi image. Is there a way to convert the images and keep the same image size?

    1. Qcow2 format is an automatic compressed image file. then it’s dynamic, not fixed file size. Only fixed partition size with file compression data.
      see man qemu.

  2. Don’t I need to remove the MAC address from the network config files?
    What about installing cloud-init so the qcow2 can be used on public clouds?

Leave a Reply