Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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"
@blindmanonacid
Copy link

blindmanonacid commented Aug 13, 2019

This script didn't work for me on 10.14.6, this did however:
https://forums.macrumors.com/threads/how-to-create-recovery-partition-post-install.2161426/#post-27464447
replying with this since this page seems to be the first hit on a google search to create a recovery partition for Mojave.

@danielshenry
Copy link

danielshenry commented Nov 11, 2019

I'm not gonna lie...I am a copy/paste kind of terminal user :-/

with that said, after cd'ing into the folder with this script in it, using both "recovery.sh" and "sudo: recovery.sh", I get a "sudo: recovery.sh: command not found" message...what am I doing wrong.

using iTerm2 3.3.0 on Mojave 10.14.6.

also, I do have the "Install macOS Mojave" app in my Applications folder, but the entry in recovery.sh remains as just "Install macOS" or should I change that to "Install macOS Mojave"?

do not use a colon between the sudo and the recovery.sh
so like this
sudo ./recovery.sh

@vacarogit
Copy link

vacarogit commented Apr 8, 2020

Thanks for sharing this script. Because it references a 10.13.6 version of a Recovery HD file, I assumed it would install a 10.13.6 High Sierra recovery partition. I was surprised to discover that it actually uses whatever version of “Install macOS” .app is in your Applications folder. So in my case, my Mac Pro is running High Sierra, but I only had Install macOS Mojave.app in my Applications folder, so after running this script I ended up with a Mojave recovery partition.

If anyone else is looking specifically for a High Sierra recovery partition, and you can’t see Install macOS High Sierra in the App Store anymore, a direct link to High Sierra in the App Store is still available on this page: https://support.apple.com/en-us/HT208969 . In my case this App Store link only downloaded a small 22MB “stub” High Sierra installer which didn’t include the resources this script depends on. I gave up at that point and just used the stub installer to reinstall High Sierra and the recovery partition at the same time.

Also to note, on APFS disks the recovery partition no longer shows up in the boot menu on a Mac Pro 5,1 when you hold down the Option key while booting. APFS recovery partitions are a hidden volume within the disk’s APFS container, which isn’t listed in the boot menu like recovery partitions on HFS+ drives are. At least that’s true for my new NVMe drive. Nonetheless, booting into the recovery partition with Command+R worked great.

my Disk recovery disappeared (or you can see, shrank to only 20kb? not working anymore)
Can I use this script to recreate it? High Sierra 10.13.6 (no play to upgrade)

/dev/disk5 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +499.9 GB disk5
Physical Store disk2s2
1: APFS Volume MacOS 330.4 GB disk5s1
2: APFS Volume Preboot 19.3 MB disk5s2
3: APFS Volume Recovery 20.5 KB disk5s3 <---------
4: APFS Volume VM 1.1 GB disk5s4

@toonetown
Copy link

toonetown commented May 15, 2020

@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

jonathantneal commented Oct 10, 2021

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

@everybodies
Copy link

everybodies commented Apr 26, 2022

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

@VinneyUK
Copy link

VinneyUK commented May 21, 2022

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 :(

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