Skip to content

Instantly share code, notes, and snippets.

@MiqViq
Created August 5, 2016 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiqViq/645c0d70022f0df9bb0f241a25e15707 to your computer and use it in GitHub Desktop.
Save MiqViq/645c0d70022f0df9bb0f241a25e15707 to your computer and use it in GitHub Desktop.
Tries to find the first internal Recovery HD and set the computer to boot from it on the next boot
#!/bin/bash
#
# set_boot_recovery_hd.sh
#
# tries to find the first internal Recovery HD and set the computer to boot from it on the next boot
#
#
# actions
listRecoveryHDs=$(diskutil list | grep 'Apple_Boot Recovery HD' | awk '{print $NF}')
if [ "$listRecoveryHDs" == "" ]
then
echo "ERROR: No Recovery HD partitions available."
exit 1
fi
IFS=$'\n'
for recoPart in $listRecoveryHDs
do
if diskutil info "$recoPart" | grep -woq 'Internal'
then
/usr/sbin/bless --device /dev/$recoPart --setBoot --nextonly && \
echo "Set computer to boot from internal Recovery HD /dev/$recoPart"
exit 0
fi
done
echo "ERROR: No INTERNAL Recovery HD partitions available."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment