Linux SysRq Key — How to Rescue a Frozen Server
The Magic SysRq key (SysRq, System Request) lets you send low-level commands directly to the kernel, bypassing userspace entirely. It works as long as the kernel itself is still running — even when SSH is dead, the GUI is frozen, and nothing else responds. It is the standard way to safely reboot a hung system without a hard reset.
How to Enable and Use SysRq
For security reasons, this feature is limited by default on many distributions. Full control is enabled using sysctl.
-
Check the status:
cat /proc/sys/kernel/sysrqA value of
1means all functions are enabled. Other values (e.g.,176) mean that only some, safer commands are allowed. -
Enable full functionality (temporarily):
sudo sysctl -w kernel.sysrq=1 -
Enable it permanently: Add an entry to the
/etc/sysctl.conffile (or a file in/etc/sysctl.d/):kernel.sysrq = 1
How to trigger the commands?
-
On a physical machine (with a keyboard): Hold down the
Alt+SysRqkeys (often the same key asPrint Screen), and then press the key corresponding to the command (e.g.,bfor reboot).Alt+SysRq+b -
On a remote machine (via SSH or console): We don’t have a physical keyboard, so we use the
echocommand to write the command letter to a special file in/proc:echo b | sudo tee /proc/sysrq-trigger
The Most Important SysRq Commands: The R-E-I-S-U-B Sequence
The most famous use of SysRq is to safely reboot a frozen system. Instead of a “hard” reset, we execute a sequence of commands that minimizes the risk of data loss. It’s easy to remember with the mnemonic “Raising Elephants Is So Utterly Boring” (or, in a less polite version, “Reboot Even If System Utterly Broken”).
Execute each command, waiting a few seconds in between:
-
R -
echo r > /proc/sysrq-trigger- Raw: Switches the keyboard from
XLATEmode to raw mode, taking control away from things like the X.org graphical server. The first step to regaining control.
- Raw: Switches the keyboard from
-
E -
echo e > /proc/sysrq-trigger- End: Sends the
SIGTERMsignal to all processes (exceptinit), asking them to terminate gracefully.
- End: Sends the
-
I -
echo i > /proc/sysrq-trigger- Interrupt: Sends the
SIGKILLsignal to all processes (exceptinit), brutally killing them. This is in case they didn’t listen to the polite request.
- Interrupt: Sends the
-
S -
echo s > /proc/sysrq-trigger- Sync: Synchronizes all mounted filesystems. It writes all data from buffers to the disk. This is a crucial step to prevent data loss!
-
U -
echo u > /proc/sysrq-trigger- Unmount: Remounts all filesystems in read-only mode. This is an additional safeguard against data corruption during the reboot.
-
B -
echo b > /proc/sysrq-trigger- Boot: Immediately reboots the system, without unmounting filesystems or syncing (but we already did that in steps
sandu). It’s the equivalent of pressing the “Reset” button.
- Boot: Immediately reboots the system, without unmounting filesystems or syncing (but we already did that in steps
Other useful commands
h- Help: Displays a list of available commands in the kernel log (dmesg).m- Memory: Displays information about memory usage.t- Tasks: Shows a list of currently running tasks (processes).f- Full (OOM): Invokes the “OOM killer” (Out-of-Memory killer) to kill the most memory-intensive process. Useful when the system has frozen due to lack of memory.
Enable kernel.sysrq=1 on servers and memorize the REISUB sequence — it can prevent data loss when a hard reset would be the only other option.