Magic SysRq key

Last updated
The SysRq key KeyboardWithPrintScreenRinged.svg
The 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. [1] Its effect is similar to the computer's hardware reset button (or power switch) but with many more options and much more control.

Contents

This key combination provides access to features for 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.

The magic SysRq key cannot work under certain conditions, such as a kernel panic [2] or a hardware failure preventing the kernel from running properly.

Commands

The key combination consists of Alt + SysRq and another key, which controls the command issued. SysRq may be released before pressing the command key, as long as Alt remains held down.

The combinations always assume the QWERTY keyboard layout;[ citation needed ] 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. [3] On a ChromeOS device, SysRq is activated by pressing 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 /proc/sys/kernel/sysrq. [4]

Action QWERTY Dvorak AZERTY Colemak
Set the console log level, which controls the types of kernel messages that are output to the console0 - 90 - 90 - 9
(without ⇧ Shift)
0 - 9
Immediately reboot the system, without unmounting or syncing filesystemsbxbb
Perform a system crash. A crashdump will be taken if it is configured.cjcc
Display all currently held Locks (CONFIG_LOCKDEP kernel option is required)deds
Send the SIGTERM signal to all processes except init (PID 1)e.ef
Call oom_kill, which kills a process to alleviate an OOM conditionfuft
When using Kernel Mode Setting, switch to the kernel's framebuffer console. [5]
If the in-kernel debugger kdb is present, enter the debugger.
gigd
Output a terse help document to the console
Any key which is not bound to a command should also perform this action
hdhh
Send the SIGKILL signal to all processes except initiciu
Forcibly "just thaw it" – filesystems frozen by the FIFREEZE ioctl.jhjn
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
ktke
Shows a stack backtrace for all active CPUs.lnli
Output current memory information to the consolemm,m
Reset the nice level of all high-priority and real-time tasksnbnk
Shut off the systemoroy
Output the current registers and flags to the consoleplp;
Display all active high-resolution timers and clock sources.q'aq
Switch the keyboard from raw mode, used by programs such as X11 and SVGAlib, to XLATE moderprp
Sync all mounted filesystemssosr
Output a list of current tasks and their information to the consoletytg
Remount all mounted filesystems in read-only modeugul
Forcefully restores framebuffer console.
For ARM processors, cause ETM buffer dump instead.
vkvv
Display list of blocked (D state) tasksw,zw
Used by xmon interface on PowerPC platforms.
Show global PMU Registers on sparc64.
Dump all TLB entries on MIPS. [6]
xqxx
Show global CPU registers (SPARC-64 specific)yfyj
Dump the ftrace bufferz;wz

Example output of the SysRq+h command:

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 reboot, [7] though the default value of kernel.sysrq in such distributions as Ubuntu and Debian remains 176 and 438 [8] respectively.

Another past use was to kill a frozen graphical program, as the X Window System used to have complete control over graphical mode and input devices.

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.

Configuration

The feature is controlled both by a compile-time option in the kernel configuration, CONFIG_MAGIC_SYSRQ, and a sysctl kernel parameter, kernel.sysrq.

On newer kernels (since 2.6.12 [9] ), it is possible to have more fine-grained control over how the magic SysRq key can be used. [10] 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 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 /proc/sysrq-trigger (e.g., echo s > /proc/sysrq-trigger). [1]

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. [11]

The Linux daemons sysrqd [12] and tcpconsole [13] provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The hangwatch [14] 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. [15] Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence Ctrl+O followed by the desired key.

Chromebooks have a keyboard but no dedicated SysRq key. They use Alt+VolumeUp (Alt+F10) instead, [16] [17] [18] however some keys have a different function. [19] [20]

IBM Power Systems servers can invoke the Magic SysRq feature using Ctrl+O followed by the desired key from the Hardware Management Console.

IBM mainframe partitions can invoke the Magic SysRq feature using ^+- followed by the desired key on 3270 or HMC console.

See also

Related Research Articles

The Break key of a computer keyboard refers to breaking a telegraph circuit and originated with 19th century practice. In modern usage, the key has no well-defined purpose, but while this is the case, it can be used by software for miscellaneous tasks, such as to switch between multiple login sessions, to terminate a program, or to interrupt a modem connection.

The keyboard for IBM PC-compatible computers is standardized. However, during the more than 30 years of PC architecture being frequently updated, many keyboard layout variations have been developed.

<span class="mw-page-title-main">Scroll Lock</span> Computer key

Scroll Lock is a lock key on most IBM-compatible computer keyboards.

System Request is a key on personal computer keyboards that has no standard use. Introduced by IBM with the PC/AT, it was intended to be available as a special key to directly invoke low-level operating system functions with no possibility of conflicting with any existing software. A special BIOS routine – software interrupt 0x15, subfunction 0x85 – was added to signal the OS when SysRq was pushed or released. Unlike most keys, when it is pressed nothing is stored in the keyboard buffer.

AmigaDOS is the disk operating system of the AmigaOS, which includes file systems, file and directory manipulation, the command-line interface, and file redirection.

In computing, a loadable kernel module (LKM) is an object file that contains code to extend the running kernel, or so-called base kernel, of an operating system. LKMs are typically used to add support for new hardware and/or filesystems, or for adding system calls. When the functionality provided by an LKM is no longer required, it can be unloaded in order to free memory and other resources.

A secure attention key (SAK) or secure attention sequence (SAS) is a special key or key combination to be pressed on a computer keyboard before a login screen which must, to the user, be completely trustworthy. The operating system kernel, which interacts directly with the hardware, is able to detect whether the secure attention key has been pressed. When this event is detected, the kernel starts the trusted login processing.

9P is a network protocol developed for the Plan 9 from Bell Labs distributed operating system as the means of connecting the components of a Plan 9 system. Files are key objects in Plan 9. They represent windows, network connections, processes, and almost anything else available in the operating system.

<span class="mw-page-title-main">Menu key</span> Button on Windows-oriented computer keyboards

In computing, the menu key or application key is a key previously found on Microsoft Windows-oriented computer keyboards. It was introduced at the same time as the Windows logo key. On keyboards including the key, its symbol would usually be a small icon depicting a pointer hovering above a menu; it would typically be found on the right side of the keyboard between the right Windows logo key and the right control key. While the Windows key is present on the vast majority of keyboards intended for use with the Windows operating system, the menu key was frequently omitted in the interest of space, particularly on portable and laptop keyboards.

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory. Typically, it is mapped to a mount point named /proc at boot time. The proc file system acts as an interface to internal data structures about running processes in the kernel. In Linux, it can also be used to obtain information about the kernel and to change certain kernel parameters at runtime (sysctl).

sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel's device model to user space through virtual files. In addition to providing information about various devices and kernel subsystems, exported virtual files are also used for their configuration.

sysctl Unix-like software that manages kernel attributes

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 programs, and an administrator command for interactive use and scripting. Linux additionally exposes sysctl as a virtual file system.

In computing, a keyboard shortcut is a sequence or combination of keystrokes on a computer keyboard which invokes commands in software.

The TCP window scale option is an option to increase the receive window size allowed in Transmission Control Protocol above its former maximum value of 65,535 bytes. This TCP option, along with several others, is defined in RFC 7323 which deals with long fat networks (LFNs).

debugfs is a special file system available in the Linux kernel since version 2.6.10-rc3. It was written by Greg Kroah-Hartman.

dm-crypt is a transparent block device encryption subsystem in Linux kernel versions 2.6 and later and in DragonFly BSD. It is part of the device mapper (dm) infrastructure, and uses cryptographic routines from the kernel's Crypto API. Unlike its predecessor cryptoloop, dm-crypt was designed to support advanced modes of operation, such as XTS, LRW and ESSIV, in order to avoid watermarking attacks. In addition to that, dm-crypt addresses some reliability problems of cryptoloop.

<span class="mw-page-title-main">Linux console</span> Console of the Linux kernel

The Linux console is a system console internal to the Linux kernel. A system console is the device which receives all kernel messages and warnings and which allows logins in single user mode. The Linux console provides a way for the kernel and other processes to send text output to the user, and to receive text input from the user. The user typically enters text with a computer keyboard and reads the output text on a computer monitor. The Linux kernel supports virtual consoles – consoles that are logically separate, but which access the same physical keyboard and display. The Linux console are implemented by the VT subsystem of the Linux kernel, and do not rely on any user space software. This is in contrast to a terminal emulator, which is a user space process that emulates a terminal, and is typically used in a graphical display environment.

printk is a C function from the Linux kernel interface that prints messages to the kernel log. It accepts a string parameter called the format string, which specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string. The string is then printed to the kernel log.

Control-Alt-Delete is a computer keyboard command on IBM PC compatible computers, invoked by pressing the Delete key while holding the Control and Alt keys: Ctrl+Alt+Delete. The function of the key combination differs depending on the context but it generally interrupts or facilitates interrupting a function. For instance, in pre-boot environment or in MS-DOS, Windows 3.0 and earlier versions of Windows or OS/2, the key combination reboots the computer. Starting with Windows 95, the key combination invokes a task manager or security related component that facilitates ending a Windows session or killing a frozen application.

vnStat Free network utility for the Linux operating system

vnStat is a network utility for the Linux operating system. It uses a command line interface. vnStat command is a console-based network traffic monitor. It keeps a log of hourly, daily and monthly network traffic for the selected interface(s) but is not a packet sniffer. The traffic information is analyzed from the proc filesystem. That way vnStat can be used even without root permissions.

References

  1. 1 2 "Linux Magic System Request Key Hacks". kernel.org. 2013-08-12. Retrieved 2017-05-21.
  2. 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.
  3. "Alt+SysRq on a laptop". Super User. Retrieved 25 July 2023.
  4. Linux Magic System Request Key Hacks — The Linux Kernel documentation
  5. Barnes, Jesse (2008-11-07). "DRM: i915: add mode setting support". Git (commit). Kernel. Retrieved 2013-08-31.
  6. "Linux Magic System Request Key Hacks". 2021-09-13. Retrieved 2022-09-25.
  7. "Documentation: sysrq: don't recommend 'S' 'U' before 'B'". Git (commit). Kernel. 2019-09-06.
  8. url = https://www.debian.org/doc/manuals/securing-debian-manual/restrict-sysrq.html
  9. Calleja, Diego (2012-07-17). "Linux 2.6.12". Linux Kernel Newbies. Retrieved 2013-08-31.
  10. "QA/Sysrq". Fedora Project. 2013-05-09. Retrieved 2015-04-09.
  11. Turner, Glen; Komarinski, Mark F (2003-03-31). "Magic SysRq key". Remote Serial Console How-To. The Linux Documentation Project. Retrieved 2015-05-08.
  12. Danjou, Julien. "sysrqd". GitHub (project). Retrieved 2016-09-13.
  13. van Heusden, Folkert. "tcpconsole". Archived from the original on 2017-08-31. Retrieved 2013-08-31.
  14. Morgan, Paul. "hangwatch". GitHub . Retrieved 2013-08-31.
  15. "27. The xm command quick reference", Enterprise Linux 5 Virtualization Guide, RedHat , retrieved 2013-08-31
  16. "Debug Button Shortcuts". Chromium OS docs. Retrieved 2018-10-22.
  17. "Change 29110: CHROMIUM: sysrq: treat F10 as magic sysrq key" . Retrieved 2016-07-11.
  18. "Chromium OS dev: SysRq in ChromiumOS' kernel" . Retrieved 2016-07-11.
  19. "Helping debug system hangs". The Chromium Projects. Retrieved 2018-09-25.
  20. "CHROMIUM: sysrq: add ability for sysrq-x to signal chrome/X" . Retrieved 2018-04-12.