Linux Frozen? Recover and Troubleshoot System Issues with SysRq Commands

Linux SysRq commands are a lifesaver when your system freezes or becomes unresponsive. The kernel always responds to these commands, no matter what state the computer is in. However, if the kernel itself is completely locked up, that’s a different story. The SysRq feature is extremely useful when system issues occur. For example, if your Linux is frozen and stops responding to any input, you can use SysRq command to shut down or reboot the computer.
How to Enable SysRq#
If your kernel was compiled with SysRq support, you can enable/disable its functions via /proc/sys/kernel/sysrq
. The /proc/sys/kernel/sysrq
file may contain the following values:
0 - Completely disables SysRq
1 - Enables all SysRq functions
> 1 - bitmask of allowed SysRq functions
You can set values in this file using the following command:
echo NUMBER > /proc/sys/kernel/sysrq
Note that this file only controls keyboard-initiated SysRq usage. You can use any command via /proc/sysrq-trigger
, even if it’s not enabled in the aforementioned file.
How to Use SysRq#
- On x86 systems
ALT
+ SysRq
+<command key>
Note: Many keyboards don’t have a dedicated SysRq key. SysRq is often shared with the Print Screen key, typically labeled “Print Screen” on top and “SysRq” on the bottom.
- On any system
Write a <command key>
to the /proc/sysrq-trigger
file. For example:
echo b > /proc/sysrq-trigger
If you want to execute multiple commands, prefix them with _:
echo _reisub > /proc/sysrq-trigger
List of SysRq <command key>
functions#
-
b
- Immediately reboots the system without syncing or unmounting disks -
c
- Crashes the system to collect a crash dump (if configured) -
e
- SendsSIGTERM
to all processes exceptinit
-
f
- Invokes the OOM killer to kill memory-hogging processes -
h
- Shows help -
i
- SendsSIGKILL
to all processes exceptinit
-
k
- Secure Access Key (SAK) kills all programs on current virtual console -
o
- Powers off the computer -
r
- Turns off keyboard raw mode and setsXLATE
-
s
- Attempts to sync all mounted filesystems -
t
- Dumps a list of current tasks and their information to console -
u
- Attempts to remount all mounted filesystems as read-only -
w
- Dumps tasks that are in uninterruptible (blocked) state -
0-9
- Sets console log level, controlling which kernel messages appear -
R
- Replays kernel log messages to console
Practical applications#
-
r
- Useful when X server or any svgalib program crashes. -
k
- Secure Access Key (SAK) is useful to ensure no Trojan is running on the console, as it kills all programs on the current virtual console. This helps verify that the login prompt comes from genuineinit
rather than a Trojan. Because a Trojan can steal your password when logging in. It’s also used when a program (like X or svgalib) won’t release the console. -
b
,o
- Used when you can’t shut down the computer normally. -
c
- Crashes the system to collect crash dumps (if dump collection is configured). -
s
- Ensures data is written to disk. Useful before removing media or after using a rescue shell (if it lacks shutdown functionality). Note that sync isn’t complete until you see “OK” or “Done” on screen. -
Log levels
0-9
help when the console is flooded with non-critical kernel messages. Level 0 shows only the most critical messages (PANIC
andOOPS
). -
e
,i
- Useful when you can’t terminate a runaway process by other means. -
R
- This helps view kernel log messages when the system hangs or when you can’t use dmesg to read the printk buffer.
For more details about the SysRq Key, visit this link.
Source: The Linux Kernel Documentation