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 builds virtual 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: 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
$ ifconfig eth1 up
$ dhclient eth1

fixed the problem.

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.


38 thoughts on “Howto: Transform a qemu image to a VirtualBox image [2. Update]”

  1. 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.

  2. 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.

  3. 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.


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

    QEMU_VM=$(rel2abs ${1})
    VBOX_VM=$(rel2abs ${2})

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

  4. 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.

  5. weintor: I see no reason why it shouldn’t work – it’s essentially the same VM image with all the updating scripts intact πŸ™‚

  6. 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.

  7. 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 = 0x80070057
    [!] Full error info present: true , basic error info present: true
    [!] Result Code = 0x80070057
    [!] 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…

  8. 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 πŸ™‚

  9. 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.

  10. 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.

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

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

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

  12. @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.

  13. 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.

  14. 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.

  15. 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.

  16. 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

  17. 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.

  18. 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 – 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.

  19. the point with the “not bootable image” is:
    you must not convert the bz2 file to a raw .bin, but bunzip2 it first πŸ˜‰

  20. Hi, for those of you are tight on harddrive space – just use “qemu-img convert -f qcow -O vmdk ” to convert to a vmdk image – this can be used for VirtualBox, as well.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: