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. Its effect is similar to the computer's hardware reset button (or power switch) but with many more options and much more control.
This key combination provides access to powerful features 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 the Dvorak keyboard layout, the combination to shut down the system uses the R key instead of O. Furthermore, some keyboards may not provide a separate SysRq key. In this case, a separate PrtScn key should be present.
On some devices, notably laptops, the Fn key may need to be pressed to use the magic SysRq key, e.g. on Thinkpad Carbon X1 the SysRq is activated by pressing Alt+Fn+S simultaneously, then releasing Fn and S while still holding Alt (see here). On a ChromeOS device press Alt+Volume Up (F10)+<key>.
SysRq functionalities can also be accessed without a keyboard. See § Other ways to invoke Magic SysRq below. Note that some commands may be disabled out of the box as specified in the bitmask value in
|Set the console log level, which controls the types of kernel messages that are output to the console||0 - 9||0 - 9||0 - 9
(without ⇧ Shift)
|0 - 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, switch to the kernel's framebuffer console.
If the in-kernel debugger kdb is present, enter the debugger.
|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 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, 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.
For ARM processors, cause ETM buffer dump instead.
|Display list of blocked (D state) tasks||w||,||z||w|
|Used by xmon interface on PowerPC platforms. Disables lockdown (Secure Boot restrictions) on some kernels.||x||q||x||x|
|Show global CPU registers (SPARC-64 specific)||y||f||y||j|
|Dump the ftrace buffer||z||;||w||z|
Output of the SysRq+h on a x86_64 kernel:
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)
Before the advent of journaled filesystems a common use of the magic SysRq key was to perform a safe reboot of a Linux computer which has otherwise locked up (abbr. REISUB), which avoided a risk of filesystem corruption. With modern filesystems, this practice is discouraged, offering no upsides over straight reBoot.
On distributions that do not include a textmode command, the key command Ctrl+Alt+F1 may sometimes be able to force a return to a text console. (Use F1, F2, F3, ... , Fn, 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.) There are also distributions where Ctrl+Alt + (F3, ... ,F(n-2)) opens text consoles, Ctrl+Alt+F1 reenter GUI mode, Ctrl+Alt+F2 reenter GUI mode on the login page, in order to log in another user.
On newer kernels (since 2.6.12), it is possible to have more fine-grained control over how the magic SysRq key can be used. On these machines, the number written to /proc/sys/kernel/sysrq can be 0, 1, or a number greater than 1 which is a bitmask indicating which features to allow. On Ubuntu this is set at boot time to the value defined in /etc/sysctl.d/10-magic-sysrq.conf .
Other ways to invoke Magic SysRqEdit
While the magic SysRq key 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. From user space programs (such as a command line shell), SysRq may be accessed by writing to /proc/sysrq-trigger (e.g.,
echo s > /proc/sysrq-trigger).
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 serial break signal, 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. A sysctl option needs to be set to enable this function.
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.
The Xen hypervisor has functionality to send magic commands to hosted domains via its xm sysrq command. Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence Ctrl+O followed by the desired key.
IBM mainframe partitions can invoke the Magic SysRq feature using ^+- followed by the desired key on 3270 or HMC console.
- "Linux Magic System Request Key Hacks". kernel.org. 2013-08-12. Retrieved 2017-05-21.
- Khamlichi, Mel (18 Oct 2010), Use Magic SysRq Combination Key to Recover from a Frozen System in Linux, Unixmen, archived from the original on 20 August 2014, retrieved 21 Sep 2014.
- Linux Magic System Request Key Hacks — The Linux Kernel documentation
- Barnes, Jesse (2008-11-07). "DRM: i915: add mode setting support". Git (commit). Kernel. 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 2015-04-09.
- Turner, Glen; Komarinski, Mark F (2003-03-31). "Magic SysRq key". Remote Serial Console How-To. The Linux Documentation Project. Retrieved 2015-05-08.
- Danjou, Julien. "sysrqd" (project). Retrieved 2016-09-13.
- van Heusden, Folkert. "tcpconsole". Retrieved 2013-08-31.
- Morgan, Paul. "hangwatch". GitHub. Retrieved 2013-08-31.
- "27. The xm command quick reference", Enterprise Linux 5 Virtualization Guide, RedHat, retrieved 2013-08-31
- "Debug Button Shortcuts". Chromium OS docs. Retrieved 2018-10-22.
- "Change 29110: CHROMIUM: sysrq: treat F10 as magic sysrq key". Retrieved 2016-07-11.
- "Chromium OS dev: SysRq in ChromiumOS' kernel". Retrieved 2016-07-11.
- "Helping debug system hangs". The Chromium Projects. Retrieved 2018-09-25.
- "CHROMIUM: sysrq: add ability for sysrq-x to signal chrome/X". Retrieved 2018-04-12.
- "Documentation/sysrq.txt". Linux (kernel source tree). kernel.org. Retrieved 2017-01-31.
- "Linux Magic System Request Key Hacks". Linux (linux kernel documentation). kernel.org. Retrieved 2020-06-01.
- Morton, Andrew (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 2015-04-09.
- Lawrence, Tony (2005-04-13). "Magic Sysrq Key on Linux". AP Lawrence. Retrieved 2015-04-09.
- Gall, Tom (2000-04-01). "Magic sys request". Developer works. IBM. Archived from the original on 2007-05-27. Retrieved 2013-09-03.