Home FAQ How To Migrate Virtualbox VMs Into KVM VMs In Linux
How To Migrate Virtualbox VMs Into KVM VMs In Linux

How To Migrate Virtualbox VMs Into KVM VMs In Linux

By sk
2812 Views

Have you decided to switch from Oracle VirtualBox to Kernel-based Virtual Machine? Great! This guide explains how to migrate Virtualbox VMs into KVM VMs in Linux. You might have running some important guest machines on VirtualBox. Instead of creating new KVM guests with same configuration, you can easily migrate the existing Virtualbox machines to KVM as described here.

Migrate Virtualbox VMs Into KVM VMs In Linux

First, power off all VMs hosted with KVM and VirtualBox.

The default disk image format of a Virtualbox VM is VDI.

We can find the list of virtualbox disk images and their location using command:

$ vboxmanage list hdds

Or,

$ VBoxManage list hdds

Sample output:

UUID:           ecfb6d5c-aa10-4ffc-b40c-b871f0404da8
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /home/sk/VirtualBox VMs/CentOS 8 Server/CentOS 8 Server.vdi
Storage format: VDI
Capacity:       20480 MBytes
Encryption:     disabled

UUID:           34a5709f-188c-4040-98f9-6093628c3d88
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /home/sk/VirtualBox VMs/Ubuntu 20.04 Server/Ubuntu 20.04 Server.vdi
Storage format: VDI
Capacity:       20480 MBytes
Encryption:     disabled

List virtualbox disk images details in Linux

As you can see, I have two virtualbox VMs.

Now I am going to convert CentOS 8 machines' disk image to a raw disk format using "vboxmanage" command:

$ vboxmanage clonehd --format RAW /home/sk/VirtualBox\ VMs/CentOS\ 8\ Server/CentOS\ 8\ Server.vdi CentOS_8_Server.img

Or,

$ VBoxManage clonehd --format RAW /home/sk/VirtualBox\ VMs/CentOS\ 8\ Server/CentOS\ 8\ Server.vdi CentOS_8_Server.img

Sample output:

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'RAW'. UUID: afff3db8-b460-4f68-9c02-0f5d0d766c8e

The RAW image is too big to use. In my case, RAW image is ten times bigger than Qcow2 image.

$ du -h CentOS_8_Server.img 
21G CentOS_8_Server.img

So let us convert the RAW image format into KVM disk format i.e. compressed qcow2 using qemu-img command:

$ qemu-img convert -f raw CentOS_8_Server.img -O qcow2 CentOS_8_Server.qcow2

migrate virtualbox VMs into KVM VMs

Done! We have converted Virtualbox disk image format VDI into KVM image format qcow2.

Check the size of the Qcow2 image:

$ du -h CentOS_8_Server.qcow2 
2.1G CentOS_8_Server.qcow2

See? Qcow2 is much smaller than RAW image.

You can now create a new KVM instance by importing the virtual disk image file from command line or using any graphical KVM management applications like Virt-manager or Cockpit web console. Refer the following guide for more details:

Troubleshooting

Sometimes you might have deleted the virtual disk without properly releasing it from Virtualbox media manager. When you try to create new RAM image from the same VDI file, you will get an error something like - "hard disk with UUID already exists". To fix this issue, you must release the virtual disk from the Virtualbox and try again to convert the image. Refer the following guide to know how to do this:

Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

5 comments

Jalal July 10, 2020 - 11:13 am

Hi,
Thanks a lot
Very useful article

Reply
J. Leik July 10, 2020 - 5:53 pm

I’ve already been able to get this far. I’ve also been able to import the qcow2 into Proxmox VE (KVM) without issues IF the VirtualBox VM was created using BIOS instead of UEFI.

Would you please cover any extra steps for a UEFI VM going into KVM, even if it’s not Proxmox?

Thanks

Reply
sk July 10, 2020 - 9:15 pm

I added this ot my to-do list. I will try it in my test machine and post a guide.

Reply
KpacnajaShapotshka July 12, 2020 - 2:27 pm

So, how big is the RAW image format in comparison to VDI and qcow2 usually? Does it have other disadvantages?

Reply
sk July 12, 2020 - 4:21 pm

RAW image is ten times bigger than Qcow2 image. Except the size, it doesn’t have any disadvantages as far as I know.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More