Magic SysRq Keys
Magic SysRq Key
The Magic SysRq
key is a tool for Linux administrators, providing a backdoor to issue direct commands to the kernel in cases where the system becomes unresponsive.
This feature is not just a single key but a combination that includes the Alt
and SysRq
keys, followed by a command character.
Interfaces
To leverage the Magic SysRq key, users must navigate varying key combinations depending on their system’s architecture
x86 Systems: Employ the
ALT-SysRq
plus a specific command key. Note that theSysRq
functionality might be combined with thePrint Screen
key. For keyboards that struggle with simultaneous key presses, sequentially pressing and releasing keys may improve reliability.SPARC Systems: The combination is
ALT-STOP
plus the command key.Serial Console: Send a
BREAK
, followed by a command key within 5 seconds. A doubleBREAK
signals a normalBREAK
.PowerPC: Use
ALT-Print Screen
(orF13
) followed by the command key. Sometimes, justPrint Screen
orF13
with the command key suffices.General Method: For systems where key combinations are not applicable, writing directly to
/proc/sysrq-trigger
is a universal approach, e.g.:echo t > /proc/sysrq-trigger
. This method ensures that regardless of physical or remote access limitations, system administrators can invokeSysRq
commands to manage or recover systems effectively.
Commands
- b: Immediately reboots the system without syncing or unmounting disks.
- c: Triggers a system crash through a NULL pointer dereference, capturing a crashdump if configured.
- d: Displays all held locks.
- e: Sends SIGTERM to all processes except init.
- f: Calls the OOM killer on a memory-intensive process without causing a panic.
- g: Utilized by the kernel debugger (kgdb).
- h: Displays help; any unrecognized key also triggers help.
- i: Sends SIGKILL to all processes except init.
- j: Thaws filesystems frozen by the FIFREEZE ioctl.
- k: Activates the Secure Access Key (SAK), killing all programs on the current virtual console.
- l: Shows a stack backtrace for all active CPUs.
- m: Dumps current memory information to the console.
- n: Makes RT tasks nice-able.
- o: Powers off the system if configured and supported.
- p: Dumps current registers and flags to the console.
- q: Dumps per CPU lists of all armed hrtimers and detailed clockevent device information.
- r: Switches the keyboard from raw mode to XLATE.
- s: Attempts to sync all mounted filesystems.
- t: Dumps a list of current tasks and their information to the console.
- u: Attempts to remount all mounted filesystems read-only.
- v: Forcefully restores the framebuffer console.
- w: Dumps tasks in an uninterruptable (blocked) state.
- x: Interface for xmon on ppc/powerpc platforms or shows global PMU Registers on sparc64 and dumps all TLB entries on MIPS.
- y: Shows global CPU Registers (SPARC-64 specific).
- z: Dumps the ftrace buffer.
- 0-9: Sets the console log level, controlling which kernel messages are printed to the console.
Activation and Configuration
Before using Magic SysRq commands, verify that the feature is enabled on your system. This can often be done by checking or modifying kernel parameters. For example, to enable all functions, you can echo a value to /proc/sys/kernel/sysrq
:
1
echo 1 > /proc/sys/kernel/sysrq
Here’s the list of possible values in /proc/sys/kernel/sysrq
:
0
- disablesysrq
completely1
- enable all functions ofsysrq
>1
- bitmask of allowedsysrq
functions (see below for detailed function description):2
-0x2
- enable control of console logging level4
-0x4
- enable control of keyboard (SAK
,unraw
)8
-0x8
- enable debugging dumps of processes etc.16
-0x10
- enable sync command32
-0x20
- enable remount read-only64
-0x40
- enable signalling of processes (term
,kill
,oom-kill
)128
-0x80
- allow reboot/power-off256
-0x100
- allow nicing of all RT tasks