Skip to content

Commit e93de79

Browse files
committed
zfsbootmenu: add sysrq-based reboot/poweroff
1 parent 6afe2ff commit e93de79

File tree

10 files changed

+138
-16
lines changed

10 files changed

+138
-16
lines changed

docs/online/recovery-shell.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ Common Commands
5151
**logs**
5252

5353
View warning/error/debug logs.
54+
55+
**shutdown**|**poweroff**
56+
57+
Shutdown the system using a SysRq magic invocation.
58+
59+
**reboot**
60+
61+
Reboot the system using a SysRq magic invocation.

zfsbootmenu/bin/poweroff

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

zfsbootmenu/bin/reboot

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# vim: softtabstop=2 shiftwidth=2 expandtab
3+
4+
# shellcheck disable=SC1091
5+
sources=(
6+
/lib/kmsg-log-lib.sh
7+
/lib/zfsbootmenu-core.sh
8+
)
9+
10+
for src in "${sources[@]}"; do
11+
# shellcheck disable=SC1090
12+
if ! source "${src}" >/dev/null 2>&1 ; then
13+
echo -e "\033[0;31mWARNING: ${src} was not sourced; unable to proceed\033[0m"
14+
exit 1
15+
fi
16+
done
17+
18+
unset src sources
19+
20+
case "${0##*/}" in
21+
reboot)
22+
trigger="b"
23+
;;
24+
shutdown|poweroff)
25+
trigger="o"
26+
;;
27+
*)
28+
exit
29+
;;
30+
esac
31+
32+
while read -r _pool; do
33+
is_writable "${_pool}" && export_pool "${_pool}"
34+
done <<<"$( zpool list -H -o name )"
35+
36+
sysrq="/proc/sysrq-trigger"
37+
if [ -e "${sysrq}" ] && [ -w "${sysrq}" ]; then
38+
echo "${trigger}" > /proc/sysrq-trigger
39+
else
40+
echo "${sysrq} does not exist, hard reset system"
41+
exit 1
42+
fi

zfsbootmenu/bin/shutdown

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

zfsbootmenu/help-files/132/recovery-shell.ansi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@
5151
logs
5252

5353
View warning/error/debug logs.
54+
55+
shutdown**|**poweroff
56+
57+
Shutdown the system using a SysRq magic invocation.
58+
59+
reboot
60+
61+
Reboot the system using a SysRq magic invocation.

zfsbootmenu/help-files/132/zfsbootmenu.7.ansi

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@
162162

163163
NOTE: The hooklist argument MUST NOT contain spaces and MUST NOT be enclosed in quotes.
164164

165+
zbm.autosize
166+
167+
Enable automatic font resizing of the kernel console to normalize the apparent resolution for both low resolution and high
168+
resolution displays. This option is enabled by default.
169+
165170
Deprecated Parameters
166171

167172
timeout
@@ -344,7 +349,7 @@
344349
Boot-selection hooks will be installed from the directory ${zfsbootmenu_hook_root}/boot-sel.d. These hooks will be executed
345350
after a user has selected a boot environment, but before ZFSBootMenu attempts to load and boot the kernel.
346351

347-
Teardown hooks will be installed from the directory ${zfsbootmenu_hook_root}/teardown.d. These hooks will be exectued after
352+
Teardown hooks will be installed from the directory ${zfsbootmenu_hook_root}/teardown.d. These hooks will be executed after
348353
the kernel for a selected environment has been loaded and is launching via kexec is imminent. Some hardware initialized
349354
by the ZFSBootMenu kernel may not be properly reinitialized when a boot environment is launched; teardown hooks may be
350355
useful to unbind drivers from problematic hardware or remove associated kernel modules.
@@ -364,9 +369,16 @@
364369

365370
The path to the initramfs corresponding to the selected kernel, again relative to the root of ZBM_SELECTED_BE.
366371

367-
No boot-selection or teardown hook should assume that the filesystem named in ZBM_SELECTED_BE is currently mounted. In
368-
addition, no teardown hook should assume that the ZFSBootMenu environment is in a consistent operating state.
369-
ZFSBootMenu may have exported some or all pools prior to executing teardown hooks.
372+
Additionally, boot-selection hooks will have access to a fourth environment variable:
373+
374+
ZBM_SELECTED_MOUNTPOINT
375+
376+
The path where the selected boot environment is currently mounted, which is the root relative to which ZFSBootMenu will
377+
attempt to load the selected kernel and initramfs.
378+
379+
Teardown hooks should never assume that the filesystem named in ZBM_SELECTED_BE is currently mounted. In addition, no teardown
380+
hook should assume that the ZFSBootMenu environment is in a consistent operating state. ZFSBootMenu may have exported
381+
some or all pools prior to executing teardown hooks.
370382

371383
In general, it is not possible to cleanly abort a boot attempt from boot-selection or teardown hooks. However, a
372384
boot-selection or teardown hook may take control of the boot attempt by implementing its own kexec load and execution

zfsbootmenu/help-files/52/recovery-shell.ansi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@
6262
logs
6363

6464
View warning/error/debug logs.
65+
66+
shutdown**|**poweroff
67+
68+
Shutdown the system using a SysRq magic
69+
invocation.
70+
71+
reboot
72+
73+
Reboot the system using a SysRq magic
74+
invocation.

zfsbootmenu/help-files/52/zfsbootmenu.7.ansi

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@
274274
spaces and MUST NOT be enclosed in
275275
quotes.
276276

277+
zbm.autosize
278+
279+
Enable automatic font resizing of the kernel
280+
console to normalize the apparent
281+
resolution for both low resolution and
282+
high resolution displays. This option is
283+
enabled by default.
284+
277285
Deprecated Parameters
278286

279287
timeout
@@ -596,7 +604,7 @@
596604

597605
Teardown hooks will be installed from the
598606
directory ${zfsbootmenu_hook_root}/-
599-
teardown.d. These hooks will be exectued
607+
teardown.d. These hooks will be executed
600608
after the kernel for a selected
601609
environment has been loaded and is
602610
launching via kexec is imminent. Some
@@ -630,11 +638,22 @@
630638
the selected kernel, again relative
631639
to the root of ZBM_SELECTED_BE.
632640

633-
No boot-selection or teardown hook should
634-
assume that the filesystem named in
635-
ZBM_SELECTED_BE is currently mounted. In
636-
addition, no teardown hook should assume
637-
that the ZFSBootMenu environment is in a
641+
Additionally, boot-selection hooks will have
642+
access to a fourth environment variable:
643+
644+
ZBM_SELECTED_MOUNTPOINT
645+
646+
The path where the selected boot environment
647+
is currently mounted, which is the
648+
root relative to which ZFSBootMenu
649+
will attempt to load the selected
650+
kernel and initramfs.
651+
652+
Teardown hooks should never assume that the
653+
filesystem named in ZBM_SELECTED_BE is
654+
currently mounted. In addition, no
655+
teardown hook should assume that the
656+
ZFSBootMenu environment is in a
638657
consistent operating state. ZFSBootMenu
639658
may have exported some or all pools
640659
prior to executing teardown hooks.

zfsbootmenu/help-files/92/recovery-shell.ansi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,11 @@
5252
logs
5353

5454
View warning/error/debug logs.
55+
56+
shutdown**|**poweroff
57+
58+
Shutdown the system using a SysRq magic invocation.
59+
60+
reboot
61+
62+
Reboot the system using a SysRq magic invocation.

zfsbootmenu/help-files/92/zfsbootmenu.7.ansi

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@
191191
NOTE: The hooklist argument MUST NOT contain spaces and MUST NOT be enclosed in
192192
quotes.
193193

194+
zbm.autosize
195+
196+
Enable automatic font resizing of the kernel console to normalize the apparent
197+
resolution for both low resolution and high resolution displays. This option is
198+
enabled by default.
199+
194200
Deprecated Parameters
195201

196202
timeout
@@ -414,7 +420,7 @@
414420
boot the kernel.
415421

416422
Teardown hooks will be installed from the directory
417-
${zfsbootmenu_hook_root}/teardown.d. These hooks will be exectued after the
423+
${zfsbootmenu_hook_root}/teardown.d. These hooks will be executed after the
418424
kernel for a selected environment has been loaded and is launching via kexec is
419425
imminent. Some hardware initialized by the ZFSBootMenu kernel may not be
420426
properly reinitialized when a boot environment is launched; teardown hooks may
@@ -437,11 +443,18 @@
437443
The path to the initramfs corresponding to the selected kernel, again relative to
438444
the root of ZBM_SELECTED_BE.
439445

440-
No boot-selection or teardown hook should assume that the filesystem named in
441-
ZBM_SELECTED_BE is currently mounted. In addition, no teardown hook should
442-
assume that the ZFSBootMenu environment is in a consistent operating state.
443-
ZFSBootMenu may have exported some or all pools prior to executing teardown
444-
hooks.
446+
Additionally, boot-selection hooks will have access to a fourth environment variable:
447+
448+
ZBM_SELECTED_MOUNTPOINT
449+
450+
The path where the selected boot environment is currently mounted, which is the root
451+
relative to which ZFSBootMenu will attempt to load the selected kernel and
452+
initramfs.
453+
454+
Teardown hooks should never assume that the filesystem named in ZBM_SELECTED_BE is
455+
currently mounted. In addition, no teardown hook should assume that the
456+
ZFSBootMenu environment is in a consistent operating state. ZFSBootMenu may have
457+
exported some or all pools prior to executing teardown hooks.
445458

446459
In general, it is not possible to cleanly abort a boot attempt from boot-selection or
447460
teardown hooks. However, a boot-selection or teardown hook may take control of

0 commit comments

Comments
 (0)