Skip to content

Commit 0d0372d

Browse files
committed
zfsbootmenu/bin/firmware-setup: new reboot functionality
reboots to UEFI firmware setup if supported fixes #423
1 parent 406cf45 commit 0d0372d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

docs/online/recovery-shell.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ Common Commands
6363
**reboot**
6464

6565
Reboot the system using a SysRq magic invocation.
66+
67+
**firmware-setup**
68+
69+
Reboot the system into the UEFI Firmware Setup interface (if available).

zfsbootmenu/bin/firmware-setup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../reboot

zfsbootmenu/bin/reboot

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,61 @@ done
1717

1818
unset src sources
1919

20+
check_fw_setup() {
21+
if ! is_efi_system; then
22+
zdebug "efivarfs unsupported"
23+
return 1
24+
elif [ ! -r /sys/firmware/efi/efivars/OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
25+
zdebug "OsIndicationsSupported unsupported"
26+
return 1
27+
elif [ ! -r /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
28+
zdebug "OsIndications unsupported"
29+
return 1
30+
fi
31+
32+
# Check if the EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x01 bit is set
33+
if ! (( $(od -An -t u1 -j4 -N1 \
34+
/sys/firmware/efi/efivars/OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c \
35+
| tr -dc '0-9') & 1 )); then
36+
zdebug "EFI reboot to firmware setup unsupported"
37+
return 1
38+
fi
39+
}
40+
41+
set_fw_setup() {
42+
mount_efivarfs rw
43+
if [ ! -w /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c ]; then
44+
zdebug "OsIndications not writable"
45+
return 1
46+
fi
47+
48+
mapfile -t osindications < <(od -An -t x1 -v -w1 \
49+
/sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c | tr -dc '[:alnum:]\n')
50+
51+
# Set the EFI_OS_INDICATIONS_BOOT_TO_FW_UI = 0x01 bit if not already set
52+
if ! (( "${osindications[4]}" & 0x01 )); then
53+
printf -v osindications[4] '%02x' $(( 0x"${osindications[4]}" | 0x01 ))
54+
55+
printf -v bytes '\\x%02x' "${osindications[@]}"
56+
printf '%b' "$bytes" \
57+
> /sys/firmware/efi/efivars/OsIndications-8be4df61-93ca-11d2-aa0d-00e098032b8c
58+
fi
59+
}
60+
2061
case "${0##*/}" in
2162
reboot)
2263
trigger="b"
2364
;;
2465
shutdown|poweroff)
2566
trigger="o"
2667
;;
68+
firmware-setup)
69+
if ! check_fw_setup || ! set_fw_setup; then
70+
echo -e "\033[0;31mWARNING: Reboot to UEFI firmware UI unsupported; unable to proceed\033[0m"
71+
exit 1
72+
fi
73+
trigger="b"
74+
;;
2775
*)
2876
exit
2977
;;
@@ -34,7 +82,7 @@ while read -r _pool; do
3482
done <<<"$( zpool list -H -o name )"
3583

3684
sysrq="/proc/sysrq-trigger"
37-
if [ -e "${sysrq}" ] && [ -w "${sysrq}" ]; then
85+
if [ -e "${sysrq}" ] && [ -w "${sysrq}" ]; then
3886
echo "${trigger}" > /proc/sysrq-trigger
3987
else
4088
echo "${sysrq} does not exist, hard reset system"

0 commit comments

Comments
 (0)