Skip to content

Commit

Permalink
zfsbootmenu: add sysrq-based reboot/poweroff
Browse files Browse the repository at this point in the history
  • Loading branch information
zdykstra committed Sep 27, 2023
1 parent 6afe2ff commit e93de79
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 16 deletions.
8 changes: 8 additions & 0 deletions docs/online/recovery-shell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ Common Commands
**logs**

View warning/error/debug logs.

**shutdown**|**poweroff**

Shutdown the system using a SysRq magic invocation.

**reboot**

Reboot the system using a SysRq magic invocation.
1 change: 1 addition & 0 deletions zfsbootmenu/bin/poweroff
42 changes: 42 additions & 0 deletions zfsbootmenu/bin/reboot
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# vim: softtabstop=2 shiftwidth=2 expandtab

# shellcheck disable=SC1091
sources=(
/lib/kmsg-log-lib.sh
/lib/zfsbootmenu-core.sh
)

for src in "${sources[@]}"; do
# shellcheck disable=SC1090
if ! source "${src}" >/dev/null 2>&1 ; then
echo -e "\033[0;31mWARNING: ${src} was not sourced; unable to proceed\033[0m"
exit 1
fi
done

unset src sources

case "${0##*/}" in
reboot)
trigger="b"
;;
shutdown|poweroff)
trigger="o"
;;
*)
exit
;;
esac

while read -r _pool; do
is_writable "${_pool}" && export_pool "${_pool}"
done <<<"$( zpool list -H -o name )"

sysrq="/proc/sysrq-trigger"
if [ -e "${sysrq}" ] && [ -w "${sysrq}" ]; then
echo "${trigger}" > /proc/sysrq-trigger
else
echo "${sysrq} does not exist, hard reset system"
exit 1
fi
1 change: 1 addition & 0 deletions zfsbootmenu/bin/shutdown
8 changes: 8 additions & 0 deletions zfsbootmenu/help-files/132/recovery-shell.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@
logs

View warning/error/debug logs.

shutdown**|**poweroff

Shutdown the system using a SysRq magic invocation.

reboot

Reboot the system using a SysRq magic invocation.
20 changes: 16 additions & 4 deletions zfsbootmenu/help-files/132/zfsbootmenu.7.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@

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

zbm.autosize

Enable automatic font resizing of the kernel console to normalize the apparent resolution for both low resolution and high
resolution displays. This option is enabled by default.

Deprecated Parameters

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

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

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

No boot-selection or teardown hook should assume that the filesystem named in ZBM_SELECTED_BE is currently mounted. In
addition, no teardown hook should assume that the ZFSBootMenu environment is in a consistent operating state.
ZFSBootMenu may have exported some or all pools prior to executing teardown hooks.
Additionally, boot-selection hooks will have access to a fourth environment variable:

ZBM_SELECTED_MOUNTPOINT

The path where the selected boot environment is currently mounted, which is the root relative to which ZFSBootMenu will
attempt to load the selected kernel and initramfs.

Teardown hooks should never assume that the filesystem named in ZBM_SELECTED_BE is currently mounted. In addition, no teardown
hook should assume that the ZFSBootMenu environment is in a consistent operating state. ZFSBootMenu may have exported
some or all pools prior to executing teardown hooks.

In general, it is not possible to cleanly abort a boot attempt from boot-selection or teardown hooks. However, a
boot-selection or teardown hook may take control of the boot attempt by implementing its own kexec load and execution
Expand Down
10 changes: 10 additions & 0 deletions zfsbootmenu/help-files/52/recovery-shell.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@
logs

View warning/error/debug logs.

shutdown**|**poweroff

Shutdown the system using a SysRq magic
invocation.

reboot

Reboot the system using a SysRq magic
invocation.
31 changes: 25 additions & 6 deletions zfsbootmenu/help-files/52/zfsbootmenu.7.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@
spaces and MUST NOT be enclosed in
quotes.

zbm.autosize

Enable automatic font resizing of the kernel
console to normalize the apparent
resolution for both low resolution and
high resolution displays. This option is
enabled by default.

Deprecated Parameters

timeout
Expand Down Expand Up @@ -596,7 +604,7 @@

Teardown hooks will be installed from the
directory ${zfsbootmenu_hook_root}/-
teardown.d. These hooks will be exectued
teardown.d. These hooks will be executed
after the kernel for a selected
environment has been loaded and is
launching via kexec is imminent. Some
Expand Down Expand Up @@ -630,11 +638,22 @@
the selected kernel, again relative
to the root of ZBM_SELECTED_BE.

No boot-selection or teardown hook should
assume that the filesystem named in
ZBM_SELECTED_BE is currently mounted. In
addition, no teardown hook should assume
that the ZFSBootMenu environment is in a
Additionally, boot-selection hooks will have
access to a fourth environment variable:

ZBM_SELECTED_MOUNTPOINT

The path where the selected boot environment
is currently mounted, which is the
root relative to which ZFSBootMenu
will attempt to load the selected
kernel and initramfs.

Teardown hooks should never assume that the
filesystem named in ZBM_SELECTED_BE is
currently mounted. In addition, no
teardown hook should assume that the
ZFSBootMenu environment is in a
consistent operating state. ZFSBootMenu
may have exported some or all pools
prior to executing teardown hooks.
Expand Down
8 changes: 8 additions & 0 deletions zfsbootmenu/help-files/92/recovery-shell.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@
logs

View warning/error/debug logs.

shutdown**|**poweroff

Shutdown the system using a SysRq magic invocation.

reboot

Reboot the system using a SysRq magic invocation.
25 changes: 19 additions & 6 deletions zfsbootmenu/help-files/92/zfsbootmenu.7.ansi
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@
NOTE: The hooklist argument MUST NOT contain spaces and MUST NOT be enclosed in
quotes.

zbm.autosize

Enable automatic font resizing of the kernel console to normalize the apparent
resolution for both low resolution and high resolution displays. This option is
enabled by default.

Deprecated Parameters

timeout
Expand Down Expand Up @@ -414,7 +420,7 @@
boot the kernel.

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

No boot-selection or teardown hook should assume that the filesystem named in
ZBM_SELECTED_BE is currently mounted. In addition, no teardown hook should
assume that the ZFSBootMenu environment is in a consistent operating state.
ZFSBootMenu may have exported some or all pools prior to executing teardown
hooks.
Additionally, boot-selection hooks will have access to a fourth environment variable:

ZBM_SELECTED_MOUNTPOINT

The path where the selected boot environment is currently mounted, which is the root
relative to which ZFSBootMenu will attempt to load the selected kernel and
initramfs.

Teardown hooks should never assume that the filesystem named in ZBM_SELECTED_BE is
currently mounted. In addition, no teardown hook should assume that the
ZFSBootMenu environment is in a consistent operating state. ZFSBootMenu may have
exported some or all pools prior to executing teardown hooks.

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

0 comments on commit e93de79

Please sign in to comment.