Skip to content

Instantly share code, notes, and snippets.

@meoow
Created August 4, 2014 05:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoow/f1f6b41448eb6c4fad24 to your computer and use it in GitHub Desktop.
Save meoow/f1f6b41448eb6c4fad24 to your computer and use it in GitHub Desktop.
Mount VDI/VHD/VMDK images without virtual machine installed (need vdfuse)
#!/bin/bash
if ! which vdfuse &>/dev/null;then
echo Can not find vdfuse >&2
exit 1
fi
if [[ ! -f "$1" ]];then
echo Disk file does not exist >&2
exit 1
fi
if [[ ! -d ~/.VDMP ]];then
mkdir ~/.VDMP
fi
rmdir ~/.VDMP/* 2>/dev/null
while true;do
MP=$RANDOM
if mkdir ~/.VDMP/$MP;then
break
fi
done
format=$(tr [[:lower:]] [[:upper:]] <<< ${1##*.})
case "$format" in
VDI|VMDK|VHD) : ;;
*) echo Can not recognize file extension >&2;exit 1 ;;
esac
vdfuse -f "$1" -t $format ~/.VDMP/$MP || exit 1
if [[ $MACHTYPE =~ ^.*-apple-darwin.*$ ]];then
hdiutil attach -imagekey diskimage-class=CRawDiskImage \
-mount optional ~/.VDMP/$MP/EntireDisk || exit 1
#open -b com.apple.DiskUtility
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment