In this guide, we will be going through how to convert your VirtualBox VM which uses the “.vdi” extension to KVM which uses “.qcow2”. This is a guide for people who wish to switch over to KVM virtualisation without creating a whole new virtual machine all over again.
Step 1: Open CMD and locate your VirtualBox directory.
Firstly, open your command prompt and locate your VirtualBox directory using the cd command.
In my case, it’s in my D drive.
Step 2: Clone and convert your VDI file into a raw image file.
To clone and convert the file, run the following command in your command prompt.
VboxManage clonehd “absolutepath/filename_of_existing_vdi_file.vdi” “absolutepath/filename.img” -format raw
Here is an example of my command.
VBoxManage clonehd “D:\Oracle\VirtualBox VMs\Ubuntu\Ubuntu.vdi” “D:\Oracle\VirtualBox VMs\Ubuntu\Ubuntu.img” -format raw
You will be seeing a similar output as followed in your command prompt.
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100% Clone medium created in format ‘raw’. UUID: afdb24d-1a3c-4276-9251-bf2616f9b75e
You will be able to see an image file in the directory you had cloned into. The raw image file will be much larger in comparison with your “.vdi” file.
Step 3: Converting image file into the ".qcow2" file which is the file type for KVM.
This final step requires you to use the qemu-ing command, kindly refer to this link if you do not have the command installed, else skip this step if you already have it installed and proceed with the guide.
Run the following command for the “.img” to “.qcow2” conversion.
qemu-img convert -f raw -O qcow2 “absolutepath/filename_of_existing_img_file.img” “absolutepath/filename.qcow2”
After this, you will finally be able to find your “.qcow2” file in the directory you had chosen. You are now ready for KVM Virtualisation now.