Mount partitions from a VirtualBox VDI in Linux.

7 07 2011

Hi, people!

The title’s pretty self explanatory, so I’ll just dive right in…

I needed to access data on a VM which had no network connectivity, and therefore needed a way to mount partitions from the host (Ubuntu 11.04 in this case).

After a little research, I found this article. It explains in simple steps how to go about this. Here’s my much shortened (but far less complete) version:

First, you need to have the package qemu-kvm installed. This can be done in Ubuntu by running the following command:
sudo apt-get install qemu-kvm

Next, load the nbd kernel module.
sudo modprobe nbd

Now you’re ready to make the partitions available to the host OS by running:
sudo qemu-nbd -c /dev/nbd0 {VDI FILE}

This will allow you to access the partitions as /dev/nbdp{number}. For example, to mount the first partition of the VDI in /mnt, you would run the following command:
sudo mount /dev/nbd0p1 /mnt.

For a whole bunch more information on this, click the link to the original article I mentioned before.

Any questions, just ask!





11 responses

3 12 2011

Pardon the newbie question: It says I have to specify the filesystem type to mount it.

$ sudo mount /dev/nbd0p1 /mnt
mount: you must specify the filesystem type

Is this intrinsic to the vdi file, or is that something I can just put in for any old file system I want it to be?

3 12 2011

Hi Fanglord,

If it says you have to state the filesystem, it usually means that it was unable to automatically detect which one it is. To specify, use the -t flag. If the FS is ext3, command will be:

$ sudo mount -t ext3 /dev/nbd0p1 /mnt

If it still doesn’t work, then is there a possibility that your OS doesn’t support the filesystem used in the VM? What are your Host and Guest OS?


3 12 2011

My host OS is Ubuntu natty (11.04), my guest OS is Mac OS X snow leopard (10.6.x). I have the hfs+ tools installed on Natty.

3 12 2011

Ah, but wait… I’m mounting the vdi file on my Mac OS, but it’s shared by a Freenas server, which runs a version of FreeBSD. I’m not sure of the filesystem type that FreeBSD uses…

6 12 2011

That would explain it. I’m not sure what filesystems OSX will support, but I could take an educated guess and say that that’s the problem. I’d look into how to mount a FreeBSD partition on Mac OSX.


6 12 2011

I did some more research, and realized that FreeNAS creates ZFS partitions, which “mount” won’t mount. đŸ˜¦ I might not want to use it for storing my Music and photo files, as it might be hard to get them out if something goes wrong.

7 12 2011

Hi again,

Thanks for keeping me posted. I might update the guide, to mention the potential problems from OSX. I’d advise exactly what you’re thinking – you could look at customising modify FreeNAS, so it uses a more widely accepted format. One thing to ABSOLUTELY ensure is that you have done regular backups. Speaking as an IT Administrator, nothing can prevent unexpected HDD failure – Failing to prepare is preparing to fail. If you don’t have crazy amounts, or at least don’t add crazy amounts regularly, you might want to think of backing up on DVD. I’ve found it to be one of the most reliable medium-term backup methods possible.


7 02 2012

In case a few more details would be helpful, the following worked for me on openSuse 11.4 – 64bit host (all commands run as root), mounting an ntfs filesystem from a dynamic vdi created from a virtualbox windows7 guest:

(Much of this was figured out from

1) unload network block devicei kernel module, in case it is loaded without the max_part option (if you have already linked any nbd devices to vdi files, remove them with “qemu-nbd -d /dev/nbd0” or similar)

rmmod nbd

2) reload nbd with max_part option

modprobe nbd max_part=16

3) link your nbd to your vdi file

qemu-nbd -c /dev/nbd0 VDIFILE.vdi

4) scan for partitions, this should create the new device files in dev


5) list your device files to make sure they were created

ls -l /dev/nbd0*

6) to view the sizes of any partions found in the vdi, you can run fdisk and print the partition table

fdisk /dev/nbd0

7) finaly, mount the desired partition (I used ‘-r’ for readonly to be safe)

mount -t ntfs -r /dev/nbd0p2 /MNTPOINT

7 02 2012

Many thanks, Pat!

I’ll add your comments to my blog’s new location as soon as I get a chance.


25 06 2012

Just to let you know that your procedure allowed me to mount a VDI with OS/2 Warp 4 under Ubuntu, and extract some data from there. As I’m still struggling with the networking part of OS/2 under VirtualBox, it was the only way to communicate data from the OS/2 guest back to the host. Thanks a big deal!!!

25 06 2012

Hi Smurf,

Glad you found the article useful! Check out my new blog at – all the articles from here and a bunch of new ones.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: