Configuring and Using the Linux Magic SysRq System Keys
[12345.678901] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
On QWERTY-layout keyboards, the SysRq function shares the PrintScreen key. To send a kernel command, press Alt+SysRq+<command-key>; on most laptops, this requires substituting Alt+Fn+PrtSc for the SysRq chord. These emergency shortcuts let you perform critical system operations even when the system is unresponsive, such as flushing filesystem buffers, terminating misbehaving processes, unmounting volumes, or rebooting the system.
Kernel Prerequisites
The Linux kernel must be compiled with the CONFIG_MAGIC_SYSRQ option enabled. Most modern Linux distributions enable this by default, but for custom-compiled kernels, verify the setting by checking your kernel config file:
grep CONFIG_MAGIC_SYSRQ /boot/config-$(uname -r)
A valid output will show CONFIG_MAGIC_SYSRQ=y. An additional kernel config option, CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE, sets a bitmask of allowed SysRq functions; the default value is typically 0x01b6.
Check Current SysRQ Allowance
To view the current allowed SysRq functions, read the /proc/sys/kernel/sysrq file:
cat /proc/sys/kernel/sysrq
This returns a numeric bitmask value. Each bit in the 9-bit value corresponds to a set of allowed functions:
| Bit Position | Value | Allowed Actions |
|---|---|---|
| 0 (LSB) | 1 | Enable all SysRq functions |
| 1 | 2 | Control console log levels |
| 2 | 4 | Use SAK and unraw keyboard commands |
| 3 | 8 | Dump process debugging information |
| 4 | 16 | Run filesystem sync operations |
| 5 | 32 | Remount filesystems as read-only |
| 6 | 64 | Send termination signals to processes |
| 7 | 128 | Reboot or power off the system |
| 8 (MSB) | 256 | Adjust real-time task priority |
For example, a value of 16 only allows filesystem sync operations, while a value of 130 (binary 10000010) allows console log level control and system reboot/poweroff.
Adjust SysRq Allowance
To temporari change the allowed SysRq functions, write the new bitmask value to the /proc/sys/kernel/sysrq file:
echo "176" | sudo tee /proc/sys/kernel/sysrq >/dev/null
Alternatively, use sysctl for the same temporary change:
sudo sysctl -w kernel.sysrq=176
To make this change persistent across reboots, add the configuration to your sysctl config file:
echo "kernel.sysrq = 176" | sudo tee -a /etc/sysctl.conf >/dev/null
Using SysRq Shortcuts
There are two ways to trigger SysRq commands:
- Keyboard Chord: Use the
Alt+SysRq+<command-key>(or laptop equivalent) shortcut - sysrq-trigger Interface: Write the command key to
/proc/sysrq-trigger(requires root privileges)
Example of using the trigger interface to immediately reboot the system:
echo "b" | sudo tee /proc/sysrq-trigger >/dev/null
Command keys vary slightly across keyboard layouts. Below is a reference table for common layouts:
| Action | QWERTY | Dvorak | AZERTY | Colemak |
|---|---|---|---|---|
| Set console log level | 0-9 | 0-9 | 0-9 (no Shift) | 0-9 |
| Immediately reboot | b | x | b | b |
| Trigger system crash | c | j | c | c |
| Show all active locks | d | e | d | s |
| Send SIGTERM to all non-init processes | e | . | e | f |
| Trigger OOM killer | f | u | f | t |
| Switch to kernel framebuffer console | g | i | g | d |
| Print help text | h | d | h | h |
| Send SIGKILL to all non-init processes | i | c | i | u |
| Freeze filesystems | j | h | j | n |
| Kill all processes in current virtual console | k | t | k | e |
| Show stack backtraces for all CPUs | l | n | l | i |
| Print memory usage stats | m | m | , | m |
| Reset real-time task nice levels | n | b | n | k |
| Power off system | o | r | o | y |
| Print CPU register state | p | l | p | ; |
| Show active high-resolution timers | q | ' | a | q |
| Switch keyboard to XLATE mode | r | p | r | p |
| Sync all mounted filesystems | s | o | s | r |
| Print full task list | t | y | t | g |
| Remount all filesystems read-only | u | g | u | l |
| Force framebuffer console recovery | v | k | v | v |
| Show blocked D-state tasks | w | , | z | w |
| PPC/xmon interface | x | q | x | x |
| SPARC-64 global CPU registers | y | f | y | j |
| Dump ftrace buffer | z | ; | w | z |
| Print help text (space key) | space | space | space | space |
Common Workflows
Safe System Reboot (R-E-I-S-U-B)
This sequence is the emergency equivalent of a clean reboot, and avoids filesystem corruption:
- R: Switch keyboard to XLATE mode to bypass X11 input capture
- E: Send SIGTERM to all non-init processes, allowing 30 seconds for graceful shutdown
- I: Send SIGKILL to force-terminate any remaining non-init processes, wait 10 seconds
- S: Sync filesystem buffers to disk, wait 10 seconds
- U: Remount all mounted filesystems as read-only, wait 10 seconds
- B: Immediately reboot the system
Recovering From a Hung System
Instead of a full rebooot, try these targeted recovery steps:
- F: Trigger the OOM killer to terminate a memory-heavy process (useful for out-of-memory hangs)
- K: Kill all processes attached to the current virtual console
- N: Reset nice levels for real-time and high-priority tasks to resolve CPU-bound hangs
Gathering System Diagnostic Info
Run these commands before attempting recovery to log system state:
- M: Print current memory utilization
- L: Show stack backtraces for all active CPUs
- P: Print current CPU register and flag state
- T: Print full list of running processes
- W: Show all blocked D-state tasks
Viewing SysRq Command Output
By default, all SysRq command output is logged to the system syslog facility. Output will also appear on the local console if the console loglevel is higher than the default kernel message level, or forwarded to a remote machine via netconsole. Note that if the system's syslog daemon is killed during an emergency, logs may not be saved.
To view the most recent SysRq output, use the dmesg command:
sudo dmesg | tail -n 10