Mount a VHD or VDI in Linux with vdfuse

My old post on mounting VHDs in Linux is rather outdated. I don’t think it even works anymore. So revisiting this on a newer Ubuntu version now. These instructions are for Ubuntu 14.04, so for other OS installs. You’ll also need your compiler installed, so you may need to run sudo apt-get install build-essential to get them before proceeding.

First we need some prequisites, you’ll need the virtualbox and libfuse-dev packages to be installed.

sudo apt-get install virtualbox libfuse-dev

Now you should get vdfuse for the newer versions of VirtualBox. It’s available in this github repo here: https://github.com/Thorsten-Sick/vdfuse

If you have git, simply run this command:

git clone https://github.com/Thorsten-Sick/vdfuse.git

Next change directory into vdfuse (e.g. cd vdfuse)

NOTE: The following example commands reference a specific version of VirtualBox, if you download a different version, be sure to replace the version number in the following commands.

Now we need the includes folder from the source. Again, this uses VirtualBox 4.3.16, so replace with the current version number. (Instead of using wget, you can also download the source with your browser which removes the need to figure out what the current version of VirtualBox is. )

wget http://download.virtualbox.org/virtualbox/4.3.16/VirtualBox-4.3.16.tar.bz2
tar xvjf VirtualBox-4.3.16.tar.bz2 VirtualBox-4.3.16/include

Now, we build vdfuse.

sh vdbuild_new VirtualBox-4.3.16/include vdfuse.c

If all went well, you should now have an executable called vdfuse in your vdfuse folder. Optionally, you can now copy it to /usr/local/bin or /usr/bin so any user on the system can use it. We’re almost done, there’s one fuse configuration change that is required.

First, we make sure that users other than root can read /etc/fuse.conf

sudo chmod o+r /etc/fuse.conf

And then you need to edit /etc/fuse.conf to have a line that reads user_allow_other.

Once you have done that, you should now be able to actually run your vdfuse executable. The entire disk and it’s partions are exposed as regular files in the target mount point. These can be loopback mounted like any other file.

An example from my machine:

vdfuse -f "~/VirtualBox VMs/Test/Test.vdi" ~/Test
ls -l ~/Test
-rw------- 1 1001 1001 144570624 Sep 14 12:18 EntireDisk
-rw------- 1 1001 1001  93214208 Sep 14 12:18 Partition1
-rw------- 1 1001 1001  51323392 Sep 14 12:18 Partition2

3 Responses to “Mount a VHD or VDI in Linux with vdfuse”

  1. Artem

    Hi! Thank you for useful and straight manual. I’ve encountered one problem when building vdfuse with VB 4.3.26, gcc 4.9.2. Your build script gave me:
    /usr/bin/ld: cannot find -l:/usr/lib/virtualbox/VBoxDDU.so
    though the file is there. I changed the compiler invocation command to:
    gcc "${infile}" -o "${outfile}" \
    `pkg-config --cflags --libs fuse` \
    -I"${incdir}" \
    -Wl,-rpath,"${INSTALL_DIR}" \
    -L"${INSTALL_DIR}" \
    -l:VBoxDDU.so \
    -Wall ${CFLAGS}

    (note -L added and -l changed). Then it builds with success.

  2. asdf

    FUSE headers not found. Are they installed?
    For a Centos Machine

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>