How to check which SysRq functions are enabled?

15

9

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

user001

Posted 2012-01-07T17:54:52.607

Reputation: 2 074

Answers

22

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.

William Jackson

Posted 2012-01-07T17:54:52.607

Reputation: 7 646

Ah, it's just a linear combination of the individual bitmasks. Thanks very much. – user001 – 2012-01-07T18:08:26.920

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 – 2012-01-07T18:14:24.180

3I added a possible way to check for CONFIG_MAGIC_SYSRQ. – William Jackson – 2012-01-07T18:27:10.487

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 – 2012-01-07T18:28:33.627

1On 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). – user1686 – 2012-01-07T19:16:17.013

Thanks @grawity. There is no file /proc/config.gz on my system, however. – user001 – 2012-01-07T19:45:54.593

I did say 'many', not 'all' -- Debian/Ubuntu do keep it in /boot. – user1686 – 2012-01-07T19:47:01.113

2

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

kenorb

Posted 2012-01-07T17:54:52.607

Reputation: 16 795