Advertisement
Guest User

Untitled

a guest
May 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Mac OS X script to locate and mount an EFI System Partition (ESP)
  4. #
  5. # Usage:
  6. #
  7. # ./mountesp
  8. #
  9. # This program is copyright (c) 2015 by Roderick W. Smith
  10. #
  11. # This program is licensed under the terms of the GNU GPL, version 3,
  12. # or (at your option) any later version.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. #
  16. # Revision history:
  17. #
  18. # 0.9.3 -- Initial release (with rEFInd 0.9.3)
  19.  
  20. # Mount the ESP at /Volumes/ESP or determine its current mount
  21. # point.
  22. MountOSXESP() {
  23. # Identify the ESP. Note: This returns the FIRST ESP found;
  24. # if the system has multiple disks, this could be wrong!
  25. Temp=$(mount | sed -n -E "/^(\/dev\/disk[0-9]+s[0-9]+) on \/ \(.*$/s//\1/p")
  26. if [ $Temp ]; then
  27. Temp=$(diskutil list | grep " EFI " | grep -o 'disk.*' | head -n 1)
  28. if [ -z $Temp ]; then
  29. echo "Warning: root device doesn't have an EFI partition"
  30. fi
  31. else
  32. echo "Warning: root device could not be found"
  33. fi
  34. if [ -z $Temp ]; then
  35. Temp=$(diskutil list | sed -n -E '/^ *[0-9]+:[ ]+EFI EFI[ ]+[0-9.]+ [A-Z]+[ ]+(disk[0-9]+s[0-9]+)$/ { s//\1/p
  36. q
  37. }' )
  38.  
  39. if [ -z $Temp ]; then
  40. echo "Could not find an EFI partition. Aborting!"
  41. exit 1
  42. fi
  43. fi
  44. Esp=/dev/`echo $Temp`
  45. echo "The ESP has been identified as $Esp; attempting to mount it...."
  46. # If the ESP is mounted, use its current mount point....
  47. Temp=`df -P | grep "$Esp "`
  48. MountPoint=`echo $Temp | cut -f 6- -d ' '`
  49. if [[ "$MountPoint" == '' ]] ; then
  50. if [[ $UID != 0 ]] ; then
  51. echo "You must run this program as root or using sudo! Exiting!"
  52. exit 1
  53. fi
  54. MountPoint="/Volumes/ESP"
  55. mkdir /Volumes/ESP &> /dev/null
  56. mount -t msdos "$Esp" $MountPoint
  57. # Some systems have HFS+ "ESPs." They shouldn't, but they do. If this is
  58. # detected, mount it as such and set appropriate options.
  59. if [[ $? != 0 ]] ; then
  60. mount -t hfs "$Esp" $MountPoint
  61. if [[ $? != 0 ]] ; then
  62. echo "Unable to mount ESP!\n"
  63. exit 1
  64. fi
  65. fi
  66. fi
  67. echo "The ESP is mounted at $MountPoint"
  68. } # MountOSXESP()
  69.  
  70. #
  71. # Main part of script....
  72. #
  73.  
  74. case "$OSTYPE" in
  75. darwin*)
  76. MountOSXESP
  77. ;;
  78. *)
  79. echo "This script is meant to be run under OS X *ONLY*! Exiting!"
  80. exit
  81. ;;
  82. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement