Created
August 4, 2014 05:25
-
-
Save meoow/f1f6b41448eb6c4fad24 to your computer and use it in GitHub Desktop.
Mount VDI/VHD/VMDK images without virtual machine installed (need vdfuse)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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