Convert Virtualbox vdi to KVM qcow

I have been asked several times how to convert an existing VirtualBox machine / image to KVM. The process is quite easy and involves simply converting your virtual hard drive (VirtualBox uses “vdi”) to a format compatible with KVM (qcow). You then use the qcow image with KVM, either from the command line of with virt-manager.

Although the process is quite easy, it does require sufficient hard drive space as the VirtualBox .vdi is first converted to a raw disk image.

Side track – Both vdi and qcow images are compressed, so a a 10 Gb .vid or .qcow will take less space on your hard drive. Conversion, however, requires you to first convert the .vdi to a raw image, which will require the full 10 Gb, so plan accordingly.

Assume your VirtualBox image is called “ubuntu.vdi”

Step 1. Convert the VB disk vdi image to a raw image format.

VBoxManage clonehd --format RAW ubuntu.vdi ubuntu.img

Note: The ubunut.img is a raw disk image, it will be quite large (as many GB as your virtual drive is, see above).

Step 2 : convert the raw image to a qcow

qemu-img convert -f raw ubuntu.img -O qcow2 ubuntu.qcow

That is all there is to it, the ubuntu.qcow can be used with KVM.

Test your new image (ubuntu.qcow) with:

kvm -m 512 -usbdevice tablet -hda ubuntu.qcow

If it is working you may delete the raw image (ubuntu.img) and archive or delete the ubuntu.vdi .

Welcome to KVM :)

This entry was posted in Linux. Bookmark the permalink.

24 Responses to Convert Virtualbox vdi to KVM qcow

  1. jimcooncat says:

    Thanks so much for this, I will be moving to KVM this week!

  2. m says:

    Hi.

    KVM sounds interesting and certainly seems like the future in virtualization on nix.

    The one feature virtualbox offers me that I could not live without is the headless mode with interaction with the VM over the remote desktop protocol. Can kvm/qemu do anything like that? I can never seem to find any “features” page.

  3. bodhi.zazen says:

    KVM has a built in VNC server and you may run guests “headless”. From there you can VNC into the guest with any VNC client.

    The built in VNC server does not have a ton of features, so you may wish to install a more full featured VNC server.

    In terms of “Seamless Integration” , this is actually a feature of Windows and the so called rdp (remote desktop protocol). You will have to manually configure it, but it should work (it is not difficult).

    This Ubuntu Wiki page will show you how to do it, follow the instructions for “qemu”.

  4. Pingback: linkfeedr » Blog Archive » Bodhi.Zazen: Convert Virtualbox vdi to KVM qcow - RSS Indexer (beta)

  5. Yann says:

    Alright, and where can we get vditool? :/

  6. bodhi.zazen says:

    vidtool is included in vitrualbox. If needed you may install either the OSE from the Ubuntu repositories or the PUEL edition from the Sun site.

  7. Yann says:

    Hello bodhi, could you please double check this, or specify which package contains it, and where it gets installed? I don’t think it is true :/

  8. bodhi.zazen says:

    hmm … It appears they changed the syntax and I can no longer find vditool for download :(

    use VBoxManage clonehd

    I updated my tutorial , lol

  9. Yann says:

    Does it work? If I create a vdi disk with the following command line:

    VBoxManage createhd -filename ubuntu.vdi -size 200M

    And then try to convert it:

    VBoxManage clonehd -format RAW ubuntu.vdi ubuntu.img

    I get the following error:

    Error: failed to clone hard disk. Error message: Could not create the clone hard disk ‘/home/yann/.VirtualBox/HardDisks/ubuntu.img’ (VERR_INVALID_PARAMETER)

    (placing myself in /home/yann/.Virtualbox/HardDisks)

    Any idea?

  10. bodhi.zazen says:

    I am able to convert using the PUEL version. In fact, I downloaded to test this for you yesterday (I made a disk, converted it using the commands I updated, and used the disk with KVM).

    (Host Ubuntu 9.04 x86_64 ; Virtualbox PUEL 2.2.2)

    A google search shows that this error you now have is common with VirtualBox, but it was “fixed in SVN”.

    http://www.virtualbox.org/ticket/3012

    I suggest you update your version of VirtualBox and if the problem persists filing a bug report with VirtualBox.

    #VBoxManage clonehd –format RAW ubuntu.vdi ubuntu.img

    VirtualBox Command Line Management Interface Version 2.2.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: 6d73f00d-5165-4717-ae32-55b1992d7f7e

    #ls
    ubuntu.img ubuntu.vdi

    #qemu-img convert -f raw ubuntu.img -O qcow2 ubuntu.qcow

    #ls
    ubuntu.img ubuntu.qcow ubuntu.vdi

  11. bodhi.zazen says:

    And , just for completeness …

    I installed Virtualbox ( PUEL 2.2.2 – x86_64 ) on Fedora 10 ->
    I then installed Ubuntu 9.04 (guest) with an encrypted / (root)

    I then used the commands in this blog to convert the ubuntu.vdi -> ubuntu.img (raw) -> ubuntu.qcow

    The resulting ubuntu.qcow booted in KVM with no problems, encryption was preserved.

    HTH :twisted:

  12. Ryan Grieve says:

    Depending on your version of VirtualBox you may have to put the “-format RAW” AFTER the filenames.

    VBoxManage clonehd |
    [--format VDI|VMDK|VHD|RAW|]
    [--variant Standard,Fixed,Split2G,Stream,ESX]
    [--type normal|writethrough|immutable]
    [--remember]

    VBoxManage clonehd “ubuntu.vdi” “ubuntu.img” -format RAW

    Hope this help!

    Ryan

  13. Pingback: 将virtualbox的vdi镜像文件转换成kvm的qcow静像文件 | Linux|系统管理|WEB开发

  14. Guest says:

    How would it be the same process but backwards? Would it work just like that or it would require extra steps?

  15. bodhi.zazen says:

    In theory, it should work the same in reverse.

    In Practice, sometimes my conversions fail, and when they do sometime I can debug and sometimes not.

  16. Pablo Alonso says:

    Hi I have tested the procedure and it works like a charm!

    but… I have a little problem after the conversion…
    In this case I converted a Windows XP vbox machine into KVM qcow and then I’m not able to startup the machine because of the common bsod caused by the HAL problem…

    anyone knows how to overcome this issue without having to repair the windows installation???

    thanks in advance!

  17. bodhi.zazen says:

    Pablo Alonso: Aye, the “problem” is that when you convert form VMWare to KVM, as far as Windows is concerned, the “hardware” changed.

    I do not know of an easy fix :(

  18. Anonymous says:

    VBoxManage clonehd -format RAW ubuntu.vdi ubuntu.img

    I get the following error:

    Error: failed to clone hard disk. Error message: Could not create the clone hard disk ‘/home/yann/.VirtualBox/HardDisks/ubuntu.img’ (VERR_INVALID_PARAMETER)

    Try:
    VBoxManage clonehd –format RAW ubuntu.vdi ubuntu.img

  19. bodhi.zazen says:

    @Anonymous:

    Try two – -

    Wordpress renders two – - as a long –

    I updated the syntax of the post , hope that helps.

  20. Pingback: Converting VirtualBox VDI files to raw disk images | Needs More Pop

  21. Conceit says:

    As far as I’ve read, KVM can read VMDK files (Vmware). Virtualbox exports VMDK either via vboxmanage or via “Export appliance” in the file menu. Export works fine, but I did not try using the VMDK in KVM, yet.

  22. Jim says:

    I was able to make this conversion in one step with this command:

    qemu-img convert -f vdi oldImage.vdi -O qcow2 newImage.qcow

  23. Pingback: VirtualBox -> KVM « zeusville

  24. Pingback: HowTo:kvm | S.C.Y 工作記錄

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>