How to mount a virtual disk image on a host

 

If you are running Ubuntu, and want to mount a virtual hard disk image on your host, here is how to do it.

This works for any VBox-compatible disk:

  • VDI – VirtualBox disk image (Oracle)
  • VMDK – Virtual Machine Disk (VM ware)
  • VHD – Virtual Hard Disk (Microsoft)
  • HDD – Parallels Hard Disk (OS X)

 

First of all, install virtualbox-fuse, to be able to mount virtual disk as Filesystem in Userspace (FUSE):

sudo apt-get install virtualbox-fuse

 

Next step is setting the proper permissions for the configuration file:

sudo chmod a+rwx /etc/fuse.conf

 

Mount the virtual disk as FUSE:

vdfuse -r -a –v -f /path/to/virtual/disk/VirtualDiskName.vhd /path/to/mount/fuse_folder

(for explanation of the options used here, see the end of this post)

 

The output of this command would look something like this:

disktype is VHD

Partition Size Offset

========= ==== ======

Partition1 1048576 104857600

Partition2 105906176 107267227648

 

Now, the partition(s) appear as block files (Partition1, …), and can be mounted as a Loop Device:

sudo mount /path/to/mount/fuse_folder/Partition1 /path/to/mount/as/loop/folder/

 

Now the files contained in the virtual disk image can be accessed under /path/to/mount/as/loop/folder/

 

After usage, if the virtual disk image should be used in the same session, do the following unmounts:

sudo umount /path/to/mount/as/loop/folder/

sudo umount /path/to/mount/fuse_folder/

 

If you do a vdfuse -h, you will get the following:

DESCRIPTION: This Fuse module uses the VirtualBox access library to open a

VirtualBox supported VD image file and mount it as a Fuse file system. The

mount point contains a flat directory containing the files EntireDisk,

Partition1 .. PartitionN. These can then be loop mounted to access the

underlying file systems

USAGE: vdfuse [options] -f image-file mountpoint

-h help

-r readonly

-t specify type (VDI, VMDK, VHD, or raw; default: auto)

-f VDimage file

-a allow all users to read disk

-w allow all users to read and write to disk

-g run in foreground

-v verbose

-d debug

NOTE: you must add the line “user_allow_other” (without quotes) to /etc/fuse.confand set proper permissions on /etc/fuse.conf for this to work.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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