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