]> code.delx.au - refind/blob - mountesp
Added new mountesp script to help OS X users mount the ESP.
[refind] / mountesp
1 #!/bin/bash
2
3 # Mount the ESP at /Volumes/ESP or determine its current mount
4 # point.
5 MountOSXESP() {
6 # Identify the ESP. Note: This returns the FIRST ESP found;
7 # if the system has multiple disks, this could be wrong!
8 Temp=$(mount | sed -n -E "/^(\/dev\/disk[0-9]+s[0-9]+) on \/ \(.*$/s//\1/p")
9 if [ $Temp ]; then
10 Temp=$(diskutil list | grep " EFI " | grep -o 'disk.*' | head -n 1)
11 if [ -z $Temp ]; then
12 echo "Warning: root device doesn't have an EFI partition"
13 fi
14 else
15 echo "Warning: root device could not be found"
16 fi
17 if [ -z $Temp ]; then
18 Temp=$(diskutil list | sed -n -E '/^ *[0-9]+:[ ]+EFI EFI[ ]+[0-9.]+ [A-Z]+[ ]+(disk[0-9]+s[0-9]+)$/ { s//\1/p
19 q
20 }' )
21
22 if [ -z $Temp ]; then
23 echo "Could not find an EFI partition. Aborting!"
24 exit 1
25 fi
26 fi
27 Esp=/dev/`echo $Temp`
28 # If the ESP is mounted, use its current mount point....
29 Temp=`df -P | grep "$Esp "`
30 MountPoint=`echo $Temp | cut -f 6- -d ' '`
31 if [[ "$MountPoint" == '' ]] ; then
32 MountPoint="/Volumes/ESP"
33 mkdir /Volumes/ESP &> /dev/null
34 mount -t msdos "$Esp" /Volumes/ESP
35 # Some systems have HFS+ "ESPs." They shouldn't, but they do. If this is
36 # detected, mount it as such and set appropriate options.
37 if [[ $? != 0 ]] ; then
38 mount -t hfs "$Esp" /Volumes/Esp
39 if [[ $? != 0 ]] ; then
40 echo "Unable to mount ESP!\n"
41 exit 1
42 fi
43 fi
44 fi
45 echo "The ESP is mounted at $MountPoint"
46 } # MountOSXESP()
47
48 #
49 # Main part of script....
50 #
51
52 case "$OSTYPE" in
53 darwin*)
54 MountOSXESP
55 ;;
56 *)
57 echo "This script is meant to be run under OS X *ONLY*! Exiting!"
58 exit
59 ;;
60 esac