How to check which SysRq functions are enabled?
These are the available SysRq functions:
0 - disable every SysRq function.
1 - enable every SysRq function.
2 - enable control of console logging level
4 - enable control of keyboard (SAK, unraw)
8 - enable debugging dumps of processes etc.
16 - enable sync command
32 - enable remount read-only
64 - enable signalling of processes (term, kill, oom-kill)
128 - allow reboot/poweroff
256 - allow nicing of all RT tasks
438
= 2 + 4 + 16 + 32 + 128 + 256
, so only the functions associated with those numbers are allowed. Read all about it in the documentation.
If you convert 438
to base 2 (110110110
) it is even easier to see.
1 1 0 1 1 0 1 1 0
^256 ^128 ^64 ^32 ^16 ^8 ^4 ^2 ^1
Depending on your distribution, you may be able to tell if the kernel was compiled with CONFIG_MAGIC_SYSRQ
using this command:
$ grep SYSRQ /boot/config-$(uname -r)
This works for me on Ubuntu.
Here is a Bash one-liner which will print you the enabled options:
for i in $(seq 1 8); do (( ($(</proc/sys/kernel/sysrq) & $((1<<$i))) > 0 )) && echo $((1<<$i)); done
Which SysRq functions are allowed/disallowed when the bitmask is set to 438?
$ for i in $(seq 1 8); do (( (438 & $((1<<$i))) > 0 )) && echo $((1<<$i)); done
2
4
16
32
128
256
For the meaning, refer to William's answer.
To enable all options, run:
echo 1 | sudo tee /proc/sys/kernel/sysrq
To make it persistent, run:
echo kernel.sysrq=1 | sudo tee /etc/sysctl.d/20-sysrq.conf