Skip to content

Instantly share code, notes, and snippets.

@macsimom
Last active November 18, 2020 12:57
Show Gist options
  • Save macsimom/982d507ff94767428e4832ef0fdbdf0c to your computer and use it in GitHub Desktop.
Save macsimom/982d507ff94767428e4832ef0fdbdf0c to your computer and use it in GitHub Desktop.
A quick script to convert a macOS recovery partition to a bootable iso intended for VMware Fusion
#!/bin/bash
# Download the script from https://gist.github.com/macsimom/982d507ff94767428e4832ef0fdbdf0c
# Open Terminal
# diskutil list
# Find the device identifer of the recovery partition, eg. "disk1s3"
# call the script with the device indentifier
# bash build_a_booter_for_fusion.sh disk1s3
# An iso file is built at /Users/Shared
#
# Open VMware Fusion
# Create a new custom virtual machine
# Choose "Apple OS X" and whatever OS specifier matches the version of the booter iso
# Connect the iso file to virtual optical drive
# Start up the virtual machine
# Connect your TimeMachine drive to the virtual USB
# At the macOS Utilities screen choose to restore from TimeMachine
DEST="/Users/Shared"
if [[ -n "$1" && -e "/dev/$1" ]]; then
RECOVERYDEV="/dev/${1}"
echo "Attempting to create booter from user provided input: ${RECOVERYDEV}"
else
echo "Attempting to create booter from first available recovery volume"
RECOVERYDEV=$(diskutil list|grep Recovery|head -n1|awk '{print $NF}')
fi
diskutil mount $RECOVERYDEV
RECOVERYMOUNT=$(/usr/libexec/PlistBuddy -c "Print :MountPoint" /dev/stdin <<<$(diskutil info -plist $RECOVERYDEV))
RECOVERYVERSIONPLIST=$(find "$RECOVERYMOUNT" -name SystemVersion.plist)
if [ ! -e "$RECOVERYVERSIONPLIST" ]; then
echo "Recoery system version not found..."
diskutil unmount "$RECOVERYMOUNT"
exit 1
fi
RECOVERYVERSION=$(/usr/libexec/PlistBuddy -c "Print :ProductVersion" "$RECOVERYVERSIONPLIST")
BOOTFOLDER=$(sed -E 's/\/SystemVersion.plist//' <<<$RECOVERYVERSIONPLIST)
cd "$DEST"
if [ -e "FusionBooter_${RECOVERYVERSION}.iso" ]; then
echo "FusionBooter_${RECOVERYVERSION}.iso already exists. Delete it? y/n"
read RESPONSE
if [ "$RESPONSE" == "y" ]; then
rm "FusionBooter_${RECOVERYVERSION}.iso"
else
echo "Exiting early..."
diskutil unmount "$RECOVERYMOUNT"
exit 1
fi
fi
echo "hdiutil makehybrid -o \"FusionBooter_${RECOVERYVERSION}\" -hfs-blessed-directory \"$BOOTFOLDER\" \"$RECOVERYMOUNT\"
"
hdiutil makehybrid -o "FusionBooter_${RECOVERYVERSION}" -hfs-blessed-directory "$BOOTFOLDER" "$RECOVERYMOUNT"
if [ "$?" == "0" ]; then
echo "Created ${DEST}/FusionBooter_${RECOVERYVERSION}.iso"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment