]> code.delx.au - refind/blob - mountesp
Merge remote-tracking branch 'tianon/master'
[refind] / mountesp
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) 2012-2015 by Roderick W. Smith
10 # It is released under the terms of the GNU GPL, version 3,
11 # a copy of which should be included in the file COPYING.txt.
12 #
13 # Revision history:
14 #
15 # 0.9.3 -- Initial release (with rEFInd 0.9.3)
16
17 # Mount the ESP at /Volumes/ESP or determine its current mount
18 # point.
19 MountOSXESP() {
20 # Identify the ESP. Note: This returns the FIRST ESP found;
21 # if the system has multiple disks, this could be wrong!
22 Temp=$(mount | sed -n -E "/^(\/dev\/disk[0-9]+s[0-9]+) on \/ \(.*$/s//\1/p")
23 if [ $Temp ]; then
24 Temp=$(diskutil list | grep " EFI " | grep -o 'disk.*' | head -n 1)
25 if [ -z $Temp ]; then
26 echo "Warning: root device doesn't have an EFI partition"
27 fi
28 else
29 echo "Warning: root device could not be found"
30 fi
31 if [ -z $Temp ]; then
32 Temp=$(diskutil list | sed -n -E '/^ *[0-9]+:[ ]+EFI EFI[ ]+[0-9.]+ [A-Z]+[ ]+(disk[0-9]+s[0-9]+)$/ { s//\1/p
33 q
34 }' )
35
36 if [ -z $Temp ]; then
37 echo "Could not find an EFI partition. Aborting!"
38 exit 1
39 fi
40 fi
41 Esp=/dev/`echo $Temp`
42 echo "The ESP has been identified as $Esp; attempting to mount it...."
43 # If the ESP is mounted, use its current mount point....
44 Temp=`df -P | grep "$Esp "`
45 MountPoint=`echo $Temp | cut -f 6- -d ' '`
46 if [[ "$MountPoint" == '' ]] ; then
47 if [[ $UID != 0 ]] ; then
48 echo "You must run this program as root or using sudo! Exiting!"
49 exit 1
50 fi
51 MountPoint="/Volumes/ESP"
52 mkdir /Volumes/ESP &> /dev/null
53 mount -t msdos "$Esp" $MountPoint
54 # Some systems have HFS+ "ESPs." They shouldn't, but they do. If this is
55 # detected, mount it as such and set appropriate options.
56 if [[ $? != 0 ]] ; then
57 mount -t hfs "$Esp" $MountPoint
58 if [[ $? != 0 ]] ; then
59 echo "Unable to mount ESP!\n"
60 exit 1
61 fi
62 fi
63 fi
64 echo "The ESP is mounted at $MountPoint"
65 } # MountOSXESP()
66
67 #
68 # Main part of script....
69 #
70
71 case "$OSTYPE" in
72 darwin*)
73 MountOSXESP
74 ;;
75 *)
76 echo "This script is meant to be run under OS X *ONLY*! Exiting!"
77 exit
78 ;;
79 esac