Magic SysRq key

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Short description Script error: No such module "redirect hatnote". Script error: No such module "Unsubst".

File: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]

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.

Implementation

The Linux kernel contains sysrq.c,[3] which implements magic SysRq functionality. Magic SysRq functionality is called by serial devices[4][5] at a low level in the driver code.

Commands

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

The combinations always assume the QWERTY keyboard layoutScript error: No such module "Unsubst".. For example, on the Dvorak keyboard layout, the combination to shut down the system uses the Template:Key key instead of Template:Key. Furthermore, some keyboards may not provide a separate Template:Key key. In this case, a separate Template:Key key should be presentScript error: No such module "Unsubst"..

On some devices, notably laptops, the Template:Key key may need to be pressed to use the magic Template:Key key, e.g. on Thinkpad Carbon X1 the Template:Key is activated by pressing Template:Key simultaneously, then releasing Template:Key and Template:Key while still holding Template:Key.[6]

SysRq functionalities can also be accessed without a keyboard. See Template:Section link below. Note that some commands may be disabled out of the box as specified in the bitmask value in /proc/sys/kernel/sysrq.[7]

Action QWERTY Dvorak AZERTY Colemak
Set the console log level, which controls the types of kernel messages that are output to the console Template:Key - Template:Key Template:Key - Template:Key Template:Key - Template:Key
(without Template:Key)
Template:Key - Template:Key
Immediately reboot the system, without unmounting or syncing filesystems Template:Key Template:Key Template:Key Template:Key
Perform a system crash. A crashdump will be taken if it is configured. Template:Key Template:Key Template:Key Template:Key
Display all currently held Locks (Template:Tt kernel option is required) Template:Key Template:Key Template:Key Template:Key
Send the Template:Tt signal to all processes except Template:Tt (PID 1) Template:Key Template:Key Template:Key Template:Key
Call Template:Tt, which kills a process to alleviate an OOM condition Template:Key Template:Key Template:Key Template:Key
When using Kernel Mode Setting, switch to the kernel's framebuffer console.[8]
If the in-kernel debugger Template:Tt is present, enter the debugger.
Template:Key Template:Key Template:Key Template:Key
Output a terse help document to the console
Any key which is not bound to a command should also perform this action
Template:Key Template:Key Template:Key Template:Key
Send the Template:Tt signal to all processes except Template:Tt (PID 1) Template:Key Template:Key Template:Key Template:Key
Forcibly "just thaw it" – filesystems frozen by the Template:Tt ioctl. Template:Key Template:Key Template:Key Template:Key
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
Template:Key Template:Key Template:Key Template:Key
Shows a stack backtrace for all active CPUs. Template:Key Template:Key Template:Key Template:Key
Output current memory information to the console Template:Key Template:Key Template:Key Template:Key
Reset the nice level of all high-priority and real-time tasks Template:Key Template:Key Template:Key Template:Key
Shut off the system Template:Key Template:Key Template:Key Template:Key
Output the current registers and flags to the console Template:Key Template:Key Template:Key Template:Key
Display all active high-resolution timers and clock sources. Template:Key Template:Key Template:Key Template:Key
Switch the keyboard from raw mode, used by programs such as X11 and SVGAlib, to XLATE mode Template:Key Template:Key Template:Key Template:Key
Sync all mounted filesystems Template:Key Template:Key Template:Key Template:Key
Output a list of current tasks and their information to the console Template:Key Template:Key Template:Key Template:Key
Remount all mounted filesystems in read-only mode Template:Key Template:Key Template:Key Template:Key
Forcefully restores framebuffer console.
For ARM processors, cause ETM buffer dump instead.
Template:Key Template:Key Template:Key Template:Key
Display list of blocked (D state) tasks Template:Key Template:Key Template:Key Template:Key
Used by xmon interface on PowerPC platforms.
Show global PMU Registers on sparc64.
Dump all TLB entries on MIPS.[9]
Template:Key Template:Key Template:Key Template:Key
Show global CPU registers (SPARC-64 specific) Template:Key Template:Key Template:Key Template:Key
Dump the ftrace buffer Template:Key Template:Key Template:Key Template:Key
Debug dump of BPF scheduler Template:Key ? ? ?
Replay the kernel log messages on consoles Template:Key ? ? ?
Disables the BPF scheduler and revert to CFS Template:Key ? ? ?

Example output of the Template:Key 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) dump-sched-ext(D) replay-kernel-logs(R) reset-sched-ext(S)

Configuration

The feature is controlled both by a compile-time option in the kernel configuration, Template:Tt,[4] and a sysctl kernel parameter, Template:Tt.

On newer kernels (since 2.6.12[10]), it is possible to have more fine-grained control over how the magic SysRq key can be used.[11] On these machines, the number written to Template:Tt 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 Template:Tt .

Uses

Before the advent of journaled filesystems a common use of the magic SysRq key was to perform a safe reboot of a locked-up Linux computer (using the sequence of key presses indicated by the mnemonic REISUB), which lessened the risk of filesystem corruption. With modern filesystems, syncing and unmounting is still useful to force unflushed data to disk, but is no longer necessary to prevent filesystem corruption (and may increase the risk of corruption in case the lock-up is caused by the kernel being in a bad state).[12] The default value of kernel.sysrq in distributions such as Ubuntu and Debian remains 176Script error: No such module "Unsubst". (allowing the sync, unmount, and reboot functions) and 438[13] (allowing the same functions plus loglevel, unraw, and nice-all-RT-tasks) respectively.

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

On distributions that do not include a Template:Tt command,Template:Clarify the key sequence Template:Key may be able to force a switch to a text console. Some systems may require use of Template:Key or Template:Key instead of Template:Key.

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 Template:Tt (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.[14]

The Linux daemons Template:Tt[15] and Template:Tt[16] provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The Template:Tt[17] 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 Template:Tt command.[18] Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence Template:Key followed by the desired key.

The Kernel-based_Virtual_Machine (KVM) hypervisor has functionality to send magic commands to hosted domains via its Template:Tt command. [19] eg:

virsh send-key --domain domainname --keycode KEY_LEFTALT KEY_SYSRQ KEY_S

Chromebooks have a keyboard but no dedicated SysRq key. They use Template:Key (Template:Key) instead,[20][21][22] however some keys have a different function.[23][24]

IBM Power Systems servers can invoke the Magic SysRq feature using Template:Key followed by the desired key from the Hardware Management Console.

IBM mainframe partitions can invoke the Magic SysRq feature using Template:Key followed by the desired key on 3270 or HMC.

See also

References

Template:Reflist

External links

Template:Sister project Template:Sister project

  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  • Script error: No such module "citation/CS1".
  1. a b Script error: No such module "citation/CS1".
  2. Script error: No such module "citation/CS1"..
  3. Script error: No such module "citation/CS1".
  4. a b Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. Script error: No such module "citation/CS1".
  7. Linux Magic System Request Key Hacks — The Linux Kernel documentation
  8. Script error: No such module "citation/CS1".
  9. Script error: No such module "citation/CS1".
  10. Script error: No such module "citation/CS1".
  11. Script error: No such module "citation/CS1".
  12. Script error: No such module "citation/CS1".
  13. Script error: No such module "citation/CS1".
  14. Script error: No such module "citation/CS1".
  15. Script error: No such module "citation/CS1".
  16. Script error: No such module "citation/CS1".
  17. Script error: No such module "citation/CS1".
  18. Script error: No such module "citation/CS1".
  19. https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-editing_a_guest_virtual_machines_configuration_file-sending_keystoke_combinations_to_a_specified_domain
  20. Script error: No such module "citation/CS1".
  21. Script error: No such module "citation/CS1".
  22. Script error: No such module "citation/CS1".
  23. Script error: No such module "citation/CS1".
  24. Script error: No such module "citation/CS1".