Sysrq

From Leo's Notes
Last edited on 30 December 2021, at 01:29.

The magic SysRq key provides a way to instruct the kernel through the /proc pseudo-filesystem. It must be enabled with the kernel during compile time with the CONFIG_MAGIC_SYSRQ option and is standard for most distributions.

Rebooting

Suppose you have a system that you can SSH into but cannot reboot because the system disk is dying or the SATA bus is in some weird state and no IO is actually working.

# reboot
bash: /sbin/reboot: Input/output error
# shutdown -r now
bash: /sbin/shutdown: Input/output error

Or perhaps the system disk is fine, but sync() isn't returning which causes reboot to hang even with the -f option.

To reboot the machine in such a state, enable sysrq and write 'b' to the sysrq-trigger.

## Enable sysrq
# echo 1 > /proc/sys/kernel/sysrq

## Reboot the machine without sync immediately
# echo b > /proc/sysrq-trigger

See Also