Magic SysRq key
||This article's lead section may not adequately summarize key points of its contents. (June 2012)|
||This article is written like a manual or guidebook. (June 2012)|
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.
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.
The combinations always assume the QWERTY keyboard layout; for example, on a Dvorak Simplified Keyboard, the combination to shut the system down uses the key labelled R instead of O. Furthermore, some keyboards may not provide a separate SysRq key. In this case, a separate "PrintScrn" key should be present.
Under graphical environments (such as GNOME or KDE) 'Alt'+'PrintScrn/SysRq'+key combination generally only leads to a screenshot being dumped. To avoid this Print Screen feature the magic SysRq combination should include the Ctrl, becoming 'Ctrl'+'Alt'+'SysRq'+key. For the same purposes the AltGr key, if present, can be used in place of the Alt key. On some laptops SysRq is accessible only by pressing 'Fn'. In this case the combination is a bit trickier: hold 'Alt', hold 'Fn', hold 'SysRq', release 'Fn', press key. The magic SysRq can also be accessed from the serial console.
|Set the console log level, which controls the types of kernel messages that are output to the console||0 through 9||0 through 9||0 through 9
(without using shift)
|0 through 9|
|Immediately reboot the system, without unmounting or syncing filesystems||b||x||b||b|
|Perform a system crash. A crashdump will be taken if it is configured.||c||j||c||c|
|Display all currently held Locks (CONFIG_LOCKDEP kernel option is required)||d||e||d||s|
|Send the SIGTERM signal to all processes except init (PID 1)||e||.||e||f|
|Call oom_kill, which kills a process to alleviate an OOM condition||f||u||f||t|
|When using Kernel Mode Setting, provides emergency support for switching back to the kernel's framebuffer console If the in-kernel debugger 'kdb' is present, enter the debugger.||g||i||g||d|
|Output a terse help document to the console
Any key which is not bound to a command should also perform this action
|Send the SIGKILL signal to all processes except init||i||c||i||u|
|Forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl.||j||h||j||n|
|Kill all processes on the current virtual console (Can be used to kill X and svgalib programs, see below)
This was originally designed to imitate a secure attention key
|Shows a stack backtrace for all active CPUs.||l||n||l||i|
|Output current memory information to the console||m||m||,||m|
|Reset the nice level of all high-priority and real-time tasks||n||b||n||k|
|Shut off the system||o||r||o||y|
|Output the current registers and flags to the console||p||l||p||;|
|Display all active high-resolution timers and clock sources.||q||'||a||q|
|Switch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE mode||r||p||r||p|
|Sync all mounted filesystems||s||o||s||r|
|Output a list of current tasks and their information to the console||t||y||t||g|
|Remount all mounted filesystems in read-only mode||u||g||u||l|
|Forcefully restores framebuffer console, except for ARM processors, where this key causes ETM buffer dump||v||k||v||v|
|Display list of blocked (D state) tasks||w||,||z||w|
|Used by xmon interface on PPC/PowerPC platforms.||x||q||x||x|
|Show global CPU registers (SPARC-64 specific)||y||f||y||j|
|Dump the ftrace buffer||z||;||w||z|
A common use of the magic SysRq key is to perform a safe reboot of a Linux computer which has otherwise locked up. This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work. The QWERTY (or AZERTY) mnemonics: "Raising Elephants Is So Utterly Boring", "Reboot Even If System Utterly Broken" or simply the word "BUSIER" read backwards, are often used to remember the following Sysrq-keys sequence:
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.
- Hold down the Alt and SysRq (Print Screen) keys.
- While holding those down, type the following keys in order, several seconds apart: REISUB
- Computer should reboot.
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.
When magic SysRq keys are used to kill a frozen graphical program, the program has no chance to restore text mode. This can make everything unreadable. The commands
textmode (part of SVGAlib) and
reset can restore text mode and make the console readable again.
On distributions that do not include a
textmode executable, the key command 'Ctrl'+'Alt'+'F1' may sometimes to force a return to a text console. (Use 'F1', 'F2', 'F3', ..., 'F(n)', where 'n' is the highest number of text consoles set up by the distribution. 'Ctrl'+'Alt'+ 'F(n+1)' would normally be used to reenter GUI mode on a system on which the X server has not crashed.)
The feature is controlled both by a compile-time option in the kernel configuration, CONFIG_MAGIC_SYSRQ, and a sysctl kernel parameter, kernel.sysrq. To be able to use this functionality the
CONFIG_MAGIC_SYSRQ option has to be enabled at kernel compile time.
The SysRq key can be disabled with the following command:
echo 0 > /proc/sys/kernel/sysrq
echo 1 > /proc/sys/kernel/sysrq
On newer kernels (since 2.6.12), it is possible to have a more fine-grained control. On these machines, the number written to /proc/sys/kernel/sysrq can be zero, one, or a number greater than one which is a bitmask indicating which features to allow.
Possible values are:
- 0 - disable SysRq
- 1 - enable SysRq completely
- >1 - bitmask of enabled SysRq functions:
- 2 - control of console logging level
- 4 - control of keyboard (SAK, unraw)
- 8 - debugging dumps of processes etc.
- 16 - sync command
- 32 - remount read-only
- 64 - signalling of processes (term, kill, oom-kill)
- 128 - reboot/poweroff
- 256 - nicing of all RT tasks
Alternate ways to invoke Magic SysRq
While this was originally implemented as part of the kernel's keyboard handler for debugging, the functionality has been also exposed via the proc filesystem and is commonly used to provide extended management capabilities to headless and remote systems. As an example, shell script can be simply used:
echo b > /proc/sysrq-trigger
This is equivalent to the key combination Alt+SysRq+B which reboots the machine.
The Linux daemons sysrqd and tcpconsole provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The hangwatch daemon will invoke pre-configured sysrq triggers when system load average exceeds a certain threshold.
Many embedded systems have no attached keyboard, but instead use a serial console for text input/output to the running system. It is possible to invoke a Magic SysRq feature over a serial console by sending a 'break' serial command, followed by the desired key. The method of sending a break is dependent on the terminal program or hardware used to connect to the serial console.
For minicom, a popular serial terminal program, the command sequence: 'ctrl-a f' will initiate a break sequence. So the command: 'ctrl-a f m' would show memory information about the system.
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.
Situations when the Magic SysRq key does not work
- When init is successfully killed with a SEGV (Segmentation Fault) Signal.
- After any kernel panic.
- When there is a (hardware or software) failure and the kernel is no longer running correctly even if it doesn't show a kernel panic.
- When the magic SysRq key combination is pressed with the command "c", it will cause a kernel panic (no subsequent commands will be possible after that) or when the following equivalent command is executed in a command-line:
# echo c > /proc/sysrq-trigger
- "Linux Magic System Request Key Hacks". kernel.org. 2013-08-12. Retrieved 2013-08-31.
- Turner, Glen; Komarinski, Mark F. (2003-03-31). "Remote Serial Console HOWTO". Retrieved 2013-08-31.
- Barnes, Jesse (2008-11-07). "DRM: i915: add mode setting support". Retrieved 2013-08-31.
- Peddicord, Jacob (2007-09-08). "Fix a Frozen System with the Magic SysRq Keys". fosswire.com. Retrieved 2013-08-31.
- Calleja, Diego (2012-07-17). "Linux 2.6.12". Linux Kernel Newbies. Retrieved 2013-08-31.
- "QA/Sysrq". Fedora Project. 2013-05-09. Retrieved 2013-08-31.
- Danjou, Julien. "sysrqd". Retrieved 2013-08-31.
- van Heusden, Folkert. "tcpconsole". Retrieved 2013-08-31.
- Morgan, Paul. "hangwatch". Retrieved 2013-08-31.
- "Chapter 27. The xm command quick reference". Red Hat Enterprise Linux Virtualization Guide. RedHat. Retrieved 2013-08-31.
- P, Vikas G (August 2002). "SysRq: The Process-nuke". Linux Gazette (81). Retrieved 2013-08-31.
- Harris, Mike A. (1998-06-12). "Re: Speaking of SysRQ...". Linux Kernel Mailinglist. Retrieved 2013-08-31.
- Khamlichi, Mel. "Use Magic SysRq Combination Key to Recover from a Frozen System in Linux." Www.unixmen.com. N.p., 18 Oct. 2010. Web. 21 Sept. 2014.
|The Wikibook Linux Guide has a page on the topic of: Freezes|
- "Documentation/sysrq.txt in the Linux kernel source tree". kernel.org. Retrieved 2013-09-03.
- Andrew Morton (2013-03-13). "Kernel patch to the -mm tree that added the /proc/sysrq-trigger feature: This makes sysrq facilities available to remote users.". Retrieved 2013-09-03.
- Lawrence, Tony (2005-04-13). "Magic Sysrq Key on Linux". Retrieved 2013-92-03. Check date values in: