Shared publicly  - 
 
Have a Lion Mac without a recovery partition?

Here's a method to create one, programatically. It won't be too hard to package this up, or script it.

Some background:
We've been looking for a way to create a recovery partition on systems that don't have one, e.g. using a custom image.

Initially, I spent time tearing apart OSInstall.mpkg from the 10.7.0 base install. I noticed the Distribution file for it had, along with the usual pkg-ref entries, a system-image entry. The source for this was BaseSystem.dmg, and I suspect 10.7's installer can do something with this.

Before I had success with that, though, I downloaded and expanded the RecoveryHDUpdate package.

Inside of that, there was ./RecoveryHDUpdate.pkg/Scripts/replaceRecovery, which called out ./RecoveryHDUpdate.pkg/Scripts/Tools/dmtest and references BaseSystem.dmg from inside the RecoveryHDMeta.dmg.

This is all you need to add a recovery partition. I've only tested this on a few machines at this point.


How to do it:
All commands are single lines.
Download RecoveryHDUpdate.dmg from http://support.apple.com/kb/DL1464

$ hdiutil attach RecoveryHDUpdate.dmg
$ pkgutil --expand /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/RecoveryHDUpdate.pkg /tmp/RecoveryHDUpdate
$ hdiutil attach /tmp/RecoveryHDUpdate/RecoveryHDUpdate.pkg/RecoveryHDMeta.dmg
$ /tmp/RecoveryHDUpdate/RecoveryHDUpdate.pkg/Scripts/Tools/dmtest ensureRecoveryPartition / /Volumes/Recovery\ HD\ Update/BaseSystem.dmg 0 0 /Volumes/Recovery\ HD\ Update/BaseSystem.chunklist

[... magic happens ...]

$ hdiutil eject /Volumes/Recovery\ HD\ Update
$ hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD Update

Less important:
$ sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
$ sudo kextcache -f -u /


No warranty expressed or implied.
30
21
Harald Wagener's profile photokeling da's profile photoMichael Lynn's profile photoNoah Abrahamson's profile photo
29 comments
 
For those that are following me because I work at Google, this is the sort of thing I do at work.

(If you're hoping for insight to help your SEO company, you're in the wrong place.)
 
Thanks for the cool tip Clay :)
 
I think the "system-image" in an mpkg dist-file has promise, as well, as that's not relying on mysterious binaries only found inside package installers...
 
Funny you should post this, I was just wondering how to do this...

Thanks crc!
 
We've been beating our heads on it for a while, as having a recovery partition is a requirement for FileVault 2.

(More to come on our efforts there at some point, as well.)
 
I'm just de-PGPing the 10.6 box and running the upgrader. But I don't have N-thousand boxes to cope with either :-)
 
I don't suppose you can leverage DeployStudio for your machine imaging? DeployStudio allows you to pull an image of a recovery partition, and then copy and use that .recover.dmg image alongside InstaDMG-created images to image a Mac with both the recovery and main partitions.
 
That is excellent, Clay - thanks for writing this up. I just moved us onto using Deploy Studio so that we could restore Recovery partitions. DS has plenty of other benefits, but this was the functionality we really wanted.
 
+Harald Wagener Yeah, I ran into that. I'm fixing it with puppet - if the machine is running 10.7 and has pgpwde, I run an exec to trash all the PGP crapware with extreme prejudice.
 
Looks like 10.7.2 leaves a copy of dmtest in /usr/local/bin -- how did you come to learn its syntax? — ah wait, from the install scripts. I wonder what other magic it can perform.
 
I don't have any copies of dmtest on my 10.7.2 machine, so it's not installed universally. I didn't dig into it too much; I only found the syntax above by looking in the RecoveryHDUpdate/RecoveryHDUpdate.pkg/Scripts/ - there's a "recoveryUpdate" (or something) perl script there.
 
run /usr/local/bin/dmtest for some help output. If you want to see more stuff to dig, run 'strings /usr/local/bin/dmtest'
 
Copy of the strings for others:

dmtest - DiskManagement tester and Apple-internal utilities

Usage: dmtest ensureRecoveryPartition <DiskSlice> <PathToDMG> <0|1> <0|1> <pathToChunkList>

This command shrinks the given volume-bearing slice and creates a new partition and volume in the freed space. It them copies files to make that new partition an ImageBoot-bootable Mac OS X system.

The given disk must be a volume-bearing slice-disk; the path must be to a bootable Mac OS X disk image (.dmg) file; the last two parameters are boolean for VerifyDiskImage and RepairNotJustVerifyBeforeShrinking, respectively.

For pathToChunkList, provide a path to a BaseSystem.chunklist file

So in Clay's example he has 0 and 0 which basically says: Don't verify the BaseSystem.dmg and only verify the main boot volume prior to shrink (don't repair it if verification fails).
 
Thanks for this! A few notes:

$ hdiutil eject /Volumes/Mac OS X Lion Recovery HD Update
...needs escaping as:
$ hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update

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

Hope that helps. Feel free to delete this comment if you edit these into the post above.
 
thanks for the tip !
I'm having a problem, though, when trying to do the magic :
Creating recovery partition: finished
Error (async): A partition, not a whole disk, is required for this operation (-69802)
Any ideas why ?
 
Sounds like the command is typed in wrongly. It's better to not type it in or cut and paste, but rather use terminal and TAB to autocomplete for your setup.
 
I finally had other problems, and I reinstalled the whole thing. I now own a shiny new recovery partition \o/
 
Hadn't come across that one, I know it seems odd to feed the command a disk partition name when really it is going to act on the disk but that's how it seems to operate. Disk Utility's partition wizardry sometimes hits a wall it seems. Glad you were able to nuke it and start fresh (as "Windows" as that seems :)
 
Hi Clay Caviness
Thank You So much for your information, its work for us, now we can deploy the lion image to macbook pro 2012 retina model thank you
 
Thank you... worked flawlessly for me just now on 10.7.4 after a Time Machine restore of OS X to new HDD did not recreate the Recovery partition. 
 
Cool stuff, Clay...but why wouldn't a Lion computer have a recovery partition? When I use DeployStudio it automatically makes one.
 
Oh, I guess via upgrading, it's sometimes not created...
How's life?
 
Time Machine recovery to a blank/reformatted harddrive doesn't recreate a recovery partition in 10.7

Sent from my iPhone
Add a comment...