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.

  1. Check the status:

    cat /proc/sys/kernel/sysrq
    

    A value of 1 means all functions are enabled. Other values (e.g., 176) mean that only some, safer commands are allowed.

  2. Enable full functionality (temporarily):

    sudo sysctl -w kernel.sysrq=1
    
  3. Enable it permanently: Add an entry to the /etc/sysctl.conf file (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 + SysRq keys (often the same key as Print Screen), and then press the key corresponding to the command (e.g., b for reboot). Alt + SysRq + b

  • On a remote machine (via SSH or console): We don’t have a physical keyboard, so we use the echo command 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:

  1. R - echo r > /proc/sysrq-trigger

    • Raw: Switches the keyboard from XLATE mode to raw mode, taking control away from things like the X.org graphical server. The first step to regaining control.
  2. E - echo e > /proc/sysrq-trigger

    • End: Sends the SIGTERM signal to all processes (except init), asking them to terminate gracefully.
  3. I - echo i > /proc/sysrq-trigger

    • Interrupt: Sends the SIGKILL signal to all processes (except init), brutally killing them. This is in case they didn’t listen to the polite request.
  4. 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!
  5. 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.
  6. B - echo b > /proc/sysrq-trigger

    • Boot: Immediately reboots the system, without unmounting filesystems or syncing (but we already did that in steps s and u). It’s the equivalent of pressing the “Reset” button.

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.