macOS

Recreate 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!

Requirements

  1. RecoveryHDUpdate.dmg

    It contains the tool that will be used to create the partition.

  2. 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 same version of the install app your system is currently using!

  3. We will be using the sudo command. If your user does not have a password create one before you start.

  4. 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!

Disk Examination

First things first. Before we start 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:

diskutil list

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 650MB, 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.

diskutil list

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 Up

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/

Expected Results

diskutil list

When you start your Mac pressing CMD + R it will boot-up the Recovery partition.

Final Thoughts

  • 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.


DO NOT FORGET TO BACKUP BEFORE YOU START!

 

© 2019 Mteam7 Network. All rights reserved.