Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create or update macOS 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/42/58/091-94330/mm8vnigq4ulozt9iqhgcl9hp8m7iygsqbl/macOSUpd10.13.6.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"
@jscurtu

This comment has been minimized.

Copy link

commented Jan 13, 2019

Thanks for sharing this! Had no issues with it..

@peterquest

This comment has been minimized.

Copy link

commented Feb 1, 2019

At what point is it expected that this script is running? i.e. when does a system have the OS installer still available in /Applications ?

@gustavolessa23

This comment has been minimized.

Copy link

commented Mar 6, 2019

Same problem as @StevenKSanford.

@e-tip

This comment has been minimized.

Copy link

commented Mar 27, 2019

@StevenKSanford @gustavolessa23 you can copy dm util from 10.13.6 pkg and use it on mojave

@mmehrle

This comment has been minimized.

Copy link

commented Apr 6, 2019

I assume this one is not going to work for Mojave 10.14.4?

@allyouaskfor

This comment has been minimized.

Copy link

commented May 6, 2019

About to give this a shot.

@djangofan

This comment has been minimized.

Copy link

commented Jun 6, 2019

How did it go? Did it work for 10.14.5? I updated my MacPro trash-can hard drive, and i had to clone the new harddrive and i want to update the recovery partition. I'll try this myself and fork the script if it works.

@mengoreo

This comment has been minimized.

Copy link

commented Jun 22, 2019

How did it go? Did it work for 10.14.5? I updated my MacPro trash-can hard drive, and i had to clone the new harddrive and i want to update the recovery partition. I'll try this myself and fork the script if it works.

Not working for me. I'm on 10.14.5 too, after a taste of Catalina. I can't enter recovery mode since the downgrade. \sad

@daniel-toman

This comment has been minimized.

Copy link

commented Jun 25, 2019

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.

@adrienlabigne

This comment has been minimized.

Copy link

commented Jun 27, 2019

Awesome, after some try, and figure out that i haven't the installer in /Applications, this works well :)

For better understanding, you should make some errors echo. Like "You don't got any installer". "You don't have internet connexion". ;)

Thanks for you job !

@tillkrueger

This comment has been minimized.

Copy link

commented Aug 3, 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"?

@blindmanonacid

This comment has been minimized.

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.