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"
@xarbit

This comment has been minimized.

Copy link

@xarbit xarbit commented Jan 13, 2019

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

@peterquest

This comment has been minimized.

Copy link

@peterquest peterquest 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

@gustavolessa23 gustavolessa23 commented Mar 6, 2019

Same problem as @StevenKSanford.

@e-tip

This comment has been minimized.

Copy link

@e-tip e-tip 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

@mmehrle mmehrle 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

@allyouaskfor allyouaskfor commented May 6, 2019

About to give this a shot.

@djangofan

This comment has been minimized.

Copy link

@djangofan djangofan 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

@mengoreo mengoreo 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

@daniel-toman daniel-toman 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

@adrienlabigne adrienlabigne 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

@tillkrueger tillkrueger 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

@blindmanonacid 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

This comment has been minimized.

Copy link

@danielshenry 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

This comment has been minimized.

Copy link

@vacarogit 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

This comment has been minimized.

Copy link

@toonetown toonetown commented May 15, 2020

@aonez

This comment has been minimized.

Copy link

@aonez 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 this one in my Mac mini internal disk 🤷🏻‍♂️

@au10tic

This comment has been minimized.

Copy link

@au10tic 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

This comment has been minimized.

Copy link

@aonez 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

This comment has been minimized.

Copy link

@au10tic 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

This comment has been minimized.

Copy link

@aonez aonez commented Jun 6, 2020

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

TARGET="CataRecovery"

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

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.