Converting VMWare .vmdk To VirtualBox .vdi Using Qemu+ and VBoxManage

From ITCwiki
Revision as of 19:47, 16 November 2010 by ABorgert (talk | contribs) (Created page with 'If you want to switch to VirtualBox and have a Vmware Virtual Machine you want to use? You can convert a Vmware .vmdk file into a VirtualBox .vdi file that you can use on Virtual…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

If you want to switch to VirtualBox and have a Vmware Virtual Machine you want to use? You can convert a Vmware .vmdk file into a VirtualBox .vdi file that you can use on VirtualBox.

First, download qemu, open a Console and execute:

sudo apt-get install qemu

Next, open a console and go to your .vmdk virtual disc image folder and type this:

qemu-img convert "harddrive-name".vmdk -O raw-file.bin

Change "harddrive-name" with the name of your .vmdk file and raw-file with the name of the new converted file you want to create. This takes a few minutes, After the conversion is completed. A raw hard disk image has been created.

To convert a raw disk image to a VirtualBox Disk Image (VDI) file use this command.

VBoxManage convertfromraw

The syntax is as follows: sudo VBoxManage clonehd /home/edwardss/.VirtualBox/HardDisks/XPHardDisk1.vdi /home/edwardss/.VirtualBox


VBoxManage convertfromraw <filename> <outputfile> [--format VDI|VMDK|VHD] [--variant Standard,Fixed,Split2G,Stream,ESX] VBoxManage convertfromraw stdin <outputfile> <bytes> [--format VDI|VMDK|VHD] [--variant Standard,Fixed,Split2G,Stream,ESX]

where the parameters mean: format Select the disk image format to create. Default is VDI.

variant Allow to choose a file format variant for the output file. It is a comma-separated list of variant flags. Not all combinations are supported, and specifying inconsistent flags will result in an error message.

The second form forces VBoxManage to read the content for the disk image from standard input(useful for using that command in a pipe).

Run VirtualBox, use the (File Menu) Virtual Media Manager and 'Add' the newly cloned drive. This makes Virtual Box 'aware' of the drive. Then go though the normal creation steps and choose this as the drive to use for the virtual machine.

Downloading that vditool file is not the simplest thing in the world. If you try and open it with Firefox, for page with weird code in it will appear. To save this vditool file, right click on the link and choose to save the file. You can also tell a download manager to download this file for you. I suggest you the download manager: Aria. It is into Ubuntu repositoryes.

Now that we’ve got vditool, we need to make it executable. Right click on the file, open its propertyes and set the “Executable” permission option. In Gnome, go into the Permission tag and activate the “Let this program be executed” or something like that option (Remember, my Ubuntu is Italian, dunno what’s your exact translation).

At that point, we’ll need the console again, from the same dir where you’ve stored dvitool and the .bin raw file. Run this from console into the interested dir:

LD_LIBRARY_PATH=/opt/VirtualBox* ./vditool DD new-file.vdi old-file.bin

Where new-file.vdi is the file that will be outputted by vdi tool and must be the first to appear in the command. The second filename, old-file.bin, is the name of the raw disc image we converted the .vmdk image to. Naturally, change this invented names with real ones.

If you wish, remember that you can run vditool for other tasks too. Now we’ll run it to optimize the filesize of the .vdi image file, for example. For a list of all commands, you’ve just got to execute vditool without any other option.

Now we’re going to optimize the filesize of the newly converted .dvi file, let’s call it new-file.dvi and fromth console in the dir where you’ve got this file, run:

LD_LIBRARY_PATH=/opt/VirtualBox* ./vditool SHRINK new-file.vdi

Now we’re all setted up. Let’s run Virtual Box. At this point, you have to create a new Virtual Machine, set it up as you like and choose the new-file.dvi as disc image. If everything is okay, the machine will run, even if it will have to be settep up again a bit from inside the OS you’re using. For example, Windows has got a lot of problems in this part.

When I started my old disc image converte into a new compressed .vdi file inside a new Virtual Machine created with VBox, WinXP refused to start. I had to insert in the CD-Rom my original WinXP Cd to boot from cd and restore the windows installation! Windows, this way, reconfigured and installed each new virtual peripheral so that at reboot everything was okay and all my programs where left installed where they were.

Multiple vmdk files to vdi

A lot of people have been asking me about this. I sincerely didn’t have a clue on how to convert multiple vmdk vmware virtual disc images into a vdi VB virtual disc image. Luckily, Leonardo Cosmai just provided us with a solution in one of the comments on this post! You can see that post for yourself.

What you have to do is:

1) Downloading and installing VMWare Server for your platform, it is freeware but proprietay software, it is opensourced but you’ll need to subscribe for a license to use it. We’ll just use this to convert multiplevmdk images into a single one. You can find VMWare Server here.

2) Run a terminal, move in the dir where you store your multiple vmdk disc images and run:

vmware-vdiskmanager -r source_multiples.vmdk -t 2 single_file.vmdk

And that’s all! The multiple vmdk images will be converted into one single vmdk image file. At that point you’ll be able to normally use this guide to convert the newly obtained vmdk disc image into a single .vdi file!

I sincerely hope this helped a lot of people out there. It is almost impossible to find a way to use vditool in Google for now. No matter how much you google, I spent the all day trying to find something. Thanks to the guys from the VBox IRC Channel for helping me out, I wasn’t going to get out from this problem alone. And a lot of people in Ubuntu Forum where in my same conditions, so…. Enjoy your migration to Virtual Box!