Magic SysRq key

The magic SysRq key is a key combination understood by the Linux kernel, which allows the user to perform various low level commands regardless of the system’s state. It is often used to recover from freezes, or to reboot a computer without corrupting the filesystem.

To be able to use this functionality the CONFIG_MAGIC_SYSRQ option has to be enabled at kernel compile time.

Purpose

Much like Sun Microsystems’s Open Firmware (OpenBoot), this key combination provides access to powerful tools for software development and disaster recovery. In this sense, it can be considered a form of escape sequence. Principal among the offered commands are means to forcibly unmount file systems, kill processes, recover keyboard state, and write unwritten data to disk. With respect to these tasks, this feature serves as a tool of last resort.

Magic commands


The key combination consists of Alt, SysRq and another key, which controls the command issued (as shown in the table below). Users with a keyboard layout other than QWERTY have to remember that their layout becomes QWERTY when they use one of these combinations. For example, on a Dvorak keyboard, the key below ‘9’ and ‘0’ counts as a ‘o’, not as an ‘r’, so it shuts the system down instead of switching the keyboard to raw mode. Furthermore, some keyboards may not provide a separate SysRq key. In this case, a separate “Print” key should be present. Under graphical environments (such as Gnome or KDE) ‘Alt’+’PrintScrn/SysRq’+key combination generally only leads to a screenshot to be dumped. To avoid this Print Screen feature the magic SysRq combination should be additionally prefixed by Ctrl, becoming ‘Ctrl’+’Alt’+’SysRq’+key. For the same purposes the AltGr key, if present, can be used in place of Alt key. The magic SysRq can also be accessed from the serial console.

action key
Set the console log level, which controls the types of kernel messages that are output to the console 0 through 9
Immediately reboot the system, without unmounting partitions or syncing b
Reboot kexec and output a crashdump c
Display all currently held Locks d
Send the SIGTERM signal to all processes except init (PID 1) e
Call oom_kill, which kills a processes except ini (PID1) f
When using Kernel Mode Setting, provides emergency support for switching back to the kernel’s framebuffer console g
Output a terse help document to the console.
Any key which is not bound to a command should also do the trick
h
Send the SIGKILL signal to all processes except init i
Kill all process on the current viritual console (Can be used to kill X and svgalib programs)
This was originallu desingned to imitate a Secure Access Key
k
Output current memory information to the console m
Reset the nice level of all high priority and real-time task n
Shut off the system o
Output the current registers and flags to the console p
Display all active high-resolution timers and clock sources q
Switch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE mode r
Sync all mounted filesystems s
Output all list of current task and their information to the console t
Remount all mounted filesytems in read-only mode u
Output Voyager SMP processor information v
Display list of blocked (D state) task w

“Raising Elephants” mnemonic device
A common idiom to perform a safe reboot of a Linux computer which has otherwise locked up, the QWERTY (or AZERTY) mnemonic “Raising Elephants Is So Utterly Boring”, “Reboot Even If System Utterly Broken” or simply remembering the word “BUSIER” backwards, is often useful. It stands for

unRaw (take control of keyboard back from X),
tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
kIll (send SIGKILL to all processes, forcing them to terminate immediately),
Sync (flush data to disk),
Unmount (remount all filesystems read-only),
reBoot.

This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work.

In practice, each command may require a few seconds to complete, especially if feedback is unavailable from the screen due to a freeze or display corruption. For example, sending SIGKILL to processes which have not yet finished terminating can cause data loss.

Security concerns

Some people view this key as giving access to dangerous system-level commands to anyone who has physical access to the keyboard or serial console. It has been argued that this perceived security is illusory, as anyone with physical access to the computer would already have the capability to compromise its security. The advent of the procfs interface has rekindled debate over this subject.

Disabling SysRq key

The SysRq key can be disabled with the following command:

echo 0 > /proc/sys/kernel/sysrq

to re-enable:

echo 1 > /proc/sys/kernel/sysrq

source

share and enjoy.

Leave a comment


Subscribe Scroll to Top
Get Adobe Flash player