Automated: Removal of the Apple Recovery Partition

themacdweeb
Contributor

Before anyone starts to throw beer bottles at me because I'm recommending that you should remove your hidden recovery partition, let me be clear:

I'm not recommending anything. You're a sysadmin and you know what's best for your Macs. And, if you have cause to remove that partition and would like an effortless way to do it, you can use the following script to automate the process one one or more machines.

WARNING: pushing this via policy, ARD, or running it locally only works when there's only one Recovery partition on your HD. If you have multiple drives or multiple partitions and have install instances of OSX 10.7 or 10.8 spread around, this won't work. I suppose I'll be updating the script over time to make use of an array but, for now: it is what it is.

For the record, I made this tool because I've been testing the deployment of the Recovery partition on it's own and needed an effective way to delete the one I already had on my machine.

Boo-ya.

#!/bin/sh

# This script automatically:
#    finds the recovery partition installed by Apple
#    sets variables to identify it and the parent partition above it
#    erase the recovery partition
#    merge the partition up into its parent

# Last update June 11th, 2013

# Free to use and share
# Just include these lines of code. Copyright© David Koff, 2013

#----------------------------------------------------------
#   Variables
#----------------------------------------------------------

#-----Assignments
SCRIPTNAME=$0

#-----Logging 
# use WHATEVER log file suits you best. this is ours.
exec >> "/Library/Logs/Getty Installations.log" 2>&1  ## must be run as admin or root for exec to work

#-----Computations
# establish the drive pattern for the disk(s) in question
DevRoot=`diskutil list | grep Recovery | cut -c 69-74`

# isolate the last digit of that partition ID
DevID=`diskutil list | grep Recovery | cut -c 75`

# set the variable which contains the FULL drive ID of the recovery partition
recoveryPart="$DevRoot$DevID"
echo "The recovery partition we're erasing is: $recoveryPart"

# we know the main partition is one digit LESS on the chain
let mergeID=DevID-1

# set the variable for the drive partition into which we'd like to merge
mergePart="$DevRoot$mergeID"
echo "The partition into which we're merging is: $mergePart"

# find the NAME of the merge partition by setting variable
mergeName=`diskutil list | grep $mergePart | cut -c 34-57`
echo "The name of the merge partition is: $mergeName"

#----------------------------------------------------------
#  Timestamp
#----------------------------------------------------------
echo "                                   "
echo "###################################"
echo "##### $SCRIPTNAME"
echo "##### `date "+%A %m/%d/%Y %H:%M"`"
echo "###################################"
echo "                                   "

#----------------------------------------------------------
#  Script
#----------------------------------------------------------
echo "The Following Recovery Partition(s) has been found:"
echo $recoveryPart
echo ""

diskutil eraseVolume HFS+ Blank $recoveryPart
echo ""

echo "Now merging the space from $recoveryPart into $mergePart"
diskutil mergePartitions HFS+ $mergeName $mergePart $recoveryPart
echo ""

echo "Merging is complete. Recovery Partition has been removed."

#----------------------------------------------------------
#  Timestamp
#----------------------------------------------------------
echo "                                   "
echo "###################################"
echo "##### End Log"
echo "##### `date "+%A %m/%d/%Y %H:%M"`"
echo "###################################"
echo "                                   "

exit 0
6 REPLIES 6

armando
New Contributor III

i'm interested in how you are testing the deployment of the Recovery partition on it's own.

Thanks

Jpcorzo
Contributor

+1 to armando's question

Thanks

gregneagle
Valued Contributor

Perhaps using a method like this: http://managingosx.wordpress.com/2012/08/15/creating-recovery-partitions/

themacdweeb
Contributor

neagle: always improving everything, sheeeeesh! i didn't even know you'd worked your magic on this task, dude. because of that, this time i took my cue from the also venerable rich trouton:

http://derflounder.wordpress.com/2012/06/26/creating-an-updated-recovery-hd/

that approach requires, admittedly, a few more step's than greg's approach:

1) getting lion's recovery update tool here: http://support.apple.com/kb/DL1464
2) getting a script from joel bruner here: http://www.brunerd.com/blog/wp-content/uploads/createRecoveryHDUpdater.command.zip
3) creating a recovery DMG
4) downloading the package software iceberg: http://s.sudre.free.fr/Software/files/Iceberg.dmg
5) transferring files from the created recovery DMG into iceberg
6) writing a one line post-install shell script to make it nice-nice.

and it works. i've begun deploying the pkg that i generate using this approach in casper imaging. however, regardless of what approach you use, PLEASE NOTE: you can't add this pkg into the main build -- it need to be installed on first boot or it won't work.

that being said, i'm looking forward to trying out neagle's tool and reporting back. thank you, uncle greg.... :)

just as an FYI to those looking to do the same, here's a list of the sites i researched/tested, not knowing about greg's approach:

clay caviness:
https://plus.google.com/109088229817689076273/posts/CDTUmQUiBV9

joel bruner:
http://www.brunerd.com/blog/2012/03/21/update-create-lion-recoveryhd-partition-quickly-without-reins...

alan golbig:
http://www.afp548.com/2012/08/15/creating-a-10-8-recovery-hd-package-with-luggage/

themacdweeb
Contributor

thus far - no contest: greg's tool is - by far - the easiest to use in my travels:
http://managingosx.wordpress.com/2012/08/15/creating-recovery-partitions/

once set up, the thing takes maybe a minute to run. which is way, way better than my previous methods and i've further automated the process by writing a script and setting variables for the location of the core files that you'll need (an OSX Installer, the Lion Recovery Tools upgrade and greg's pkg template.

the resulting file should be deployable (haven't yet tested) via casper IF installed at firstboot and not as part of the initial casper configuration build.

#!/bin/sh

# This script auto-builds a macintosh recovery partition installer based on
# Greg Neagle's http://managingosx.wordpress.com/2012/08/15/creating-recovery-partitions/


#----------------------------------------------------------
#   Variables
#----------------------------------------------------------

#-----Assignments
SCRIPTNAME=$0

#-----Logging
exec >> "/path/to/your/favorite/logfile" 2>&1  ## must be run as admin or root for exec to work

#-----Folders & Files (use your own locations, of course: these are mine)
RecUpd="/CreateRecoveryPartition/RecoveryHDUpdate.pkg"
CreatePart="/CreateRecoveryPartition/CreateRecoveryPartition.pkg"
InstallESD="/Applications/Install OS X Mountain Lion.app/Contents/SharedSupport/InstallESD.dmg"

#----------------------------------------------------------
#  Timestamp
#----------------------------------------------------------
echo "                                   "
echo "###################################"
echo "##### $SCRIPTNAME"
echo "##### `date "+%A %m/%d/%Y %H:%M"`"
echo "###################################"
echo "                                   "

pkgutil --expand $RecUpd ./RecoveryUpdate
cd ./RecoveryUpdate/RecoveryHDUpdate.pkg/Scripts/Tools/
cp dmtest $CreatePart/Contents/Resources/


hdiutil attach "$InstallESD" -noverify
cp /Volumes/Mac OS X Install ESD/BaseSystem.* $CreatePart/Contents/Resources/
hdiutil eject /Volumes/Mac OS X Install ESD/

echo "                                   "
echo "Recovery Partition Installer has been created and is now available at:"
echo "$CreatePart"
echo "                                   "

#----------------------------------------------------------
#  Timestamp
#----------------------------------------------------------
echo "                                   "
echo "###################################"
echo "##### End Log"
echo "##### `date "+%A %m/%d/%Y %H:%M"`"
echo "###################################"
echo "                                   "

exit 0

gregneagle
Valued Contributor

If you like what I've done with the process, you'll love this:

https://github.com/MagerValp/Create-Recovery-Partition-Installer