-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmount_efi.sh
More file actions
executable file
·51 lines (42 loc) · 1.74 KB
/
mount_efi.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.74 KB
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
#!/bin/bash
#set -x
# Note: Based on CloverPackage MountESP script.
if [ "$(id -u)" != "0" ]; then
echo "This script requires superuser access, use: 'sudo $0 $@'"
exit 1
fi
if [ "$1" == "" ]; then
DestVolume=/
else
DestVolume="$1"
fi
DiskDevice=$(LC_ALL=C diskutil info "$DestVolume" 2>/dev/null | sed -n 's/.*Part [oO]f Whole: *//p')
if [ -z "$DiskDevice" ]; then
echo "Can't find volume with the name $DestVolume"
exit 1
fi
# Check if the disk is a GPT disk
PartitionScheme=$(LC_ALL=C diskutil info "$DiskDevice" 2>/dev/null | sed -nE 's/.*(Partition Type|Content \(IOContent\)): *//p')
if [ "$PartitionScheme" != "GUID_partition_scheme" ]; then
echo Error: volume $DestVolume is not on GPT disk
exit 1
fi
# Get the index of the EFI partition
EFIIndex=$(LC_ALL=C /usr/sbin/gpt -r show "/dev/$DiskDevice" 2>/dev/null | awk 'toupper($7) == "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" {print $3; exit}')
[ -z "$EFIIndex" ] && EFIIndex=$(LC_ALL=C diskutil list "$DiskDevice" 2>/dev/null | awk '$2 == "EFI" {print $1; exit}' | cut -d : -f 1)
[ -z "$EFIIndex" ] && EFIIndex=$(LC_ALL=C diskutil list "$DiskDevice" 2>/dev/null | grep "EFI"|awk '{print $1}'|cut -d : -f 1)
[ -z "$EFIIndex" ] && EFIIndex=1 # if not found use the index 1
# Define the EFIDevice
EFIDevice="${DiskDevice}s$EFIIndex"
# Get the EFI mount point if the partition is currently mounted
EFIMountPoint=$(LC_ALL=C diskutil info "$EFIDevice" 2>/dev/null | sed -n 's/.*Mount Point: *//p')
code=0
if [ ! "$EFIMountPoint" ]; then
# try to mount the EFI partition
EFIMountPoint="/Volumes/EFI"
[ ! -d "$EFIMountPoint" ] && mkdir -p "$EFIMountPoint"
diskutil mount -mountPoint "$EFIMountPoint" /dev/$EFIDevice >/dev/null 2>&1
code=$?
fi
echo $EFIMountPoint
exit $code