Feed RSS
Feed RSS
Links
Debian GNU Linux
Play Ogg
Eliminate DRM!
hosted by tuxfamily.org
Articles Hierarchy

    SysRq magic keys

The SysRq are magic keys that can be used to recover the system from a complete freeze. These combinations of keys are read directly by the kernel that will always respond unless a kernel panic happened. The magic keys combinations are all of the kind

Alt + PrintScreen + KEY

where KEY changes with the action we want to perform.
In order to be able to use the SysRq keys the kernel must have been compiled with the flag

CONFIG_MAGIC_SYSRQ

enabled. Any major distribution enables SysRq by default but in order to whether this is true use

$ grep CONFIG_MAGIC_SYSRQ /boot/config-$(uname -r)
CONFIG_MAGIC_SYSRQ=y
CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x01b6

the relevant lines is the first that indicates that the flag has been enabled. If it is the SysRq can be enabled/disabled at will in the system quickly modifying the /proc/sys/kernel/sysrq

$ cat /proc/sys/kernel/sysrq
438

The number in this file explain which combinations are available, a 0 means that SysRq is not enabled. The enabled combinations can be desumed from the following table (from the official documentation)

FLAG BITMASK MEANING
0   disable sysrq completely
1   enable all functions of sysrq
>1   bitmask of allowed sysrq functions
  2 = 0x2 enable control of console logging level
  4 = 0x4 enable control of keyboard (SAK, unraw)
  8 = 0x8 enable debugging dumps of processes etc.
  16 = 0x10 enable sync command
  32 = 0x20 enable remount read-only
  64 = 0x40 enable signalling of processes (term, kill, oom-kill)
  128 = 0x80 allow reboot/poweroff
  256 = 0x100 allow nicing of all RT tasks

 

Under Debian the bitmask 438 corresponds to

438 = 2 + 4 + 16 + 32 + 128 + 256

Note that the value 438 in hexadecimal corresponds to 0x01b6 as found in

$ grep CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE /boot/config-$(uname -r)
CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x01b6

Modifying this key at kernel compilation time will change the default SysRq combinations eanbled. The default flag can be changed on a live system using

# echo "1" > /proc/sys/kernel/sysrq

or

# sysctl -w kernel.sysrq=0

While to make the change permanent it must be modified the file /etc/sysctl.conf. In this file we must search for the key kernel.sysrq or create it if it doesn't exist, like in the following case

kernel.sysrq = 1

Which commands are available? The documentation page lists all the available commands. The most used ones are the following:

FLAG MEANING
b Will immediately reboot the system without syncing or unmounting your disks
e Send a SIGTERM to all processes, except for init
f Will call oom_kill to kill a memory hog process
i Send a SIGKILL to all processes, except for init
o Will shut your system off (if configured and supported)
s Will attempt to sync all mounted filesystems
t Will dump a list of current tasks and their information to your console
u Will attempt to remount all mounted filesystems read-only
Comments
No Comments have been Posted.

Post Comment
Please Login to Post a Comment.

Ratings
Rating is available to Members only.

Please login to vote.

No Ratings have been Posted.