Recreate macOS' HD Recovery Partition
A number of scenarios can cause the Mac to "lose" it's recovery partition. However, the recovery partition (Recovery HD) is required for a number of tasks. For instance, to disable SIP (System Protection Integrity) in El Capitan and newer OSes, or to recovery from serious partition errors you need this partition.
This is an ADVANCED tutorial, and should NOT be used by beginners! Read the entire tutorial BEFORE you start!
It contains the tool that will be used to create the partition.
Install OS X El Capitan.app or Install OS X Yosemite.app or other installation app. (download from AppStore). This contains the image of the partition to be created. (Lion or newer).
Use the correct install app, the same of your system's version.
We will be using the sudo command. If your user does not have a password create one before you start.
Backup of all HDD data (all partitions).
All your data may be wiped if something goes wrong, the whole disk! Better safe than sorry. Backup!
First things first. First we need to see how the hard drive is partitioned. Chances are that you already know how the disk is partitioned.
Open Terminal.app and type:
The first column (#) indicates the partition number, the second column (TYPE) is the type of the file system, the third column (NAME) is the volume name, the fourth column (SIZE) is the size of the partition, and finally the fifth column (IDENTIFIER) is the node identifier of the partition.
The partition number 2 here is a Apple_HFS partition type with name El Capitan. Right after this OS X partition we should have a hidden partition called Recovery HD.
The solution to recreate the Recovery HD partition is to shrink the end of the OS X partition by 650 MB, and in the empty space left create a recovery partition.
The process is automated and there is no need to resize the OS X partition or re-create the Recovery HD manually. We will only need the requirements above.
Setting Up To Recreate Recovery
Place the RecoveryHDUpdate.dmg and the OS X install app on the Desktop and open the Terminal.app.
Mount the RecoveryHDUpdate.dmg. It contains the tool that we will be using to recreate the partition:
hdiutil attach -nobrowse ~/Desktop/RecoveryHDUpdate.dmg
Extract the contents of RecoveryHDUpdate.pkg that contains the tool:
pkgutil --expand /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/RecoveryHDUpdate.pkg /tmp/RecoveryHDUpdate
This creates a new directory within /tmp called RecoveryHDUpdate. And inside this directory the tool that will be used. Our tool setup is ready!
Now do this:
(A) Locate on your Desktop the OS X installer (Install OS X El Capitan.app or Install OS X Yosemite.app, or other)
(B) Right click it and choose Show Package Contents
(C) Navigate to Contents/SharedSupport folder
(D) Copy the file InstallESD.dmg to your Desktop
Mount the OS X installation image using the Terminal! Type in:
hdiutil attach -nobrowse ~/Desktop/InstallESD.dmg
Recreating The HD Recovery Partition
Everything ready! Now let's run the command to create the Recovery HD partition.
BE PATIENT and wait for the command to complete its execution. It may take a while, DO NOT close the terminal and DO NOT interrupt the program!!!
To avoid typos, simply copy and paste the command in the terminal.
sudo /tmp/RecoveryHDUpdate/RecoveryHDUpdate.pkg/Scripts/Tools/dmtest ensureRecoveryPartition / /Volumes/OS\ X\ Install\ ESD/BaseSystem.dmg 0 0 /Volumes/OS\ X\ Install\ ESD/BaseSystem.chunklist
When the command above finishes the new partition will be ready. A kext caches update is needed.
To update the kexts run the following commands:
sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist sudo kextcache -f -u /
Cleaning what was left behind. First delete the folder in /tmp:
sudo rm -rf /tmp/RecoveryHDUpdate
And finally unmount the two images that were previously mounted:
hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update hdiutil eject /Volumes/OS\ X\ Install\ ESD/
By pressing CMD + R the Mac will boot-up the Recovery partition.
If you do not have the OS Install application (it is automatically deleted after the update) you can get it from the AppStore. Open the AppStore and click on Purchased and search for it in the list. Click Install, the App will be re-downloaded to the Applications folder.
Remember, you are creating a new partition after the OS X partition. If there are already other partitions after OS X partition these will have their numbers and nodes changed. In the above example, the Windows partition number 3 on the node disk0s3 was turned into partition number 4 on the node disk0s4. And the Linux partitions number 4 node disk0s4 turned into number 5 node disk0s5.