Originally, I wanted to use Casper Imaging  from the Recovery partition.  So this post is based off of this article and this feature request on JAMF Nation.  At the end, I realized I probably wouldn’t be able to add this app to the Recovery HD until JAMF updates it to 64-bit.  However, this process seems to work for other 64-bit apps.  The example I use in this walkthrough is Calculator.app.

Requirements For This Walkthrough

Materials

  1. Mac

Downloads

Knowledge, Skills, and Abilities

  • Ability and confidence to enter commands in the Terminal, adjusting them to suit your environment, if necessary
  • Familiarity with disk partitioning and mounting/un-mounting volumes
  • Ability to edit plist files
  • Knowledge of OS X file system

Resources

Warnings

  • Use a test machine for this as you will be overwriting data and possibly creating partitions
  • You will not be able to use Cmd+R to boot to your custom Recovery HD (unless you use the dmtest tool)
  • Last tested on 10.9.2

Download Install OS X Mavericks.app

  1. Download the app to ~/Desktop
  2. Right-click Install OS X Mountain Lion.app
  3. Choose Show Package Contents
  4. Copy SharedSupport/InstallESD.dmg  to ~/Desktop

Mount InstallESD.dmg to Find The Recovery HD Image

  1. Run the command defaults write com.apple.finder AppleShowAllFiles TRUE;killall Finder
  2. Double-click InstallESD.dmg  to mount it
  3. Copy BaseSystem.dmg  and BaseSystem.chunklist  to the Desktop (both are hidden files)
  4. Eject Mac OS X Install ESD

Mount BaseSystem.dmg to Make A Read/write Copy of it

  1. Double-click ~/Desktop/BaseSystem.dmg  to mount it
  2. Open Disk Utility
  3. Highlight OS X Base System
  4. Click New Image
  5. Adjust the settings as follows:
  • Save As: OS X Base System RW
  • Where: Desktop
  • Image Format: read/write
  • Encryption: none
  1. Eject Mac OS Base System
  2. Quit Disk Utility

Backup the Read/write Image

In case a mistake is made, it would be a good idea to make a copy of the read/write version of the .dmg.

  1. Right-click ~/Desktop/Mac OS X Base System RW.dmg
  2. Choose Duplicate
  3. Save it somewhere safe

Mount the Read/write Base System to Make Customizations

  1. Double-click ~/Desktop/Mac OS X Base System RW.dmg  to mount it
  2. Rename the mounted volume as Mac OS X Base System RW  so it won’t get mixed up with the original

Add Calculator.app

1. Copy over Calculator.app (or any 64-bit app) into either /Volumes/Mac OS X Base System RW/Applications  or /Volumes/Mac OS X Base System RW/Applications/Utilities

2. Copy over /System/Library/PrivateFrameworks/Calculate.framework/  from your main system into the same path inside the Base System RW disk image (I’ll explain this a bit more later).

3. If need be, you can check what architecture the app is with the Get Info dialog or running the command: lipo -info /Applciations/<app_name>/Contents/Mac\ OS/<app_name>

Modify the Utilities.plist to Have Calculator.app Show in The Utilities When Booted To the Recovery HD

One important step here is that the BundlePath  point to just the .app and the Path  points to the actual binary inside the .app.

1. Open /Volumes/Mac OS X Base System RW/System/Installation/CDIS/OS X Utilities.app/Contents/Resources/Utilities.plist  in Xcode or another plist editor

2. Duplicate one of the keys under the Buttons section

3. Expand the duplicated item

4. Edit the BundlePath  to point to /Applications/Utilities/Calculator.app

5. Edit the description to make sense

6. Edit the Path  to point to /Applications/Utilities/Calculator.app/Contents/MacOS/Calculator

7. Edit the paths for any app added in the previous step

8. Repeat the process for any other apps added in

9. Save the changes

Convert the Custom Volume Back to Read-only

During my experiments, I was never able to get a the read/write version of the disk image to restore to a partition.  I always got the resource busy error.  It seems to work fine once it is converted back to read-only.

  1. Temporarily rename /Volumes/Mac OS X Base System RW  to /Volumes/CustomRecovery
  2. Open Disk Utility
  3. Highlight the Mac OS X Base System RW.dmg (not the volume that was just renamed)
  4. Click Convert
  5. Adjust the settings as follows:
  • Save As: Custom Recovery.dmg
  • Where: Desktop
  • Image Format: read-only
  • Encryption: none

A Fork in the Road

Here you have two ways to add your recovery partition:

  • Restore using Apple’s dmtest  to retain Cmd+R functionality during boot
  • Restore using Disk Utility, where holding Option at boot will let you boot to this volume

I’ll show the dmtest way first, since that will be most useful and is also a bit easier. The Disk Utility method might be easier for cloning or capturing the volume.  This could also be used if you wanted to have the Recovery HD on a USB drive or some other location.

Method One: Restore The CustomRecovery Using dmtest

Retain Cmd+R boot keystroke to boot to the Recovery

You can download dmtest  (Lion) (Mavericks) from me, or manually extract it from the recovery update using the instructions below:

  1. Download the Lion Recovery Update V1.0 (Yosemite Recovery Update is distributed via the App Store, so if you want to be able to extract the tool from there, take a look at Saving App Store Downloads As .pkgs–which is how I got the Yosemite dmtest  tool)
  2. Run the following commands
hdiutil mount ~/Downloads/RecoveryHDUpdate.dmg
pkgutil --expand /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/RecoveryHDUpdate.pkg ~/Desktop/recoveryupdate
cp ~/Desktop/recoveryupdate/RecoveryHDUpdate.pkg/Scripts/Tools/dmtest ~/Desktop
umount /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/
sudo dmtest ensureRecoveryPartition / ~/Desktop/CustomRecovery.dmg 0 0 ~/Desktop/BaseSystem.chunklist

If you get the error

Error (async): The new recovery partition would be too large (-69668)

Then you will need to trim down the content on the .dmg (maybe by removing unneeded apps like Safari (~34MB), or Disk Utility (~21MB), Install OS X Yosemite (~8MB) etc.)

Others have mentioned that these two commands need to also be run in order to clean things up, clear the cache, and make the system recognize the new partition, but in my testing, it worked fine without doing these:

sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist 
sudo kextcache -f -u /

Method Two: Restore The CustomRecovery Using Disk Utility

Disables Cmd+R during boot, but you could restore this to any partition and boot to it.

Caution here.  This will overwrite any existing data.  Hopefully, you are using a test machine to try this.  Also, if you restore this way, the Cmd+R boot keystroke will not work, you need to hold Option to get into it.

1. Open Disk Utility

2. Highlight CustomRecovery.dmg

3. Click Images > Scan Image for Restore

4. Highlight  CustomRecovery.dmg again

5. Click the Restore tab

6. Drag an empty partition into the Destination field

7. Click Restore

8. Click Erase

9. Notice the name of the partition is now changed to CustomRecovery: a visual clue that the partition now has the CustomRecovery on it

Reboot Into the New Partition to Test it Before Moving Forward

  1. Reboot the Mac holding Option
  2. Select the Custom Recovery partition created in the previous step

Success!

Copy Over Frameworks if an App Does Not Launch in the Recovery Partition

Since the Recovery Partition is a slimmed down version of OS X, it does not have all the lower-level files needed to run some apps.  If you launch an app from Recovery and it doesn’t open, you may need to do some digging to find the frameworks needed to run it.  The steps below are how I found out what the Calculator.app needed to run.

  1. Open Terminal when booted to the Recovery partition
  2. Type /Applications/Calculator.app/Contents/MacOS/Calculator
  3. View the output to see if there are mentions of any missing frameworks
  4. Reboot back into OS X
  5. Follow the steps to edit the read/write partition but instead of adding an app, copy over the framework.  
In the case of Calculator.app, we need to copy over /System/Library/PrivateFrameworks/Calculate.framework/  See the output below from trying to run the Calculator binary
Library not loaded: /System/Library/PrivateFrameworks/Calculate.framework/Versions/A/Calculate