How to check which SysRq functions are enabled?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 How To Check Which Sysrq Functions Are Enabled?
00:34 Accepted Answer Score 31
01:27 Answer 2 Score 5
01:52 Thank you
--
Full question
https://superuser.com/questions/375816/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #bash #linuxkernel #bitmaps #sysrq
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 How To Check Which Sysrq Functions Are Enabled?
00:34 Accepted Answer Score 31
01:27 Answer 2 Score 5
01:52 Thank you
--
Full question
https://superuser.com/questions/375816/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #bash #linuxkernel #bitmaps #sysrq
#avk47
ACCEPTED ANSWER
Score 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.
ANSWER 2
Score 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