reboot: allow to specify reboot mode via sysfs
PATCH 1/1 reboot: allow to specify reboot mode via sysfs
From: Matteo Croce <[email protected]>
The kernel cmdline reboot= option offers some sort of control on how the reboot is issued.
Add handles in sysfs to allow setting these reboot options, so they can be changed when the system is booted, other than at boot time.
The handlers are under <sysfs>/kernel/reboot, can be read to get the current configuration and written to alter it.
# cd /sys/kernel/reboot/
# grep . * cpu:0 force:0 mode:cold type:acpi
# echo 2 >cpu # echo 1 >force # echo soft >mode # echo bios >type
# grep . * cpu:2 force:1 mode:soft type:bios
Before setting anything, check for CAP_SYS_BOOT capability, so it's possible to allow an unpriviledged process to change these settings simply by relaxing the handles permissions, without opening them to the world.
--- Documentation/ABI/testing/sysfs-kernel-reboot | 26 +++ kernel/reboot.c | 193 ++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-kernel-reboot
Documentation/ABI/testing/sysfs-kernel-reboot new file +26 -0
@@ -0,0 +1,26 @@ +What: /sys/kernel/reboot +Date: October 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Interface to set the kernel reboot mode, similarly to + what can be done via the reboot= cmdline option. + (see Documentation/admin-guide/kernel-parameters.txt) + +What: /sys/kernel/reboot/mode +What: /sys/kernel/reboot/type +What: /sys/kernel/reboot/cpu +What: /sys/kernel/reboot/force + +Date: October 2020 +Contact: Matteo Croce <[email protected]> +Description: Tune reboot parameters. + + mode: Reboot mode. Valid values are: + cold warm hard soft gpio + + type: Reboot type. Valid values are: + bios acpi kbd triple efi pci + + cpu: CPU number to use to reboot. + + force: Force an immediate reboot.
kernel/reboot.c +193 -0
196 lines not on this page · raw message
Signature · 1 line
2.28.0
kernel/reboot.c static int __init reboot_setup(char *str) · line 601
Quoted 4 lines · Matteo Croce
kernel/reboot.c +4
-0+#ifdef CONFIG_SYSFS + +#define STARTS_WITH (s, sc) (!strncmp(s, sc, sizeof(sc))) +
Just noticed an off-by-one here, it should be sizeof(sc)-1 because of the null terminator.
This way, the CR usually added by echo will be skipped.
Regards,
Signature · 1 line
per aspera ad upstream