Do you have some VirtualBox virtual machines that you would like to re-use on your KVM? Follow through this guide to learn how to use VirtualBox VMs on KVM.
Using VirtualBox VMs on KVM
The first thing to note is that both VirtualBox and KVM uses different disk formats. In order to re-use each format on different virtualization platform, you simply need to convert the disks to the format supported by each virtualization solution in question.
Well in that regard, in this guide, we are going to learn how to convert VirtualBox VDI disks to KVM QCOW2 disks.
We also assume that you are not running VirtualBox and KVM on the same host at the same time.
There are two ways in which we can convert the VirtualBox disk image into KVM qcow2.
- One method is to convert VDI to raw disk image (.img) and then convert the raw disk image to QCOW2.
- Another method is to directly convert VDI to QCOW2 using the qemu-img command.
- What if you have an OVA image? Convert OVA to QCOW2
Convert VirtualBox VDI to Raw Disk Image
Create a directory to store KVM images. (Not necessary).
mkdir ~/kvm-images
Next, convert a specific VirtualBox VM disk to raw image.
vboxmanage clonemedium --format RAW /path/to/vm-disk-name.vdi ~/kvm-images/vm-disk-name.img
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'RAW'. UUID: 261d0760-16bd-4cfd-a852-96861293f663
Replace the location of the VirtualBox VM and the name of the VM disk (/path/to/vm-disk-name.vdi
) accordingly.
You should now be having a RAW virtual machine disk image, located in the ~/kvm-images
for our case.
ls ~/kvm-images
vm-disk-name.img
Convert RAW Disk Image to KVM QCOW2
Now, copy the raw disk image to the host running KVM and convert it to the format supported by KVM, in this case, qcow2
.
The conversion can be done by executing the command below;
qemu-img convert -f raw vm-disk-name.img -O qcow2 vm-disk-name.qcow2
Convert VDI Directly to QCOW2
You can simply do the direct conversions of VDI to QCOW2 by executing the command below;
qemu-img convert -f vdi -O qcow2 vm-disk-name.vdi vm-disk-name.qcow2
Convert OVA to QCOW2
What if you have an OVA image exported from VirtualBox? In this case, then you also need to convert the OVA to QCOW2 image.
How to convert OVA to QCOW2?
- Extract disk image from OVA;
tar xf <name>.ova
You will either have VDI or VMDK depending on how the vm was created. See example files below
ls -1
ubuntu22.vmdk
ubuntu22.mf
ubuntu22.ova
ubuntu22.ovf
- In the above case, you need to convert VMDK image to QCOW2 format:
qemu-img convert -f vmdk -O qcow2 ubuntu22.vmdk ubuntu22.qcow2
Create New KVM Virtual Machine
You can now transfer the QCOW2 disk image to KVM host.
After that, you can create a new virtual machine by importing from the existing disk image.
Related Tutorials
How to Rename KVM Virtual Machine with virsh command