magic sysrq

sysrq is a special key combination that allows sending commands directly to the linux kernel, even if userspace is broken/frozen.

enabling it

the /proc/sys/kernel/sysrq file accepts a bitmask written to it, to control which sysrq features are enabled. a 0 disables all sysrq features, while 1 enables all of them. see the kernel documentation for more granular control of sysrq features

since procfs options are not persistant over reboots, it can be enabled persistantly with the sysctl option kernel.sysrq=1 in /etc/sysctl.d/ or by setting the sysrq_always_enabled=1 kernel parameter if you need it before the filesystem mounts

key combinations

sysrq can be used by holding alt, then hitting sysrq (print screen, you may have to press fn too), then releasing all keys except for alt, the letter(s) you want can be pressed. you can do multiple sysrq commands without needing to press sysrq again by continuing to hold alt.

keybehavior
fforce an OOM kill now, even if not out of memory. mey help with a freeze
nnice real-time tasks, may also help with a freeze
kkill current console, can be used as a "secure attention key"
0-9set kernel verbosity
vforce viewing framebuffer (show console)
hprint sysrq helptext to the kernel log, to see more keys not listed here
runraw the keyboard, to take back control from something like X11
esigterm (gracefull kill) all tasks
isigkill all tasks
ssync disks
uunmount disks (sync first to avoid a dirty unmount)
bforce a reboot

the reisub mnemonic (with a few seconds between each key) may be used to gracefully reboot. however, realistically with modern CoW and journaling filesystems, there is not much reason to use it over just holding down the power button