You are here
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!
Comments
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.
Thanks!
qemu-nbd looks very useful
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.
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.
Yet another way
This way it should also work to directly convert VDI to (uncompressed) RAW:
VBoxManage internalcommands converttoraw file.vdi file.raw
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.
http://bethesignal.org/blog/2011/01/05/how-to-mount-virtualbox-vdi-image/
contingency plans for virtualbox
I am curious about <a href="http://blog.thehigheredcio.com/2011/08/25/vdi-and-business-continuity/">... continuity for virtual desktops</a> and what a VritualBox approach might be for comparison to other solutions.
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.
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
Simple solution
Having VirtualBox GUI installed, you need at least one VM to manage disks, then you can "Copy" VDI disk to VMDK.
Syntax error
Hi there
Command:
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.
Usage:
VBoxManage clonemedium [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>
[--format VDI|VMDK|VHD|RAW|<other>]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--existing]
Syntax error: Invalid parameter 'RAW'
...
I have exactly the same result with VMDK
...
Syntax error: Invalid parameter 'VMDK'
any ideas ?
Correct Syntax
this must be...
VBoxManage clonehd <MyUUID> --format RAW MySytem.raw
Thanks for the update.
There are some real
There are some real necromancers :-D They raise your post from dead to #1 search in google :-D
True! :)
Great
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 :)
Pages
Add new comment