mercredi 27 mai 2009

Transformer une image qemu en une image VirtualBox

Source : liquidat.wordpress.com

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


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: 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
[NDR : ! vditool is Obsolete ! Use : (see Update#1)

New method :]

$ VBoxManage convertdd kde4daily.bin kde4daily.vdi

$ VBoxManage modifyvdi kde4daily.vdi compact

[NDR : Old Method : ]

$ ./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.

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

Aucun commentaire:

Enregistrer un commentaire