TurnKey Linux Virtual Appliance Library

Converting a virtual disk image: VDI to VMDK to a raw loopback file you can mount

By default, VirtualBox creates virtual disk images in a special format called VDI, which is unique to VirtualBox. Disk images are stored in $HOME/.VirtualBox/HardDisks.

You'll need to convert VDI into another format if you want to run a VirtualBox VM on another virtualization platform, such as VMWare or KVM.

The VMDK virtual disk format is a good choice because even though it originated with VMWare it is supported by other virtualization platforms including VirtualBox and KVM.

VirtualBox enables the conversion using the low-level "VBoxManage clonehd" command:

VBoxManage list hdds # prints a list of disk image UUIDs
VBoxManage clonehd <UUID> -o converted.vmdk format VMDK
cd ~/.VirtualBox/HardDisks/
ls -la converted.vmdk

Once you have converted to VMDK you can use qemu-img, a tool bundled with qemu (KVM's virtualization backend) to further convert VMDK to other formats.

A particularly useful format to convert to is 'raw' which you can then mount as a loopback device:

apt-get install qemu
qemu-img convert -f vmdk converted.vmdk -O raw converted.raw
mount -o loop converted.raw /mnt

Ever had to convert between disk image formats? Post a comment!

You can get future posts delivered by email or good old-fashioned RSS.
TurnKey also has a presence on Google+, Twitter and Facebook.


Guest's picture

qcow2 for avoiding the size of a raw file

Just a note, but the biggest disadvantage is that raw will exctract a file that is the same size as the compressed drive onto your system. Usually the native file system has some compression but this is still a problem if you have 1000 gig disk images. 

A work-around is to use kvm-nbd or qemu-nbd which are part of the kvm package. This creates a network block device attached to a qcow2 image which you can mount instead of loop.  This will sve you the trouble of having a 1 TB file sitting on your drive.



Liraz Siri's picture

qemu-nbd looks very useful

Usually the filesystems we play with during appliance development are pretty small, so the size of a raw loopback file is manageable. For larger systems it can be a problem.

I haven't tried the nbd tool yet, but it sounds like a very useful trick. Might have other creative uses as well. Thanks for sharing!

PS: Sorry for the late response. We're in the middle of a development cycle and I'm spending most of my time offline.

Guest's picture

It sometimes is handy to mount RAW images via loopback

 We can directly create RAW images with newer versions of VBoxManage clonehd <uuid>|<filename> <outputfile> [--format VDI|VDMK|VHD|RAW|<other>] ...

Though, I'm not sure what that <other> could be.


Guest's picture

Yet another way

This way it should also work to directly convert VDI to (uncompressed) RAW:

VBoxManage internalcommands converttoraw file.vdi file.raw

Guest's picture

Directly mounting a partition from inside a .vdi file: qemu-nbd

This post notes how to use qemu-nbd to directly get at the partitions in a .vdi file - no need to convert to vmdk first.


Guest's picture

contingency plans for virtualbox

I am curious about <a href="http://blog.thehigheredcio.com/2011/08/25/vdi-and-business-continuity/">business continuity for virtual desktops</a> and what a VritualBox approach might be for comparison to other solutions.

Guest's picture

Mount Dynamic VDI on CentOS

I run CentOS 5.5. My nbd kernel module does not support partitions, at least I don't see /dev/nbd0p1 etc., but do get a /dev/nbd0. Here are my commands:

# modprobe nbd

# qemu-nbd -c /dev/nbd0 <some-dynamic>.vdi

# mount -o loop,offset=32256 /dev/nbd0 /mnt/nbd0p1

That's it! The offset was found by looking at the starting sector in the fdisk output. It lists 63 in my case which is 63 * 512 = 32256 bytes.

Guest's picture

mount -o loop,offset=32256 /dev/nbd0 /mnt/nbd0p1

another way to access the partitions in a raw disk is kpartx (Fedora)

# kpartx -a /dev/nbd0

one can now mount, use and eject the filesystems in nautilus

# kpartx -d /dev/nbd0

Guest's picture

Simple solution

Having VirtualBox GUI installed, you need at least one VM to manage disks, then you can "Copy" VDI disk to VMDK.

Guest's picture

Syntax error

Hi there

VBoxManage clonehd <MyUUID> -o MySytem.raw format RAW # has following output

Oracle VM VirtualBox Command Line Management Interface Version 5.0.14
(C) 2005-2016 Oracle Corporation
All rights reserved.


VBoxManage clonemedium      [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>
                            [--format VDI|VMDK|VHD|RAW|<other>]
                            [--variant Standard,Fixed,Split2G,Stream,ESX]

Syntax error: Invalid parameter 'RAW'

I have exactly the same result with VMDK
Syntax error: Invalid parameter 'VMDK'

any ideas ?

Guest's picture

Correct Syntax

this must be...
VBoxManage clonehd <MyUUID> --format RAW MySytem.raw

Jeremy Davis's picture

Thanks for the update.

In fairness this blog post is almost 6 years old! :)
Guest's picture

​There are some real

​There are some real necromancers :-D They raise your post from dead to #1 search in google :-D

Jeremy Davis's picture

True! :)

We probably should update it so that it's actually still relevant then! :)
Guest's picture


my colleague needed The Common Application AP-1 several days ago and was made aware of a web service that hosts lots of form templates . If people are requiring The Common Application AP-1 as well , here's a <code>http://goo.gl/pk2ORc</code>


Guest's picture

qemu-img convert and UUID

I have ESXi vm having four disk, and in /etc/fstab they are mounted by UUID’s.

 Now I need to convert these VMDK’s to raw disk using ‘qemu-img convert’ , my worries is do ‘qemu-img convert’ will change the UUID of the disk?


Thanks in advance :)


Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)