-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootbind
61 lines (49 loc) · 1.53 KB
/
bootbind
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
#!/usr/bin/bash
# vim:set ts=3:
exec 1>&2
shopt -s dotglob
shopt -s lastpipe
if mountpoint -q "${ESP_ROOT}"; then
echo "${ESP_ROOT} is already mounted, aborting..."
exit 1
fi
if ls ${ESP_ROOT}/* &> /dev/null; then
echo "${ESP_ROOT} is not empty, aborting..."
exit 1
fi
TIME=0
TIMEOUT=10
EFIVARS='/sys/firmware/efi/efivars'
LDPUVAR='LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f'
while [[ $TIME -lt $TIMEOUT ]]; do
[[ -e $EFIVARS/$LDPUVAR ]] && break
sleep 1
TIME=$(($TIME+1))
done
# get the UUID of the ESP that sd-boot was loaded from when the system booted
# skip the first four bytes as they are not part of the UUID data
# translate uppercase to lowercase because findmnt matches case-sensitively
dd if="$EFIVARS/$LDPUVAR" bs=1 skip=4 conv=lcase status=none | tr -d '\000' \
| read UUID
# fallback to using efibootmgr
if [[ -z $UUID ]]; then
echo "failed to read LoaderDevicePartUUID, retrying with efibootmgr..."
EFI_VARS="$(efibootmgr -v)"
[[ -n $EFI_VARS ]] && echo "$EFI_VARS" | grep "^BootCurrent: " \
| read LABEL BOOT_ID
[[ -n $BOOT_ID ]] && echo "$EFI_VARS" | grep "^Boot$BOOT_ID" \
| grep --perl-regexp -io '[0-9a-f-]{36}' | read UUID
fi
if [[ -z $UUID ]]; then
echo "failed to read ESP UUID from EFI, aborting..."
exit 1
fi
findmnt -n -l --source "PARTUUID=$UUID" --output "target" \
| grep "^${ESP_ROOT}@[a-z]$" | read ESP_MOUNT
if [[ -z $ESP_MOUNT ]]; then
echo "failed to find mountpoint of form ${ESP_ROOT}@[a-z]" \
"for current esp, aborting..."
exit 1
fi
mount -o bind "$ESP_MOUNT" "${ESP_ROOT}"
exit $?