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.


Mickey Mazarick's picture

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

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.

Balwinder S Dheeman's picture

 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

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

VBoxManage internalcommands converttoraw file.vdi file.raw

Neal McBurnett's picture

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.

Jerry's picture

I am curious about <a href="">... continuity for virtual desktops</a> and what a VritualBox approach might be for comparison to other solutions.

Geert's picture

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.

frank a.'s picture

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

pikob's picture

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

McGrifffin's picture

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 ?

McGrifffin's picture

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

Jeremy Davis's picture

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

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

Jeremy Davis's picture

We probably should update it so that it's actually still relevant then! :)
Ruby Roswell'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></code>


adil's picture

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