Since Deploy Studio requires that you have a pre-built Recovery HD to restore, it can be time consuming to build and capture these images. Some admins have taken a packaging approach to creating Recovery HD partitions, which is great for a wide number of deployment tools – or – use the thin-imaging or no-imaging technique where Apple’s own installer handles the magic behind the scenes. But for now let’s just say you use Deploy Studio to restore your base image and need a quick and flexible way to automatically restore the Recovery HD at the same time…

Step 1 – Gather

You’ll need to grab a couple of items, the first being the `dmtest` utility included in the RecoveryHDUpdate.pkg – http://support.apple.com/kb/DL1464

Download, mount and expand the package (see below) and grab a copy of dmtest from within the expanded package RecoveryHDUpdate.pkg/Scripts/Tools/dmtest.

pkgutil --expand /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/RecoveryHDUpdate.pkg ~/Desktop/RecoveryHDUpdate

Second, you’ll need the latest InstallESD.dmg for each Recovery HD you want to build. (You already know about this, right? )

Mount your InstallESD and grab BaseSystem.dmg and BaseSystem.chunklist from the root of the disk. We will need these files in the next step.

Root of InstallESD Disk Showing Hidden Base System Files

Step 2 – Prepare

Screenshot of directory structure of Deploy Studio including "Tools"

Create another directory in Deploy Studio’s repository called Tools. Under the new Tools directory copy in the dmtest utility and create sub-directories for the BaseSystem files for each InstallESD. Name the sub-directories so you can easily reference the specific BaseSystem files such as “L” for the latest Lion or “ML” etc.

Now, create a new script in Deploy Studio as shown below called ensureRecoveryPartition.sh

(credit to Clay Caviness)

#!/bin/sh

## EXAMPLE: /tmp/dmtest ensureRecoveryPartition / /Volumes/Recovery\ HD/com.apple.recovery.boot/BaseSystem.dmg 0 0 /Volumes/Recovery\ HD/com.apple.recovery.boot/BaseSystem.chunklist

${DS_REPOSITORY_PATH}/Tools/dmtest ensureRecoveryPartition ${DS_LAST_RESTORED_DEVICE} ${DS_REPOSITORY_PATH}/Tools/$1/BaseSystem.dmg 0 0 ${DS_REPOSITORY_PATH}/Tools/$1/BaseSystem.chunklist

exit 0

Step 3 – Test & Maintenance

Screenshot of Deploy Studio Script Action

Add the script task to your workflow after the imaging task and make sure it’s not set for postponed execution. In the script parameters box enter the subdirectory of your BaseSystem files. Now, run the workflow and watch the client log. When it’s finished you should find a freshly created Recovery HD. When Apple releases each minor OS revision replace the BaseSystem.dmg and BaseSystem.chunklist files as needed and for hardware specific OS builds  just drop the new BaseSystem files into a new sub-directory and reference via the workflow.