Madhav Kobal's Blog

This blog will be dedicated to Linux, Open Source and Technology news, affairs, how-tos and virtually EVERYTHING in these domains.

Convert VMware .vmdk to KVM .qcow2 or Virtualbox .vdi

Posted by madhavkobal on 21/08/2009

I wrote this how to as I was having problems converting a VMware image to KVM. The existing tutorials all suggest using qemu-img to convert the .vmdk, however it was not working as qemu-img only supports VMware 3 and 4 compatible image formats.

At least that is what Google searching and reading the qemu man pages yielded after I got this error message :

qemu-img convert Ubuntu.vmdk -O qcow2 Ubuntu.qcow
qemu-img: Could not open ‘Ubuntu.qcow’

And to make matters worse, it was difficult to find any information on converting the .vmdk if it was split into multiple files.

This is how I ended up converting. You can convert from a .vdi or a “flat” .vmdk


First convert the .vmdk to a format compatible with qemu-img.

Turns out this can be done with vmware-vdiskmanager.

1. Converting from .vmdk

Use vmware-vdiskmanager to create a copy. This works with a single or multiple disks.


ls
Ubuntu.vmdk
Ubuntu-f001.vmdk
Ubuntu-f002.vmdk
Ubuntu-f003.vmdk ...

vmware-vdiskmanager -r Ubuntu.vmdk -t 0 Ubuntu-copy.vmdk

Note: If you have multiple disks, use Ubuntu.vmdk as well (you do not need to convert each Ubuntu-f001.vmdk).

Note: That is a -t Zero not a capital O. see man vmware-vdiskmanager.

Note: vmware-vdiskmanager is part of vmware server (and workstation, not sure about player).

2. Alternate – Converting “flat files”.

Flat files are used by vmware if you create a virtual disk (vmdk) with the “Allocate all disk space now” option (you have this option when creating disks for use with vmware). Flat files contain all the data from your .vmdk and can (usually) be converted directly.

Notice, flat files can be directly converted to .qcow. If you wish to convert to .vdi (VirtualBox) convert flat to raw.

KVM :

qemu-img convert Ubuntu-flat.vmdk -O qcow2 Ubuntu-copy.qemu

Note: That is a capital O qcow2

RAW (for VirtualBox)

qemu-img convert Ubuntu-copy.vmdk -O qcow2 Ubuntu-copy.qemu

Note: That is a capital O qcow2

3. Boot the image with KVM

kvm -hda Ubuntu-copy.qcow -net nic -net user -m 512

Caveats :

  1. If you have vmware-tools installed, you will have mouse integration.
  2. If you have vmware-tools installed, the guest desktop may well be larger then the kvm window. You will need to resize the guest display to 800×600 .
  3. I could not convert a .vmdk which was using LVM (Fedora).

VirtualBox – Convert to .vdi

1. First use qemu-img to convert the copy .vmdk to raw.

qemu-img convert Ubuntu-copy.vmdk Ubuntu-copy.img

qemu-img with no options will make a raw image. If you prefer you can specify

qemu-img convert Ubuntu-flat.vmdk -O raw Ubuntu-copy.img

2. Then convert the raw image with VBoxManage

VBoxManage convertfromraw – -format VDI Ubuntu-copy.img Ubuntu-copy.vdi

Note: Two – – in front of “format” (WordPress converts two – – to one long one).

3. Start VirtualBox, make a new machine or add the Ubuntu.vdi to an existing machine.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: