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 22, 2023
1 parent 6afe2ff commit 592782b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions zfsbootmenu/bin/halt
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|halt|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

0 comments on commit 592782b

Please sign in to comment.