Remove Recovery HD

martin
Contributor III
Contributor III

Hi,

I wrote this script to remove the Recovery HD and add the space to the Macintosh HD volume. Maybe you'll find this usefull.

---
#!/bin/sh

diskutil list > /tmp/diskutil

while read line
do
# Find the Mac OS X 10.7 Recovery HD volume and erase
if `echo ${line} | grep "Recovery HD" 1>/dev/null 2>&1`; then
recovery_hd=echo "${line}" | awk '{ print $7 }'
diskutil eraseVolume HFS+ Blank /dev/${recovery_hd}
# Find the Macintosh HD volume and merge with erased Recovery HD volume
if `echo ${line} | grep "Macintosh HD" 1>/dev/null 2>&1`; then
macintosh_hd=echo "${line}" | awk '{ print $7 }'
diskutil mergePartitions HFS+ "Macintosh HD" ${macintosh_hd} ${recovery_hd}
fi
fi
done < /tmp/diskutil
---

Kind Regards,

Martin van Diemen

t +31 (0)205677744


G-Star Raw C.V.
www.g-star.com

4 REPLIES 4

zmbarker
Contributor

I was never able to get your script working properly.

When I ran the script this portion worked properly.
# Find the Mac OS X 10.7 Recovery HD volume and erase
if `echo ${line} | grep "Recovery HD" 1>/dev/null 2>&1`; then
recovery_hd=echo "${line}" | awk '{ print $7 }'
diskutil eraseVolume HFS+ Blank /dev/${recovery_hd}

but this portion did not work properly.
# Find the Macintosh HD volume and merge with erased Recovery HD volume
if `echo ${line} | grep "Macintosh HD" 1>/dev/null 2>&1`; then
macintosh_hd=echo "${line}" | awk '{ print $7 }'
diskutil mergePartitions HFS+ "Macintosh HD" ${macintosh_hd} ${recovery_hd}

My end result was a Blank HD on my desktop, and I could not merge them together.
-----

So with help from Jared Nichols, we ended up writing a new script which works properly.

--
#!/bin/sh

#Find the boot partition and recovery partition
bootPart=sudo diskutil list /dev/disk0 | grep Apple_HFS | rev | cut -d " " -f 1 | rev
recoveryPart=sudo diskutil list /dev/disk0 | grep Apple_Boot | rev | cut -d " " -f 1 | rev

#bombs away!
sudo diskutil mergePartitions jhfs+ "Macintosh HD" $bootPart $recoveryPart
--

mvught
Contributor

Small change:

#!/bin/sh

#Find the boot partition and recovery partition
bootPart=$(diskutil list "Macintosh HD" | grep Apple_HFS | rev | cut -d " " -f 1 | rev)
recoveryPart=$(diskutil list "Recovery HD" | grep Apple_Boot | rev | cut -d " " -f 1 | rev)

#This will merge the two partitions, with Apple_HFS absorbing the space from Recovery HD and expanding, it causes no data loss on the Apple_HFS disk.
sudo diskutil mergePartitions JHFS+ "Macintosh HD" $bootPart $recoveryPart

Really would like your help with this.  I'm trying to restore my MacBook after replacing the battery.  (MacBook 2012, OSX 10.8.5). "I'm getting the message OSX can't be installed because a recovery system can't be created" I would be very grateful if you can help me.  I will try to attach my diskutil list.  Thank you.

IMG_3297.jpg