ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > Non-Windows Software

*NIX: Mounting .vdi Files (Even Dynamic Ones)


Wanted to get at a file in a VirtualBox guest OS without starting up the system in question.  The data was stored in a .vdi file (dynamic).  It turns out that one can mount such .vdi files using some qemu tools.

From thkala's answer on serverfault:
First you make sure that the nbd kernel module is loaded with the max_part option set to a number high enough to accommodate all the partitions in your .vdi image:

# rmmod nbd
# modprobe nbd max_part=16

Then you use qemu-nbd to attach the image:

# qemu-nbd -c /dev/nbd0 test.vdi

You will get a /dev/nbd0 block device, along with several /dev/nbd0p* partition device nodes. You use them as any other disk. Once you are done, you unmount everything, and disconnect the device:

# qemu-nbd -d /dev/nbd0

--- End quote ---

To determine the relevant partition device node I used cfdisk on /dev/nbd0, but it may be that a simple use of the blkid command may be enough.  partprobe may or may not be necessary after the first qemu-nbd invocation.

I first learned about this approach via How to mount a VirtualBox VDI image, but the specific instructions in the main post didn't quite work (though with modifications suggested in the comments things worked out).

Found this:

libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk images. You can use this for viewing and editing files inside guests, scripting changes to VMs, monitoring disk used/free statistics, creating guests, P2V, V2V, performing backups, cloning VMs, building VMs, formatting disks, resizing disks, and much more.

libguestfs can access almost any disk image imaginable. It can do it securely — without needing root and with multiple layers of defence against rogue disk images. It can access disk images on remote machines or on CDs/USB sticks. It can access proprietary systems like VMware and Hyper-V.

All this functionality is available through a scriptable shell called guestfish, or an interactive rescue shell virt-rescue.

--- End quote ---


Tried it out a bit with some success.

--- ---$ virt-filesystems -a vm.vdi

--- ---$ guestmount -a vm.vdi -m /dev/sda1 --ro tmp

--- ---$ guestumount tmp

Might be a keeper :)

Thanks for the info. Could be really useful.

This is slightly off-topic, but I was surprised to discover recently that since Windows 7 (or so) you can mount virtual disks (VHDs) natively in Windows. Just open Disk Management and use Action -> Attach VHD. (You can even configure Windows to boot from VHDs somehow, but I haven't looked into it enough to learn how to do that.)

Convenient indeed.

My impression had been that doing VHD-booting for Windows 7 was limited to certain editions, but perhaps that is mistaken:

This is confusing:

It turns out that the ability to boot from a VHD is actually available in all versions of Windows 7 and that only Windows 7 Ultimate and Windows 7 Enterprise can boot off of a VHD.-
--- End quote ---

But it gets clarified later on:

So it appears that the Native VHD Boot feature is available in all versions of Windows 7, but that only Windows 7 Enterprise and Windows 7 Ultimate can boot from VHD.-
--- End quote ---

I wonder what would happen if I attempt to boot some form of Linux from a VHD...


[0] Message Index

Go to full version