My Linux Journey – Backing up files from VirtualBox VM

I recently bought a new (used) PC. After a few months, I decided to install a new SSD and put Linux inside it. So far so good, but I faced an issue – I wanted to use my old Arch VM that I created back when I was still on Windows, or at least the files inside it.

Method 1: Converting VDI to QCOW2

The most logical way that came across my mind was converting the VirtualBox VDI file to QCOW2. This way, I can reuse the whole VM but virtualize it using a different hypervisor. So let’s do just that:

/storage# qemu-img convert -f vdi -O qcow2 "/storage/VirtualBoxVMs/Arch Linux/Arch Linux.vdi" "/storage/qemu-pool/archlinux.qcow2" # convert vdi to qcow2

Then, create a new virtual machine using Virtual Machine Manager:

Booting the VM and….. it’s stuck.

Unfortunately it does not boot and I do not possess enough knowledge to troubleshoot this issue 🙁 So let’s find an alternative.

Method 2: Converting VDI to IMG to QCOW2

This method is same as the previous one but with another layer of indirection. This step requires VirtualBox as I need to use the vboxmanage utility:

/storage# apt install virtualbox virtualbox-ext-pack
/storage# vboxmanage convertdd "/storage/VirtualBoxVMs/Arch Linux/Arch Linux.vdi" "/storage/qemu-pool/archlinux.img"
/storage# qemu-img convert -f raw -O qcow2 "/storage/qemu-pool/archlinux.img" "/storage/qemu-pool/archlinux.qcow2"

Then, create a new Virtual Machine using the qcow2 image that was produced.

This method also failed, maybe I did something wrong? Because the output file is significantly smaller than the input file. Perhaps somewhere along the way, the conversion screwed up causing the img file to be invalid? Maybe I used the wrong command? So I kind of gave up and opened up VirtualBox again.

Method 3: Giving up – Using VirtualBox and copying the files using SCP

After adding the old VM to VirtualBox and trying to start it, I encountered some errors.

Luckily, vbox VMs settings are defined using XML. So open Arch Linux.vbox with a text editor, CTRL+F the important keyword and just remove the line. The issue was the audio adapter is not supported for whatever reason, and the host-only network adapter that I attached to the VM does not exist on this machine. So just remove both and then, start the machine again.

Tada! Now it boots properly. Now I only need to copy the most important files to my host OS using SCP:

archlinux$ scp -R ~/development ad@<host OS ip>:/home/ad/dev_backup
# or you can also do it from the host OS
ubuntu$ scp -R ad@<guest OS ip>:/home/ad/development ~/dev_backup

This way, I either had to reinstall Arch inside of QEMU/KVM or use VirtualBox. I preferred neither even though I have installed Arch plenty of times before and VirtualBox is easier to use (sometimes).

Leave a Reply

Your email address will not be published. Required fields are marked *

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