The SysRq key is a powerful tool for system recovery and debugging. As long as the kernel is not completely frozen, it will respond to SysRq key combinations, allowing you to collect system information such as memory usage, CPU task handling, and process states.
Configuration
To use SysRq, you must enable the CONFIG_MAGIC_SYSRQ
option in your kernel configuration. After booting, this will create the /proc/sysrq-trigger
node for debugging purposes.
Enable SysRq by adding the following line to /etc/sysctl.conf
: kernel.sysrq=1
Run the following command to apply the changes:
sysctl -p
You can also enable SysRq temporarily by writing a value to echo "number"
/proc/sys/kernel/sysrq
. Different values enable specific features:
Value | Description |
---|---|
0 | Disable SysRq completely |
1 | Enable all SysRq functions |
2 | Enable control of console logging level |
4 | Enable keyboard control (SAK, unraw) |
8 | Enable process debugging dumps |
16 | Enable the sync command |
32 | Enable remounting filesystems as read-only |
64 | Enable sending signals to processes (term, kill, oom-kill) |
128 | Enable reboot/power off |
256 | Enable real-time task priority adjustment |
How to Use SysRq
To use SysRq, echo a command key to the /proc/sysrq-trigger
node:
echo <command key> > /proc/sysrq-trigger
The <command key>
is case-sensitive.
The available command keys are listed below:
Command Key | Function |
---|---|
|
Immediately reboots the system without syncing or unmounting disks. |
|
Performs a system crash, triggering a crash dump if configured. |
|
Displays all held locks. |
|
Sends a SIGTERM signal to all processes except init. |
|
Calls the OOM killer to terminate a memory-intensive process. It will not cause a panic if no process is killed. |
|
Used by kgdb (kernel debugger). |
|
Displays help text. Any key not listed here will also show help. |
|
Sends a SIGKILL signal to all processes except init. |
|
Forcibly thaws filesystems frozen by the FIFREEZE ioctl. |
|
Secure Access Key (SAK): Kills all programs on the current virtual console. |
|
Shows a stack backtrace for all active CPUs. |
|
Dumps current memory information to the console. |
|
Resets the priority of all real-time tasks to normal. |
|
Shuts down the system (if configured and supported). |
|
Dumps the current registers and flags to the console. |
|
Dumps information about all armed high-resolution timers and clock event devices for each CPU. |
|
Switches the keyboard from raw mode to XLATE mode. |
|
Attempts to sync all mounted filesystems. |
|
Dumps a list of current tasks and their information to the console. |
|
Attempts to remount all mounted filesystems as read-only. |
|
Forcibly restores the framebuffer console. |
|
Dumps tasks that are in an uninterruptible (blocked) state. |
|
Used for xmon on ppc/powerpc. Shows global PMU registers on sparc64. Dumps all tlb entries on MIPS. |
|
Displays global CPU registers (SPARC-64 only). |
|
Dumps the ftrace buffer. |
|
Sets the console log level, which controls which kernel messages are printed to the console (e.g., '0' will only show emergency messages like PANICs or OOPSes). |
Summary
SysRq is a well-established feature for safely handling system hangs and performing reboots.