17

Is it possible (how) to mount an VHD file created by Windows 7 in OS X?

I found some information about how to do this on linux. There is a fuse fs "vdfuse" which uses virtualbox libs to mount filesystems supported by virtualbox. However I was unable to compile the package on osx because nearly all headers are missing and I doubt that it would work anyway...

EDIT #2: Okay I got my hands dirty and finally compiled vdfuse (http://forums.virtualbox.org/viewtopic.php?f=26&t=33355&start=0) on osx. As a starting point I used macfuse (http://code.google.com/p/macfuse/) and looked at the example file systems.

This led me to the following build script

infile=vdfuse.c
outfile=vdfuse
incdir="your/path/to/vbox/headers"
INSTALL_DIR="/Applications/VirtualBox.app/Contents/MacOS"
CFLAGS="-pipe"

gcc -arch i386 "${infile}" \
         "${INSTALL_DIR}"/VBoxDD.dylib \
         "${INSTALL_DIR}"/VBoxDDU.dylib \
         "${INSTALL_DIR}"/VBoxVMM.dylib \
         "${INSTALL_DIR}"/VBoxRT.dylib \
         "${INSTALL_DIR}"/VBoxDD2.dylib \
         "${INSTALL_DIR}"/VBoxREM.dylib \
        -o "${outfile}" \
        -I"${incdir}" -I"/usr/local/include/fuse" \
        -Wl,-rpath,"${INSTALL_DIR}"  \
        -lfuse_ino64  \
        -Wall ${CFLAGS}

You actually don't need to compile VirtualBox on your machine, just install a recent version of VirtualBox.

So now I can partially mount vhds. The separate partitions appear as block files Partition1, Partition2, ... on my mount point. However Mac OS X does not include a loopback file system and macfuse's loopback fs does not work with block files, so we need a loopback fs to mount the blockfiles as actual partitions.

5
  • What does Win7 Have to do with it? To answer your question completely, I'd need to know what application created your VHD (VirtualBox, VMware (and workstation vs Server vs...), etc.)
    – gWaldo
    Aug 25, 2010 at 12:47
  • Actually I created the VHD with diskpart contained in Windows 7... Aug 25, 2010 at 20:29
  • You may want to use gcc -arch x86-64 "${infile}" \ for line 7 if you're running Leopard or Snow Leopard (esp 10.6) so it compiles 64-bit
    – gWaldo
    Aug 26, 2010 at 12:45
  • @gWaldo, VHD is a file format used by Windows 6.1, Virtual PC, Virtual Server, Hyper-V, Xen, and others.
    – Chris S
    Aug 26, 2010 at 13:31
  • Incredibly, I didn't have to alter these instructions by much to get this working in 2020. However, there were a few small alterations. I've listed them in a new post.
    – Ben XO
    Jan 27, 2020 at 22:49

7 Answers 7

7

Finally I got it working. So in summary here are the steps to perform

  1. Install macfuse
  2. Install Virtual Box
  3. Compile vdfuse as mentioned in the question
  4. Mount the vhd disk

    sudo ./vdfuse -tVHD -w -f/Path/To/VHD /Path/To/Mountpoint

  5. Attach the virtual partition blockfiles

    hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount /Path/To/Mountpoint/PartitionN

  6. Mount the virtual partition

    mount -t YourFS /dev/diskK /Path/To/ParitionMountPoint

1
  • Incredibly, I didn't have to alter these instructions by much to get this working in 2020. However, there were a few small alterations. I've listed them in a new post.
    – Ben XO
    Jan 27, 2020 at 22:48
6

It's now 2020, and these 10-year-old instructions almost worked. Here's what I did to mount an old Backup Image from Windows 7 on my Mojave Mac, based on the accepted answer from Jan Bernlöhr, as well as the script in the question.

  1. Install osxfuse (the successor to macfuse)
  2. Install VirtualBox
  3. Download the vdfuse source code (vdfuse.c) from https://github.com/Thorsten-Sick/vdfuse (currently at v83 - the original link is pegged to v80).
  4. Download the VirtualBox headers, but you have to get a version from 2012. I used the following command: svn co -r '{20120801}' http://www.virtualbox.org/svn/vbox/trunk/include/
  5. Use the following build instructions, adapted from the question, but with a few small alterations (64-bit build, and newer VirtualBoxes don't seem to have VBoxREM.dylib:
  infile=vdfuse.c
  outfile=vdfuse
  incdir="$(pwd)/include"
  INSTALL_DIR="/Applications/VirtualBox.app/Contents/MacOS"
  CFLAGS="-pipe"

  gcc -arch x86_64 "${infile}" \
         "${INSTALL_DIR}"/VBoxDD.dylib \
         "${INSTALL_DIR}"/VBoxDDU.dylib \
         "${INSTALL_DIR}"/VBoxVMM.dylib \
         "${INSTALL_DIR}"/VBoxRT.dylib \
         "${INSTALL_DIR}"/VBoxDD2.dylib \
        -o "${outfile}" \
        -I"${incdir}" -I"/usr/local/include/fuse" \
        -Wl,-rpath,"${INSTALL_DIR}"  \
        -lfuse_ino64  \
        -Wall ${CFLAGS}
  1. Mount the vhd disk

    sudo ./vdfuse -tVHD -w -f/Path/To/VHD /Path/To/Mountpoint

  2. Attach the virtual partition blockfiles

    hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount /Path/To/Mountpoint/PartitionN

  3. Mount the virtual partition

    mount -t YourFS /dev/diskK /Path/To/ParitionMountPoint

Miraculously, this works a charm!

4

This worked for me on Mountain Lion. No installation or compilation necessary:

hdiutil attach -readonly -imagekey diskimage-class=CRawDiskImage <Path to .vhd file>
6
  • Say for me on 10.8.3 : hdiutil: attach failed - no mountable file systems
    – hkulekci
    Jun 4, 2013 at 7:48
  • I just tried it again and get the same error message. Weird. I have used this a couple of times successfully some months ago.
    – henning77
    Jun 4, 2013 at 10:21
  • With an older vhd image it works again (NTFS, created in 01/2013). With a newer vhd it doesn't. I don't know yet where the difference is.
    – henning77
    Jun 18, 2013 at 11:07
  • i did not find something about this issue.
    – hkulekci
    Jun 18, 2013 at 14:07
  • I have a bitlocker-encrypted VHD from Windows 7 and was able to mount it similarly with hdiutil attach -imagekey diskimage-class=CRawDiskImage /Path/to/encrypted.vhd -nomount and then use m3datarecovery.com/mac-bitlocker to unencrypt it. DAEMON Tools for Mac: Smart mounting and imaging software also worked to mount, but it's not free.
    – Pat
    Jan 2, 2017 at 19:50
1

FUSE works on MacOSX, however you would need the headers.

1
  • Thanks, I already established macfuse on our machines to make ntfs (tuxera), ext2 and other file systems accessible to our osx users. Maybe I can compile the lib on a linux system and then copy the files ot osx... Aug 25, 2010 at 20:34
1

If you don't find another solution, you could use VirtualBox (or another similar tool that supports VHD files) to run a virtual system that uses that virtual disk image, and then access or copy the files you need using Samba or sftp or such.

1
  • Thank you, this is feasible but unfortunately not quite what I'm looking for. Currently I have NTFS partitions on a dual boot system, so I can read/write data from win and osx. The next step is virtualizing the partitions which contain win7 and data... However the data is still needed to be accessible on osx. Aug 25, 2010 at 20:32
1

Just rename your VHD file to IMG.. double click on it to mount it. That's all.

Remember that Mac OS X provides read access only for NTFS volume, so if your VHD has a NTFS volume, you have only read access.

2
  • 1
    Unfortunately this does not work. DiskImageMounter just says "not recognized". Jan 13, 2012 at 22:55
  • worked for me with a .vhd file that does not contain a Windows installation but is just a virtual copy of an USB hard drive.
    – Silv
    Jul 6, 2020 at 9:05
0

The easiest way (in 2022): Rename the .vhd to .img and double click. Change what you need to change, eject the drive and rename back to .vhd.

Works like a charm.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .