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

May 19th, 2009 by bodhi.zazen

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.

Caveats :

  1. With VMWare-tools installed, Mouse integration did not work (as it did with KVM).
  2. The resolution of the guest is also larger then the Virtualbox window.
  3. I installed the VirtualBoxAdditions and guest resolution worked well, mouse integration, however, did not.

As always, I hope this helps. Converting usually went smoothly for me however there is the occasional .vmdk I could not convert.

StumbleUpon

Posted in Linux

17 Comments »

  1. Hey bodhi.

    Good job with this one, I had no Idea that was even possible. Thanks!

    Comment by Montel — May 19, 2009 @ 6:30 am

  2. Great tips, very useful, thanks.

    Comment by wiflye81 — May 19, 2009 @ 7:45 am

  3. Terrific — thanks!

    Comment by HDave — May 19, 2009 @ 8:31 pm

  4. We migrate from VMware to KVM. With this howto we can reuse our appliances. Great, Thank you very much

    Comment by maurizio — May 25, 2009 @ 7:15 am

  5. When I try to boot either the vmdk or qcow2 file from kvm, it displays an error message
    for a fraction of a second and then returns to the screen asking whether I want to boot
    safe mode. How to I freeze it on the error screen? Thanks.

    Comment by WRF — June 15, 2009 @ 10:09 am

  6. [...] Jun 17 Convert Vmware to virtual box By adminAdd commentsTest http://blog.bodhizazen.net/linux/convert-vmware-vmdk-to-kvm-qcow2-or-virtualbox-vdi/ This entry was posted on Wednesday, June 17th, 2009 at 1:12 pm and is filed under Test. You can [...]

    Pingback by Augie’s Weblog » Blog Archive » Convert Vmware to virtual box — June 17, 2009 @ 4:11 pm

  7. vmware tools…

    Intriguing idea, but I don’t know if I believe you one hundred percent….

    Trackback by Jonathan — July 2, 2009 @ 11:57 pm

  8. I have a pile of flat vmware images that have been converted using the method described here (although with kvm-img). They appear to convert fine but so far 2 out of 4 fail. One is a Ubuntu feisty vm. The Xorg log file complains of no device found (it contains reference to vmware vga drivers although vmtools were never installed) and there is also no network card present. Another one is WinXP. It doesn’t even boot. I get a BSOD type result.

    There is a lack of online documentation on how to proceed once the images have been converted and how to tackle the kind of problems I have described.

    Comment by Juan — July 27, 2009 @ 9:20 am

  9. I agree, conversion does not always work. I also agree with the lack of documentation , many sites that use “KVM” in the title are using virsh or virt-manager as front ends, for example.

    I think the problems vary with the VM and for your graphics card try reconfiguring X (boot to recovery mode and try xfix).

    Comment by bodhi.zazen — July 27, 2009 @ 5:36 pm

  10. I tried to convert a VMware VM to run on Ubuntu Jaunty KVM but got the Blue Screen of Death.
    When I got it to boot from CDROM so I could do a repair install, it just rebooted.

    KVM is not quite there handling VMware VM’s.

    Carl

    Comment by Carl Moser — September 7, 2009 @ 6:38 pm

  11. Converting Windows VM does not work so well due to the way Microsoft licenses it’s products.

    Windows is licensed per hardware and changing VM changes your hardware configuration and you are likely to have problems with needing to either re-authorize your installation or re-install drivers.

    IMO, with Windows, you are better off backing up your data and performing a fresh install.

    Converting Linux VM is easier, but still prone to errors.

    The good news is, this process does not change your original VM.

    Comment by bodhi.zazen — September 8, 2009 @ 8:52 am

  12. [...] Convert VMware .vmdk to KVM .qcow2 or Virtualbox .vdi.Converting a VMWare image to Xen HVM 1.需要的第一个工具: vmware-vdiskmanager.exe .在网上找了一通,没有找到单独的下载包,只好安装了一个vmware workstation 6.5,vmware-vdiskmanager.exe就在 workstation 安装目录下. [...]

    Pingback by help-v » 将vmware的虚拟机迁移到kvm — September 18, 2009 @ 11:30 pm

  13. Waiting for a fix to permit VMware with work with 9.10 Beta I decided to give KVM a try… thanks for your tireless efforts to keep us all on-track.

    frank

    Comment by fjgaude — October 1, 2009 @ 1:49 pm

  14. [...] convert the VMware images I used this How-To. This worked quite well for most of my Virtual Machines. But several had snapshots or were [...]

    Pingback by Convert VMware growable, splitted and snapshoted disks « falstaffs Reise durchs Internet — December 20, 2009 @ 9:16 am

  15. [...] ——— I used the following link to convert from vmdk to qcow2. [LINK] The following link is the howto located in the nagiosxi support forums. [LINK] [...]

    Pingback by Small is Beautiful » Blog Archive » RHEV - import vmware image into RHEV — January 2, 2010 @ 8:45 am

  16. Social comments and analytics for this post…

    This post was mentioned on Twitter by openvz: Convert VMware .vmdk to KVM .qcow2 or Virtualbox .vdi http://tinyurl.com/o87xwp...

    Trackback by uberVU - social comments — January 24, 2010 @ 10:12 pm

  17. [...] an XML file lacking several sections. Since it seems that we reached a dead end here, it is time to convert the vmdk images and define the libvirt xml schema later on: $ qemu-img convert -f vmdk -O qcow2 vApp-disk1.vmdk [...]

    Pingback by BrainBlog » VMware vApp (from vSphere) to KVM — March 5, 2010 @ 9:02 am

RSS feed for comments on this post. TrackBack URL

Leave a comment