Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Last active November 10, 2023 01:01
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save jonathantneal/f20e6f3e03d5637f983f8543df70cef5 to your computer and use it in GitHub Desktop.
Save jonathantneal/f20e6f3e03d5637f983f8543df70cef5 to your computer and use it in GitHub Desktop.
Create or update macOS Big Sur (or Catalina, or Mojave) Recovery Partition Without Reinstalling
#!/bin/sh
# Set the macOS installer path as a variable
MACOS_INSTALLER="/Applications/$(ls /Applications | grep "Install macOS")"
MOUNT_POINT="$MACOS_INSTALLER/Contents/SharedSupport"
echo "macOS installer is \"$MACOS_INSTALLER\""
# Set the target disk as a variable
TARGET=$(diskutil info "$(bless --info --getBoot)" | awk -F':' '/Volume Name/ { print $2 }' | sed -e 's/^[[:space:]]*//')
echo "Target disk is \"$TARGET\""
# Set the target disk filesystem
FS_TYPE=$(diskutil info "$TARGET" | awk '$1 == "Type" { print $NF }')
echo "Target filesystem is \"${FS_TYPE}\""
# Download the APFS-compatible Recovery into /private/tmp (use 10.13.6, which also works with Mojave 10.14.x)
echo "Downloading macOSUpd10.13.6.RecoveryHDUpdate.pkg into /private/tmp"
curl http://swcdn.apple.com/content/downloads/14/54/001-08570-A_XCP1PVIXQK/xg4hvg6zgpoxonqkgiw2e2cqo1c0isl97q/SecUpd2020-004HighSierra.RecoveryHDUpdate.pkg --progress-bar -L -o /private/tmp/macOSUpd10.13.6.RecoveryHDUpdate.pkg
pkgutil --expand /private/tmp/macOSUpd10.13.6.RecoveryHDUpdate.pkg /private/tmp/recoveryupdate10.13.6
if [[ "${FS_TYPE}" == "apfs" ]]; then
echo "Running ensureRecoveryBooter for APFS target volume: $TARGET"
/private/tmp/recoveryupdate10.13.6/Scripts/Tools/dm ensureRecoveryBooter "$TARGET" -base "$MOUNT_POINT/BaseSystem.dmg" "$MOUNT_POINT/BaseSystem.chunklist" -diag "$MOUNT_POINT/AppleDiagnostics.dmg" "$MOUNT_POINT/AppleDiagnostics.chunklist" -diagmachineblacklist 0 -installbootfromtarget 0 -slurpappleboot 0 -delappleboot 0 -addkernelcoredump 0
else
echo "Running ensureRecoveryPartition for Non-APFS target volume: $TARGET"
/private/tmp/recoveryupdate10.13.6/Scripts/Tools/dm ensureRecoveryPartition "$TARGET" "$MOUNT_POINT/BaseSystem.dmg" "$MOUNT_POINT/BaseSystem.chunklist" "$MOUNT_POINT/AppleDiagnostics.dmg" "$MOUNT_POINT/AppleDiagnostics.chunklist" 0 0 0
fi
echo "Finished creating Recovery HD"
@toonetown
Copy link

@aonez
Copy link

aonez commented May 26, 2020

Thanks a lot @jonathantneal and @toonetown! Worked perfectly for 10.14.6. Just changed MACOS_INSTALLER to the path where I have the installer. Installing Catalina on a usb disk removed the recovery partition in my Mac mini's internal disk 🤷🏻‍♂️

@au10tic
Copy link

au10tic commented Jun 4, 2020

hi, how would i be able to create the recovery partition on a different Volume or disk? can anybody point me which lines to modify on the script

@aonez
Copy link

aonez commented Jun 4, 2020

@au10tic set the TARGET to whatever disk you want, after line 9. I don’t know if it will work.

@au10tic
Copy link

au10tic commented Jun 5, 2020

@aonez where would I add the volume or disk that I need this on? I am trying to install this on disk1s1, mounted on /Volumes/CataRecovery any help on this, would be appreciated.

# Set the target disk as a variable

TARGET=$(diskutil info "$(bless --info --getBoot)" | awk -F':' '/Volume Name/ { print $2 }' | sed -e 's/^[[:space:]]*//')

echo "Target disk is \"$TARGET\""

@aonez
Copy link

aonez commented Jun 6, 2020

If you execute the code above you'll see your boot volume name. So maybe replace line 9 with:

TARGET="CataRecovery"

But I'm very sceptical it will work...

@jonathantneal
Copy link
Author

I have updated the URL, allowing the instructions to work again.

@everybodies
Copy link

Thank You, still works in 2022, Mojave 10.14 :)

@VinneyUK
Copy link

Hi this script appears run fine for me however, when I try and boot into the recovery partition (command R ) my machine still wants to boot into internet recovery :(

Any ideas - driving me bonkers this :(

@Igor-Ruk
Copy link

Igor-Ruk commented Feb 24, 2023

Thanks for the script. Worked like a charm!
To download the MacOS installer you may use the links from this Apple support page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment