Howto: Transform a qemu image to a VirtualBox image [2. Update]

Transform a qemu image to a VirtualBox image
Virtual Machines are an easy way to provide new applications or even entire operating systems without the need to install or alter anything in an existing system. However, often they are provided as a qemu image while VirtualBox is much more userfriendly.

A good example for an important qemu image is KDE’s “KDE 4 daily buildsvirtual machine. I wanted to use it, but in contrast to qemu, VirtualBox comes along with a well designed GUI and is simply much more userfriendly (and of course also exists in a free version).

To use the qemu image in VirtualBox, first of all qemu must be installed on the computer. In Fedora this can be done by yum install qemu, for example. Also, later on a tool called “vditool” is needed. This can be downloaded at VirtualBox’ homepage: save the following link by right click to some place on your hard disk: www.virtualbox.org/download/testcase/vditool. VirtualBox should be installed already as well.

Afterwards, the image can be converted via qemu to a raw format. This raw format can be transformed to the VirtualBox compatible “vdi” type. Last but not least the image can be shrinked down a bit to only take the space it really needs:


$ qemu-img convert kde4daily-0_0_1_r734472-qcow.img kde4daily.bin

$ ./vditool DD kde4daily.vdi kde4daily.bin
vditool    Copyright (c) 2004-2005 InnoTek Systemberatung GmbH.

Converting VDI: from DD image file="kde4daily.bin" to file="kde4daily.vdi"...
Creating fixed image with size 3758096384 Bytes...
The operation completed successfully!
Writing data...
The operation completed successfully!

$ ./vditool SHRINK kde4daily.vdi
vditool    Copyright (c) 2004-2005 InnoTek Systemberatung GmbH.
Shrinking VDI image file="kde4daily.vdi"...
progress: 0%Log created: 2007-11-23T20:56:29.959543000Z
[...]
……….10%……….20%……….30%……….40%……….50%……….60%……….70%……….80%……….90%……….100%Dumping VDI image "kde4daily.vdi" mode=r/w fOpen=0 File=00000004
[...]
The operation completed successfully!

Of course the file names must be altered according to particular needs.

Afterwards, move the image to an appropriate place, create a new virtual machine instance with VirtualBox and choose the new vdi image as the hard disk of the new vm instance. Now the virtual machine can be configured and started just like any other one.

In case of the example above there was some attention still necessary to bring up the network: it wasn’t activated by default somehow, but a simple


$ sudo su
Password:
$ ifconfig eth1 up
$ dhclient eth1

fixed the problem.

Update
Naveed Hasan mentioned that vditool is obsolete and that VBoxManage can be used for it. VBoxManage is part of the VirtualBox standard installation and offers quite a lot of options - among others the possibility to convert one format to another: VBoxManage convertdd kde4daily.bin kde4daily.vdi and VBoxManage modifyvdi kde4daily.vdi compact.

2. Update
The image contains a hard-coded MAC-address for the internet connection. Simply remove the MAC address from the /etc/iftab file, and the network problem mentioned above should be gone. Thanks to Martin for the tip.

Posted in Fedora, KDE, Linux, Shell, Technology.

34 Responses to “Howto: Transform a qemu image to a VirtualBox image [2. Update]”

  1. SSJ Says:

    Thanks Roland - I’ll add this to the comments section in the Dot article! Does it run better in VB, BTW?

  2. Naveed Hasan Says:

    vditool has been superseded by VBoxManage (which is part of the VirtualBox installation.) Run VBoxManage without any arguments to see all of the options.

    3. VBoxManage convertdd kde4daily.bin kde4daily.vdi
    12. VBoxManage modifyvdi kde4daily.vdi compact

    The above commands are the new way to do what vditool did.

  3. liquidat Says:

    Naveed, thanks for the comment, I’ve added a comment to the howto.
    SSJ: I didn’t check how it run in qemu and I never really used qemu since VirtualBox has a much more appealing GUI (and stuff like guest additions, etc.). So I cannot compare it, sorry.

  4. attendant Says:

    this little script should help the process
    the rel2abs (which i found on google) is needed because VBoxManage modifyvdi won’t work with a relative path (or at least it didn’t for me… ;)
    btw, you’ll need a lot of space to run it, you may want to modify it to delete the qemu image before creating the virtual box image.

    #!/bin/sh

    rel2abs()
    {
    dir=$(dirname — “$1″ && echo .) || return
    dir=$(cd -P — “${dir%??}” && pwd -P && echo .) || return
    dir=${dir%??}
    file=$(basename — “$1″ && echo .) || return
    file=${file%??}
    case $dir in
    /) echo “/$file”;;
    /*) echo “$dir/$file”;;
    *) return 1;;
    esac
    return 0
    }

    QEMU_VM=$(rel2abs ${1})
    VBOX_VM=$(rel2abs ${2})
    RAW_VM=${VBOX_VM}.raw

    qemu-img convert ${QEMU_VM} ${RAW_VM}
    VBoxManage convertdd ${RAW_VM} ${VBOX_VM}
    VBoxManage modifyvdi ${VBOX_VM} compact
    rm ${RAW_VM}

  5. hgdomainnames » Blog Archive » Howto: Transform a qemu image to a VirtualBox image Says:

    [...] here for [...]

  6. weintor Says:

    Thanks for the infomation. A doubt that i have is if converting to virtualbox you have the same option to update your kde4daily or not.

  7. SSJ Says:

    weintor: I see no reason why it shouldn’t work - it’s essentially the same VM image with all the updating scripts intact :)

  8. Jo Says:

    yes, you have the same option to update your kde4daily

  9. liquidat Says:

    I tested the converted image, and it runs without any problems. As I mentioned you should make sure that network runs smoothly, but that is just a question of a few command lines.

  10. chiabre Says:

    Some error in converting 4 me….

    ________________________________________________
    $ qemu-img convert kde4daily-0_0_1_r734472-qcow.img kde4daily.bin
    $ VBoxManage convertdd kde4daily.bin kde4daily.vdi

    VirtualBox Command Line Management Interface Version 1.5.2
    (C) 2005-2007 innotek GmbH
    All rights reserved.

    Converting VDI: from DD image file=”kde4daily.bin” to file=”kde4daily.vdi”…
    Creating fixed image with size 3758096384Bytes (3584MB)…

    $ VBoxManage modifyvdi kde4daily.vdi compact

    VirtualBox Command Line Management Interface Version 1.5.2
    (C) 2005-2007 innotek GmbH
    All rights reserved.

    [!] FAILED calling virtualBox->FindVirtualDiskImage(filepath, vdi.asOutParam()) at line 2291!
    [!] Primary RC = 0×80070057
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = 0×80070057
    [!] Text = Could not find a registered VDI hard disk with the file path ‘~/.VirtualBox/VDI/kde4daily.vdi’
    [!] Component = VirtualBox, Interface: IVirtualBox, {76b25f3c-15d4-4785-a9d3-adc6a462beec}

    ____________________

    anyway not compact img works well…

  11. Frederico Says:

    @chiabre:
    As noted above try giving the full/absolute path to the .vdi to VBoxManage

  12. chiabre Says:

    :D
    it works
    thx

    sorry 4 my nooobishims

  13. TopperH Says:

    As a gentoo user I’m not willing to install qemu, that requires gcc-3, only to have the qemu-img tool…

    Would be great if someone could make a torrent of the vdi image or at least of the bin image.

    I promise I will seed it :-)

  14. Let_Me_Be Says:

    It would be really nice to have the vdi. I will seed too if anybody decides to release it.

  15. liquidat Says:

    Let_Me_Be, the best is to ask SSJ directly. Maybe he can provide a vdi file. My problem is that I could upload the vdi file, but I don’t know where to.

  16. szotsaki Says:

    It’s interesting, but after I converted to and packed the .vdi image then loaded to VirtualBox I get the following error message at boot time:

    FATAL: No bootable medium found! Sytem halted.

  17. Andrei Says:

    All went fine, but when trying to run either vditool or VBoxManage the following message appears:

    ./VBoxManage: error while loading shared libraries: VBoxDDU.so: cannot open shared object file: No such file or directory

    I have VirtualBox installed and used it before.
    Can you help? Thanks

  18. mattme Says:

    @Andrei:
    Try to use the command “vboxmanage” (everything in small letters) instead. This worked on my Kubuntu Gutsy System.

    I get the “FATAL: No bootable medium found! Sytem halted.” error in VirtualBox, too.

  19. Andrei Says:

    @mattme: thanks a lot. now it works

  20. liquidat Says:

    About the “No bootable medium found” error: it sounds like the image transformation went wrong, or the image itself was corrupted. You could start a live cd inside the virtual machine to check if there are any data at all.

  21. andrei chitic | ro » Blog Archive » KDE4 daily build Says:

    [...] se numeste KDE4Daily Virtual Image. Imaginea e pentru Qemu dar pe blogul de Linux /home/liquidat gasim o modalitate de a o converti pentru a o putea folosi cu [...]

  22. szotsaki Says:

    I made the [i]VBoxManage convertdd[/i] transformation both with a from-torrent and a direct downloaded .bz2->img file.

    I can’t use qemu, becuse it requires gcc3 and on Gentoo I wouldn’t like to install it…

    Why can’t KDE developer simply share a .vdi image? I really don’t understand.

  23. Martin Steigerwald Says:

    You can work-around the network issue by removing the hard wired MAC address from the file /etc/iftab ;-). The virtualbox interface gets eth1 otherwise as it has an other MAC address than the qemu one.

  24. liquidat Says:

    Martin, thx for the tip, that was exactly what was missing. :)

  25. Thomson Says:

    I need the pasword for root (sudo), because I must edit iftab. How is the password for root?

  26. Netjack Says:

    @Thomson
    if you use sudo the passwd is the same of the user, in this case kde4daily

    bye

    @liquidat
    Great blog!

  27. Thomson Says:

    Thanks for the password, but I can’t edit iftab. When I write ” sudo kwrite” in the Konsole, then I become an error message. And when i open kwrite with root rights under alt+ f2, than i can also don’t save the edit file.
    Who can I edit this file?

    Sorry for my very bad english

  28. liquidat Says:

    Thomson, try to use “sudo su”. This will open a normal shell with root rights. Start kwrite from there. If kwrite does not work, use a command line editor like vim:
    sudo su, vim /etc/iftab, navigate with the arrows to the line with the MAC address, double press the character “d” (the line will disappear), press the character “:”, press “wq”, and hit enter. Than you should be ready.

    In general: a sentence like “then I become an error message” is useless. If you get an error message, post it so that others can get an idea of what is going wrong. Besides, if the problem is not fixed with the above mentioned method, please ask in an appropriate forum. A blog is hardly the place to discuss problems.

  29. From Parallels Desktop to VirtualBox | info.michael-simons.eu Says:

    [...] I needed to convert the Parallels image from a raw disk format to innoteks vdi format, following the steps explained here. [...]

  30. Kde4 in Qemu, VirtualBox o VMware. Dischi vdi, qcow e vmdk « Antonio Doldo Linux Blog Says:

    [...] VMware, cercavo un modo veloce per rendermi conto di cosa si sta parlando e così sono approdato su questo bel post [...]

  31. Kde4 in Qemu, VirtualBox o VMware. Dischi vdi, qcow e vmdk at Antonio Doldo Linux Blog Says:

    [...] VMware, cercavo un modo veloce per rendermi conto di cosa si sta parlando e così sono approdato su questo bel post [...]

  32. renier Says:

    Thanks. This is what I was looking for to give VirtualBox a try.

  33. Felipe Astroza Says:

    http://www.virtualbox.org/download/testcase/vditool doesn’t work with a VirtualBox 64 bits distribution, because vditool needs VBoxDD.so and VBoxRT.so for 32 bits.

    VirtualBox incorporates vditool into VBoxManage:

    VBoxManage convertdd kde4daily.bin kde4daily.vdi

  34. Hans Mueller Says:

    How to convert WinXP.vmdk to WinXP.dvi

    The usual way via “qemu-img convert” did not work on my installation
    (Ubuntu 7.10 Gutsy; qemu 0.9); it just produced a not bootable image.
    I successfully used Partition Magic instead:

    1. In the VirtualBox main window, choose File -> Virtual Disk Manager -> New
    to create a Dynamically expanding image (say, WinXP.vdi) that
    is nominally at least as large as the disk you want to convert.

    2. For a VBox virtual machine which has the old existing VMDK (WinXP.vmdk)
    as the boot hard disk, attach the new image (WinXP) as a slave hard disk.

    3. Boot the system and use Partition Magic to copy the old disk to the new one
    (PM may complain that the new partition is not bootable - don’t worry.)
    PM will require a reboot and may fail after copying - still the copy is fine.

    4. Shut down the virtual machine, detach the WinXP.vmdk,
    attach the WinXP.dvi as the new boot disk, then try booting the new image.

    5. Optionally, to compact the new disk, follow the instructions
    in http://murga-linux.com/puppy/viewtopic.php?t=21797 - in a nutshell:
    On the WinXP command prompt, execute “dirms c”, then “sdelete -c c:”
    then shut down the virtual machine
    and execute “VBoxManage modifydvi WinXP.vdi compact” on the host.

Leave a Reply