![KeyboardWithPrintScreenRinged](https://upload.wikimedia.org/wikipedia/commons/2/22/KeyboardWithPrintScreenRinged.svg)
The magic SysRq key is a key combination understood by the
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
, 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
In computing, rebooting is the process by which a running computer system is restarted, either intentionally or unintentionally. Reboots can be either a cold reboot (alternatively known as a hard reboot) in which the power to the system is physi ...
a computer without corrupting the
filesystem
In computing, file system or filesystem (often abbreviated to fs) is a method and data structure that the operating system uses to control how data is stored and retrieved. Without a file system, data placed in a storage medium would be one larg ...
.
Its effect is similar to the computer's hardware
reset button
In electronics and technology, a reset button is a button that can reset a device. On video game consoles, the reset button restarts the game, forfeiting the player's unsaved progress. On personal computers,On IBM mainframes reset neither cl ...
(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
In computer science, an escape sequence is a combination of characters that has a meaning other than the literal characters contained therein; it is marked by one or more preceding (and possibly terminating) characters.
Examples
* In C and man ...
. 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 magic SysRq key cannot work under certain conditions, such as a
kernel panic
A kernel panic (sometimes abbreviated as KP) is a safety measure taken by an operating system's kernel upon detecting an internal fatal error in which either it is unable to safely recover or continuing to run the system would have a higher ...
or a hardware failure preventing the kernel from running properly.
Commands
The key combination consists of and another key, which controls the command issued. may be released before pressing the command key, as long as remains held down.
The combinations always assume the
QWERTY
QWERTY () is a keyboard layout for Latin-script alphabets. The name comes from the order of the first six Computer keyboard keys#Types, keys on the top left letter row of the keyboard ( ). The QWERTY design is based on a layout created f ...
keyboard layout; for example, on the
Dvorak keyboard layout
Dvorak is a keyboard layout for English patented in 1936 by August Dvorak and his brother-in-law, William Dealey, as a faster and more ergonomic alternative to the QWERTY layout (the ''de facto'' standard keyboard layout). Dvorak proponent ...
, the combination to shut down the system uses the key instead of . Furthermore, some keyboards may not provide a separate key. In this case, a separate key should be present.
On some devices, notably laptops, the key may need to be pressed to use the magic key, e.g. on Thinkpad Carbon X1 the is activated by pressing simultaneously, then releasing and while still holding
see here. On a ChromeOS device press .
SysRq functionalities can also be accessed without a keyboard. See below. Note that some commands may be disabled out of the box as specified in the
bitmask
In computer science, a mask or bitmask is data that is used for bitwise operations, particularly in a bit field. Using a mask, multiple bits in a byte, nibble, word, etc. can be set either on or off, or inverted from on to off (or vice versa) in ...
value in
/proc/sys/kernel/sysrq
.
Output of the 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)
Uses
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 not encouraged, offering no upsides over straight reoot, though the default value of ''kernel.sysrq'' in such distributions as Ubuntu and Debian remains 176 and 438 respectively.
Another past use was to kill a frozen
graphical
Graphics () are visual images or designs on some surface, such as a wall, canvas, screen, paper, or stone, to inform, illustrate, or entertain. In contemporary usage, it includes a pictorial representation of data, as in design and manufacture ...
program, as the
X Window System
The X Window System (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.
X provides the basic framework for a GUI environment: drawing and moving windows on the display device and interacting wit ...
used to have complete control over graphical mode and input devices.
On distributions that do not include a command, the key command may sometimes be able to force a return to a text console. (Use , , , ... , , where is the highest number of text consoles set up by the distribution. would normally be used to reenter GUI mode on a system on which the X server has not crashed.) There are also distributions where + (, ... ,) opens text consoles, reenter GUI mode, reenter GUI mode on the login page, in order to log in another user.
Configuration
The feature is controlled both by a
compile
In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
-time option in the kernel configuration, , and a
sysctl
sysctl is a software utility of some Unix-like operating systems that reads and modifies the attributes of the system kernel such as its version number, maximum limits, and security settings. It is available both as a system call for compiled ...
kernel parameter, .
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 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 .
Other ways to invoke Magic SysRq
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 (e.g., ).
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
sysctl is a software utility of some Unix-like operating systems that reads and modifies the attributes of the system kernel such as its version number, maximum limits, and security settings. It is available both as a system call for compiled ...
option needs to be set to enable this function.
The Linux daemons and provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The daemon will invoke pre-configured SysRq triggers when system
load average exceeds a certain threshold.
The
Xen
Xen (pronounced ) is a type-1 hypervisor, providing services that allow multiple computer operating systems to execute on the same computer hardware concurrently. It was
originally developed by the University of Cambridge Computer Laboratory an ...
hypervisor has functionality to send magic commands to hosted domains via its command. Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence followed by the desired key.
Chromebook
A Chromebook (sometimes stylized in lowercase as chromebook) is a laptop or tablet running the Linux-based ChromeOS as its operating system. Initially designed to heavily rely on web applications for tasks using the Google Chrome browser, Chromeb ...
s have a keyboard but no dedicated SysRq key. They use () instead, however some keys have a different function.
IBM
Power Systems
An electric power system is a network of electrical components deployed to supply, transfer, and use electric power. An example of a power system is the electrical grid that provides power to homes and industries within an extended area. The e ...
servers can invoke the Magic SysRq feature using followed by the desired key from the
Hardware Management Console {{Refimprove, date=October 2020
Hardware Management Console (HMC) is a Physical / Virtual appliance used to manage IBM Systems including IBM AS/400, IBM System p, IBM System z, and IBM Power Systems. HMC supports command line (ssh) as well as web ...
.
IBM mainframe partitions can invoke the Magic SysRq feature using followed by the desired key on
3270 or HMC console.
See also
*
Stop-A, key sequence used to access
Sun Microsystems
Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, the ...
's
Open Firmware
Open Firmware is a standard defining the interfaces of a computer firmware system, formerly endorsed by the Institute of Electrical and Electronics Engineers (IEEE). It originated at Sun Microsystems, where it was known as OpenBoot, and has bee ...
(OpenBoot)
*
Console server
A terminal server connects devices with a serial port to a local area network (LAN). Products marketed as terminal servers can be very simple devices that do not offer any security functionality, such as data encryption and user authentication. ...
*
KVM switch
A KVM switch (with KVM being an abbreviation for "keyboard, video, and mouse") is a hardware device that allows a user to control multiple computers from one or more sets of keyboards, video monitors, and mice.
Name
Switches to connect mu ...
*
System console
One meaning of system console, computer console, root console, computer operator, operator's console, or simply console is the text entry and display device for system administration messages, particularly those from the BIOS or boot loader, the ...
References
External links
*
*
*
*
*{{cite web , url=http://www.ibm.com/developerworks/linux/library/l-magic.html , title= Magic sys request , publisher=
IBM , work =
Developer works , first= Tom , last= Gall , date= 2000-04-01 , archiveurl= https://web.archive.org/web/20070527215139/http://www.ibm.com/developerworks/linux/library/l-magic.html , archivedate= 2007-05-27 , url-status= dead , accessdate= 2013-09-03
Mnemonics
Linux kernel features
System administration
Out-of-band management