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.
Finally I got it working. So in summary here are the steps to perform
Mount the vhd disk
sudo ./vdfuse -tVHD -w -f/Path/To/VHD /Path/To/Mountpoint
Attach the virtual partition blockfiles
hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount /Path/To/Mountpoint/PartitionN
Mount the virtual partition
mount -t YourFS /dev/diskK /Path/To/ParitionMountPoint
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.
vdfuse.c
) from https://github.com/Thorsten-Sick/vdfuse (currently at v83 - the original link is pegged to v80).svn co -r '{20120801}' http://www.virtualbox.org/svn/vbox/trunk/include/
Mount the vhd disk
sudo ./vdfuse -tVHD -w -f/Path/To/VHD /Path/To/Mountpoint
Attach the virtual partition blockfiles
hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount /Path/To/Mountpoint/PartitionN
Mount the virtual partition
mount -t YourFS /dev/diskK /Path/To/ParitionMountPoint
Miraculously, this works a charm!
This worked for me on Mountain Lion. No installation or compilation necessary:
FUSE works on MacOSX, however you would need the headers.
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.
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.