22

The file /proc/sys/kernel/sysrq contains a single number, such as:

  • 1 (enable all SysRq commands),
  • 0 (disable all),
  • or a base-10 positive integer which functions as a binary bitmask, enabling a subset of functions.

Could someone please tell me which SysRq functions are allowed/disallowed when the bitmask is set to 438?


$ cat /proc/sys/kernel/sysrq
438

2 Answers 2

31

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.

8
  • Ah, it's just a linear combination of the individual bitmasks. Thanks very much.
    – user001
    Commented Jan 7, 2012 at 18:08
  • One follow-up: If nothing happens when I do Alt+SysRq+(a command key), then I suppose this means that sysrq was not enabled when the kernel was installed. Is there a simple way to check whether sysrq is enabled or not (e.g., can I find the status of CONFIG_MAGIC_SYSRQ somewhere)?
    – user001
    Commented Jan 7, 2012 at 18:14
  • 3
    I added a possible way to check for CONFIG_MAGIC_SYSRQ. Commented Jan 7, 2012 at 18:27
  • Thanks. Worked for me on Debian as well. The output: CONFIG_MAGIC_SYSRQ=y CONFIG_MAGIC_SYSRQ_DEFAULT_MASK=0x01b6 (01b6 in hex is 438 in decimal). I suppose the y means it has been enabled. Would give 2 up-votes if I could.
    – user001
    Commented Jan 7, 2012 at 18:28
  • 1
    On many Linux distros, the configuration is kept in the kernel itself, not in /boot, so the check command would be zgrep SYSRQ /proc/config.gz (or gunzip -c /proc/config.gz | grep SYSRQ). Commented Jan 7, 2012 at 19:16
5

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
2
  • For persistent config, I had to use something like 60-sysrq.conf because in case of 20-sysrq.conf, it was getting overriden by /usr/lib/sysctl.d/50-default.conf. Commented Nov 24, 2020 at 12:11
  • I wonder why anyone would decide to load the defaults at such a late index as 50 rather than at, say, 1. It obviously renders half of the index space useless. Commented Dec 22, 2020 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .