Migrating from VirtualBox to VMware

As part of the Gnash buildbot farm, I run several virtual machines as build slaves. I started with VirtualBox because it is free software and I prefer to support free software, but it’s still a bit too fragile and it still lacks x86_64 guest support.

When I discovered that VMware Server is now available for free–well, free as in beer, anyway–I happily installed it and set up some new VMs on it. Best of all, it supports x86_64 guests! Of course, now I have the problem of migrating those VirtualBox guest VMs over to VMware.

VMware uses its own VMDK format for storing virtual disk images, while VirtualBox uses its own VDI format. The first step is getting a copy of vditool, VirtualBox’s command line program for manipulating VDI files.

The host OS I used to run VirtualBox is Ubuntu‘s 8.04 Hardy Heron on AMD64. The VirtualBox 1.6.0 .deb package didn’t include vditool, for some reason. Fortunately, the VirtualBox package in Debian’s “lenny” release includes it, so lets just grab it from there.

$ wget http://http.us.debian.org/debian/pool/main/v/virtualbox-ose/virtualbox-ose_1.5.6-dfsg-6_amd64.deb
$ dpkg -x virtualbox-ose_1.5.6-dfsg-6_amd64.deb vbox-1.5.6
$ sudo cp vbox-1.5.6/usr/lib/virtualbox/vditool /usr/lib/virtualbox/vditool
$ sudo ln -sf /usr/lib/virtualbox/vditool /usr/bin/vditool

There, now we have vditool installed. Next, we use it to export our old VirtualBox VDI back to raw disk data. However, if you used VirtualBox’s “Snapshots” with differencing VDI’s, you need to discard all snapshots before the one you want to write out as the raw disk: only the “base” data gets written out, not the “Current State”.

$ cd ~/.VirtualBox/VDI
$ vditool copydd win2000-i386-32gb.vdi win2000-i386-32gb.dd
vditool    Copyright (c) 2004-2008 innotek GmbH.

Copying VDI image file="win2000-i386-32gb.vdi" to DD file="win2000-i386-32gb.dd"...
The operation completed successfully!

Be careful, this could consume a lot of disk space, if you were using compacted VDI’s instead of fixed size as the raw image will be the full size of the disk image, which in my case was 32 GB even though the VDI only took ~6.5 GB on disk.

Once we have the raw data, we can create the VMDK metadata for our DD image. We compute the size of the raw data in sectors by dividing its size in bytes by 512:

$ stat --printf="%s 512/p" win2000-i386-32gb.dd | dc
67108864

We also need to compute the CHS geometry of the virtual disk. I used the assumption of 255 heads and 63 sectors:

$ stat --printf="%s 512/255/63/p" win2000-i386-32gb.dd | dc
4177

Once we have that information, we go ahead and create the VMDK metadata. Change the elements highlighted in blue as appropriate for your system:

$ cat >win2000-i386-32gb-flat.vmdk <<-__EOF__
# Disk DescriptorFile
version=1
CID=4dd210c6
parentCID=ffffffff
createType="monolithicFlat"

# Extent description
RW 67108864 FLAT "win2000-i386-32gb.dd" 0

# The Disk Data Base
#DDB

ddb.virtualHWVersion = "4"
ddb.geometry.cylinders = "4177"
ddb.geometry.heads = "255"
ddb.geometry.sectors = "63"
ddb.adapterType = "buslogic"
__EOF__

There, we now have a VMDK suitable for use in VMware! But, it takes up all 32 GB of space on the disk while only ~6.5 GB is actually in use. Lets use vmware-vdiskmanager to create another VMDK that is growable, instead:

$ vmware-vdiskmanager -r win2000-i386-32gb-flat.vmdk -t 0 win2000-i386-32gb.vmdk
Using log file /tmp/vmware-dossy/vdiskmanager.log
Creating a monolithic growable disk 'win2000-i386-32gb.vmdk'
  Convert: 100% done.
Virtual disk conversion successful.

And there you have it: a growable converted VMDK from VDI:

$ ls -lh win2000-i386-32gb*
-rw------- 1 dossy dossy  32G 2008-05-23 11:26 win2000-i386-32gb.dd
-rw------- 1 dossy dossy  327 2008-05-23 13:40 win2000-i386-32gb-flat.vmdk
-rw------- 1 dossy dossy 6.5G 2008-05-23 14:25 win2000-i386-32gb.vdi
-rw------- 1 dossy dossy 6.3G 2008-05-23 14:20 win2000-i386-32gb.vmdk

From here, I created a new virtual machine under VMware Server, specifying “Custom” and using an existing virtual disk–the one I just created.

Of course, I couldn’t just boot this VM up because the virtualized hardware from VirtualBox differs from the virtualized hardware in VMware, and the particular VM in question is a Microsoft Windows 2000 guest. To fix the Windows install, I performed a “repair installation” of Windows 2000. I guess this is necessary when you change all the hardware out from underneath a Windows machine. After completing the repair installation, the VM booted up! I went ahead and installed VMware Tools, rebooted, and now everything works as expected.

I don’t know how many folks out there want to migrate away from VirtualBox to VMware, but I couldn’t find very much useful information on doing it so hopefully this will help people out who want to do it.

Tags: , ,

Comments

  1. R.Batista says

    I wanted to do that with an hex editor (on windows).
    Is the cat >win2000… command inserting data to the beginning of the file?
    Line feed characters limit the lines, but right after __EOF__ is the raw data in the resulting file. Did I get it right?

  2. R. Batista:

    Yes, it’s just creating a plain text file named “win2000-i386-32gb-flat.vmdk” whose contents should be the lines between “<<-__EOF__" and "__EOF__".

  3. R. Batista says

    Thanks for the instructions. I misunderstood at first because I thought “win2000-i386-32gb-flat.vmdk” would end at 32 GB size, when actually is 327 in your example.

    It’s working now, I had just cut off the virtualbox header, renamed the raw file and created the metadata file.

  4. I am using virtualbox and I am trying to backup my virtual machines. I have a ubuntu host and a windows xp guest. I had 5 snapshots of this guest. I want to keep the current state as my new base state and get rid of all the snapshots. I deleted snapshots 1 through 4. took forever… I now have snapshot 5 and current state below it. Do I delete snapshot 5 will that keep me at current state or will that revert me to the initial pre snapshot 1 state. I havent found a straight answer yet and thought you might know. thanks in advance for anybody to really spell it out for me.

  5. Adam: Great question – from what I recall having done something similar, deleting all snapshots will leave the current state, not revert you to the pre-snapshots state. However, if you’re paranoid, make a duplicate of your guest VM and delete the snapshot in that copy and see what happens. In other words: make a backup of your guest before deleting the snapshot. :-)

  6. Dr. Kenneth Noisewater says

    According to Sun and The Inq, VBox supports 32 and 64-bit guests? Apparently it also supports 64-bit guests on 32-bit hosts as well as OpenGL acceleration and VMDK/VHD support.. Actually, at least according to the changelog, they’ve pretty much closed the gap on VMware…

  7. Kenneth: Thanks for the update! Indeed, VirtualBox 2.1 looks really promising and I might give it a try. Gotta love The Inquirer: “[…] the open sauce VirtualBox project […]” LOL!

  8. Found your blog helpful and well thought out – so I figured I should share. I might be missing something – as I’m only a VirtualBox user and not an expert:
    Although I could install XP64 on VirtualBox 2.1.4, I’m limited to only running one 64bit VirtualBox at a time… Once I launch a 64bit VirtualBox any additional attempts to run ANY VirtualBox results in a dialog box that ‘VT-x’ is already in use and stops the second instance – even regular 32-bit VirtualBox’s cannot run if 64 is running. I have VT-x disabled in the 32-bit boxes – and can run several of those at a time. And 64 wont run if a 32 is running. I’m now in the process of installing VMWare yet again.

  9. Tks.

    I didn’t try any of this. (I’m searching how to migrate a virtualbox VM to another pc)… But according to http://www.xgrr.de/wordpress/2008/02/25/convert-virtualbox-vdi-to-vmware-vmdk the second part colud be easier…using qemu.

    Cheers.

  10. Hi,
    I was trying to do the same migration from VBox 2.1.6 to VMServer 2.0.
    vditool is no longer included into VBox distro, BUT! there is even easier way now:

    1. Convert VDI to VMDK using: VBoxManage clonehd -formal VMDK
    2. Create a VM in VMServer similar to the the settings of your VirtualBox one, but without HDD
    Unfortunately in may case the VMDK disk created by VBox did not work, BUT!
    3. Convert VBox VMDK file to VMSeerver VMDK file: vmware-vdiskmanager -r -t 0
    4. Put the into the VMWare directory and add HDD to your newly created VM using existing image.

    Worked like charm for both Ubuntu and Win XP images. Win XP started without repair install, found a s…load of new hardware and works after a reboot!
    Dont’ forget to install VMware tools, of course!

    Happy Virtualization!

  11. and now without lees-than and more-than brackets:

    1. Convert VDI to VMDK using: VBoxManage clonehd vdi_file vmdk_file -formal VMDK
    2. Create a VM in VMServer similar to the the settings of your VirtualBox one, but without HDD
    Unfortunately in may case the VMDK disk created by VBox did not work, BUT!
    3. Convert VBox VMDK file to VMSeerver VMDK file: vmware-vdiskmanager -r vbox_vmdk_file -t 0 new_vmdk_file
    4. Put the new_vmdk_file into the VMWare directory and add HDD to your newly created VM using existing image.

  12. Kane Freehold says

    For converting VirtualBox Windows machines to VMware, VMware’s Converter (http://www.vmware.com/products/converter/ ) has worked seamlessly for me. I have used it to convert both physical PCs and VirtualBox PCs to VMware VMDK. By default it also makes all the changes needed to boot right up in a new VMware guest machine. Only additional work was to install VMware tools, and reboot. No need for a Windows reinstall or update.

    Current version of VMware Converter Standalone is 4.0.0 . I am using VMware Fusion 2.0 on Mac OS X 10.5.6. My converted guests were all WinXP, SP3. They were converted from VirtualBox 2.1.4 on Mac OS X 10.5.6.

    Note that the converter only works on Windows OS, though, so if you’re converting a Linux or other OS, it won’t help.

  13. Nick Seth-Smith says

    Thanks for the great instructions – worked like a champ for me. I was migrating a WIndows XP Pro guest OS and made one small change – disk adaptor type of ide instead of buslogic. As a result I was able to boot the OS under VMWare immediately; albeit it went through several boot cycles installing drivers for the new hardware and also required re-activation at M$ due to significant hardware change.

    I booted the new OS using the free VMWare Player. Having created an empty VMWare image I edited the .vmx definition file to point to my freshly minted copy of the VirtualBox image and away we went.

  14. @Kane Freehold
    For converting VirtualBox Windows machines to VMware, VMware’s Converter (http://www.vmware.com/products/converter/ )

    this do not support vdi files !!!

Leave a Reply to Anatoli Arkhipenko Cancel reply

*