I had an installation of Lunar Linux, that I wanted to move from VirtualBox to KVM, and therefore had to convert the imagefile. I searched high and low, but found no up to date instructions on how to do this. | In the old days there seem to have existed a tool called "vditool", but now "VBoxManager" will do the trick of converting a VirtualBox .vdi image into raw format. Here are the steps that I took:

  • Find the UUID of the VirtualBox disk image:

    oblivion@mastermind ~/.VirtualBox/VDI $ VBoxManage list hdds 
    VirtualBox Command Line Management Interface Version 2.1.2
    (C) 2005-2009 Sun Microsystems, Inc.
    All rights reserved.
    UUID:         e4e316cb-ad9f-46ae-b15c-164b893371cb
    Format:       VDI
    Location:     /home/oblivion/.VirtualBox/VDI/lunar.vdi
    Accessible:   yes
    Usage:        Lunar (UUID: d249a972-f112-4cbc-91ce-389ce75e4fac)

  • Convert the .vdi file to raw format, using the UUID just found. Using VBoxManage's clonehd function the .vdi file is cloned into a raw image, in this case called lunar.img:

    oblivion@mastermind ~/.VirtualBox/VDI $ VBoxManage clonehd e4e316cb-ad9f-46ae-b15c-164b893371cb lunar.img -format RAW
    VirtualBox Command Line Management Interface Version 2.1.2
    (C) 2005-2009 Sun Microsystems, Inc. All rights reserved.
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Clone hard disk created in format 'RAW'. UUID: 5106c566-7188-4513-a416-73eb7a4e44a9

  • On my Gentoo Linux system, the converted image was saved in ~/.VirtualBox/HardDisks.

  • Convert the image to QEMU qcow2 format using qemu-img:

    oblivion@mastermind ~/.VirtualBox/HardDisks $ qemu-img convert ~/.VirtualBox/HardDisks/lunar.img -O qcow2 lunar.qcow2

From the utter silence of this command springs lunar.qcow2, ready for KVM!

Generated on 2018-05-03 01:14:21.912174