Migrate a VirtualBox VM to libvirt qemu-kvm

Find the original VM's disk image location

Find the disk image on the file system, you can export the path so you can use it in scripts.

$ export 'VBOX_DISK_IMAGE=/path/to/image.vdi'

Remove the harddrive from the VM

You will need an empty vdi for this

Use the VBoxManage tool.

$ VBoxManage storageattach "<vm-name>" --storagectl "SATA" --port 1 --medium /path/to/empty.vdi

Convert to raw disk image

Convert the vdi image to a raw image.

$ VBoxManage clonehd --format RAW $VBOX_DISK_IMAGE output.raw

Convert the new image to qcow2

Use qemu-img to convert it to qcow2 for best performance.

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

Copy the image to libvirt's storage dir (as root)

$ sudo cp output.qcow2 /path/to/libvirt/storage/vm-name.qcow2

Create a new vm with this new image attached

Create a new vm that has this disk image attached and boot it, you are done now!

{{ message }}

{{ 'Comments are closed.' | trans }}