Removing and rebuilding a malfunctioning Recovery HD partition
When updating to 10.7.2, there’s a Lion Recovery Update that goes along with it. This is meant to update your Recover HD recovery partition to 10.7.2 along with your Mac. However, when I tried updating, I could see from the logs that for whatever reason, my Recovery HD was staying at 10.7.1 and was not being successfully updated. As the new Find My Mac functionality in iCloud relies on Recovery HD being updated to 10.7.2, I wanted to be able to fix this problem without having to reinstall or reimage my Mac. Fortunately, thanks to the work of Clay Caviness at Google, there’s a way to rebuild your recovery partition (at least for 10.7.2) on a Mac that doesn’t have one. I did have one, but I knew how to fix that. See below the jump for the procedure.
Note: All commands shown are single lines.
Step One: Make a full backup of your boot drive.
This is absolutely the most important step of this process. Any time you’re moving partitions around, stuff can go wrong. Making a backup beforehand can turn a later “Something went wrong” moment from a crisis into a less-bad inconvenience.
Step Two: Remove the existing Recovery HD recovery partition
1. Get the disk identifier of your recovery partition by running the following command:
diskutil list
2. Once you’ve identified the entry, then remove it by running the following command. (In this case, I’ll be using disk0s4 for the recovery partition and disk0s3 for the main boot partition.):
diskutil eraseVolume HFS+ ErasedDisk /dev/disk0s4
3. Next, merge the recovery and boot partitions together to create one partition (the MacHD identifier is to give the partition a new name; your existing boot drive name shouldn’t be changed by this process):
diskutil mergePartitions HFS+ MacHD disk0s3 disk0s4
Step Three: Rebuilding the recovery partition:
1. Download the Lion Recovery Update from http://support.apple.com/kb/DL1464
2. Run the following commands to attach the correct disk image and rebuild the recovery partition:
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
At this point, you will see a large amount of code fly by as the recovery partition is rebuilt. It should end with Creating recovery partition: finished
The next set of commands is clean-up and making the system recognize the updated recovery partition.
hdiutil eject /Volumes/Recovery\ HD\ Update
hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update
sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
sudo kextcache -f -u /
Once finished, restart your Mac and verify that you can boot to Recovery HD. To verify that your Recovery HD is now on 10.7.2, open the Terminal (available from the Utilities menu when booted from the Recovery HD partition,) and run the following command:
sw_vers
The following information should be displayed:
ProductName: Mac OS X
ProductVersion: 10.7.2
BuildVersion: 11C74
Very cool, great work! You can also mount the Recovery HD volume and then grep for “ProductVersion” in the SystemVersion.plist file:
diskutil mount disk0s3
grep -A1 -i “ProductVersion” /Volumes/Recovery\ HD/com.apple.recovery.boot/SystemVersion.plist
You may want to modify this line: “hdiutil eject /Volumes/Mac OS X Lion Recovery HD Update” to “hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update”
This made for a great postsetup installation of the recovery partition. Thanks
Fixed. Thanks for the catch!
Here is an example of how this can be used in a postsetup for those that may be interested – deploying Lion without the recovery partition and having this script generate it.
#!/bin/bash
# Check for RecoveryHDUpdate and download if missing
if [ -e "RecoveryHDUpdate.dmg" ]; then
echo “A local copy of RecoveryHDUpdate.dmg will be used”
else
echo “Downloading RecoveryHDUpdate.dmg from Apple”
curl -L -O http://support.apple.com/downloads/DL1464/en_US/RecoveryHDUpdate.dmg
fi
# Mount
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
# Clean-up
hdiutil eject /Volumes/Recovery\ HD\ Update
hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update
sleep 10
rm RecoveryHDUpdate.dmg
sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
sudo kextcache -f -u /
Thanks, Dennis! This script looks very useful for folks who need to image, but aren’t sure how to handle creating the Recovery HD partition.
The script above is somewhat faulty, possibly due to formatting:
* The 4th & 6th lines (beginning with ‘echo…’) should have similar quotes than the 3rd line (beginning with ‘if [...')
* The 11th line (beginning with 'pkutil...') should have 2 dashes before expand, not a mdash.
(I have tried to correct the lines below, but if they still are not correct, blame wordpress)
#!/bin/bash
# Check for RecoveryHDUpdate and download if missing
if [ -e "RecoveryHDUpdate.dmg" ]; then
echo “A local copy of RecoveryHDUpdate.dmg will be used”
else
echo “Downloading RecoveryHDUpdate.dmg from Apple”
curl -L -O http://support.apple.com/downloads/DL1464/en_US/RecoveryHDUpdate.dmg
fi
# Mount
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
# Clean-up
hdiutil eject /Volumes/Recovery\ HD\ Update
hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update
sleep 10
rm RecoveryHDUpdate.dmg
sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
sudo kextcache -f -u /
Hmm, I have a BootCamp partition on my disk. I replaced the HD in my MB Pro after installing Lion and had restored the recovery partition to an external drive. That’s bootable, but I did it to a huge partition which was clearly a bad idea. Now I can’t restore it to a smaller partition.
So I only have 3 primary partitions on disk — Macintosh HD, the EFI partition and the BOOTCAMP partiton. I haven’t futzed with the partition scheme since BootCamp was done.
I’d be very hesitant to create a recovery partition with this setup, but I don’t really know what would happen. As far as you can tell, does the dmtest script resize MacintoshHD, create a new recovery partition, and then fill it?
It’d also be nice to be able to create a new recovery partition on a USB stick, but I haven’t had any luck doing that so far.
Brian,
Honestly, since you have the BootCamp partition in play as well, I’m not sure what would happen if you used this method to reinstall a Recovery HD partition. What I’d advise is to back up the BootCamp Windows install* and remove the Windows partition before trying to reinstall the recovery partition.
*I have another post on how to back up a BootCamp Windows 7 install available here:
http://derflounder.wordpress.com/2011/05/26/backing-up-a-windows-7-boot-camp-installation-and-restoring-it-to-a-smaller-partition/
Great, thanks.
Thank you so much. Nice work.
It worked like a champ for me!!!!! My Lion Recovery Partition version was 10.7, not even 10.7.1. Nothing else worked for me. I’ve tried a lot of suggestions … and I’ve lost a full working morning before finding this GREAT post.
I suggest to change disk0s3 and disk0s4 in the script for disk0s2 (Macintosh HD) and disk0s3 (Recovery HD), because this configuration is the standard for many who do standard Lion install with only one (visible) partition for Lion.
THANK YOU VERY MUCH!!!!!
Great. Thanks for the catch!
Hello, I’m a starter on that… but the first line to rebuild the recovery partition, it hasnt worked for me.
I mean that line:
hdiutil attach RecoveryHDUpdate.dmg
….
I’m sure, i’m doing something wrong…! but it says:
hdiutil: attach failed – No existe este archivo o directorio
(i have an spanish version of lion, but it says that the image file can’t be found..!)
What should i do?
Thank you
Toni,
If you’ve downloaded the update, try moving the file from your Downloads folder to the top level of your account’s home folder. Once the file has been moved, run the command again and see if it works.
When you open a new Terminal window, the initial directory it uses by default is the top level of your home folder.
After opening Terminal, you can use the “cd” command to move Terminal’s focus to the, for instance, Downloads folder. You could type, “cd Downloads” to move Terminal’s focus to the Downloads Directory in your Home folder. You can tell where Terminal’s focus is by the text that precedes your User name before you type any commands. Mine looks like this when I’ve typed in “cd Movies”: “MyComputer:Movies Mike$” Notice the word, “Movies” before “Mike$”? This would look like, “MyComputer:Downloads Mike$” if Terminal’s focus was in the Downloads directory. Then you run the script and Terminal can find the .dmg cause Terminal’s focus is in the Downloads directory where the actual dmg file you need to open resides, in this case the Lion Recovery Update dmg.
Oh! Thank you rtrouton!
I’ve get it with the script from dennis mueller!
Thank you a lot!
You guys are awesome! 
Congrats!
Just wanted to say thanks, I accidentally deleted my Recovery HD partition and your post helped me out A LOT!
You are the best, after months and months I found what I needed!
Thank you VERY much!!!
Credits go out to you, of course.
https://discussions.apple.com/message/17443876#17443876
Excellent write up! Now I can use Filevault. Many thanks.
Thx! I had lost Recovery partition after reinstalling from TimeMachine backup, and Filevault 2 will not work without Recovery HD… I first attempted to follow this (very good) how to:
http://www.dmitry-dulepov.com/2011/09/mac-recovery-partion-revisited.html
But since I did not have a USB install with an existing Recovery HD, your solution with using the Apple update worked best in my case.
Excellent how-to.
This really helped! OS X Mountain Lion DP1 has a broken Recovery HD for me as well. I can view it after holding Option, and/or holding Command + R, but it just goes to the Apple boot screen with the spinning gear for ages — never actually enters into the Recovery HD partition
Great information, worked a treat!
I bought an SSD and cloned my current HDD. Unfortunately, the recovery partition was now missing. This tutorial fixed my problem. Thank you very much!
Used Super Duper to clone to a new drive and lost the recover partition, you saved the day. Thanks!
Hi. Get all the way through the install but final code input results in a request for a password.
It is not,however, possible to put in any text via the keyboard?!!!
Help…..
Regards Martin J
Sorted this. Did a verify on the drive and found some minor corruptions. Used the Apple Internet recovery facility. This allowed me to repair the drive. Re-ran the code above and all worked! New recovery partition in place. Thanks for a brilliant bit of coding! Regards Martin J
Awesome, thanks very much for this. Worked perfectly.
Thanks very much – this worked great. I had installed Lion on a new SSD drive in my older MacBook which I use for work – for some reason it failed to install a recovery partition. My company is OK with using a personal Mac — but they want it encrypted – and they are beginning to use BigFix/TEM to ensure compliance. This will allow me to use FV2 and become complaint. Thanks again!
This worked perfectly for me. I had a Lion partition and a BootCamp partition on my hard drive, but after creating another partition for Snow Leopard, I lost my Recovery HD. Shortly after that, my Lion partition got corrupted, and I called Apple to help. The guy helping me said I had to buy an external hard drive and back up everything using Time Machine, then reinstall everything again, so I bought a Time Capsule and did that. When I was trying to repartition my drive for Snow Leopard and BootCamp, Mac OS X deleted my recovery HD again! I did a google search and came across this page, and everything worked perfectly. I now have 5 partitions: the EFI partition, Mac OS X Lion, Recovery HD, Mac OS X Snow Leopard, and BootCamp.
tried this on 2 seperate drives that were created with superduper,
getting the spinning wheel of doom once i reboot and get to the login screen.
then it crashes and forces a reboot, however the recovery partition is intact.
Note, if you see any errors before or after “Creating recovery partition: finished”, and your partition isn’t being created, you need to reboot into internet recovery mode (Command+R), and run Repair Disk in Disk Utility.
GREAT WORK EVER for this process…
Thank You very much, it helps best and saves days
Worked like a charm. THANKS! Consider updating your instructions for those who don’t understand what is meant by “the main boot partition”. Personally, since I don’t know Mac partitioning and formats I was unable to determine which disk/partition I was suppose to use in the command for merging. There are a couple small disks/partitions that could be mistaken as the boot partitions. Likely some error would occur if you tired to merge them with the erased Recovery disk/partition but it is best to be as clear as possible with these types of instructions since people may get lost or screw themselves out of their data. Even though you say to backup, people don’t. For mine there were 0-4 (Five total) disks/partitions. I have Lion installed with Bootcamp for Windows 7.
0 (disk0) – was listed as a 251.0 GB Type”GUID_partition_scheme”
1 (disk0s1) – was 209.7 MB Type”EFI”
2 (disk0s2) was 124.9 GB Type”Apple_HFS” Name”Macintosh HD”
3 (disk0s3) – was 650.0 MB Type”Apple_Boot” Name”Recovery HD”
4 (disk0s4) – was 125.3 GB Type”Microsoft Basic Data” Name”BOOTCAMP”.
Notice that the total size of disk/partition 2+4 equals disk/partition 0. Also, keep in mind that disk 2 & 4 which are the primary Mac OS and primary Windows Bootcamp partitions can be any size. Mine are close to equal because I split the 256 GB HDD equally in two partitions when I installed MAC OSX and Bootcamp.
In short: choose the disk which has the type “Apple_HFS” and or name “Macintosh HD” that is large in size relative to the other partitions, when you are determining which drive/partition to use for the merge. The type or name may be different on your system but “the main boot partition” should be one of the larges ones and should be in GB not MB. Verbose, I know, but I hope this helps someone.