Content deleted Content added
RProgrammer (talk | contribs) m section links don't auto-update on renaming sections! that might be useful to add to wikipedia :) |
Filled in 1 bare reference(s) with reFill 2 |
||
(92 intermediate revisions by 61 users not shown) | |||
Line 1:
{{Short description|Keyboard commands for recovering a Linux machine}}
{{manual|date=June 2012}}▼
{{Redirect|Magic key|the TV series|The Magic Key}}
[[File:KeyboardWithPrintScreenRinged.svg|thumb|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 [[freeze (computing)|freeze]]s, or to [[booting|reboot]] a computer without corrupting the [[
| url=https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
| title=Linux Magic System Request Key Hacks
Line 8 ⟶ 10:
| publisher=[[kernel.org]]
| accessdate=2017-05-21
}}</ref>
This key combination provides access to
The magic SysRq key cannot work under certain conditions, such as a [[kernel panic]]<ref>{{Citation | url = http://www.unixmen.com/use-magic-sysrq-combination-key-to-recover-from-a-frozen-system-in-linux-ubuntu/ | last = Khamlichi | first = Mel | title = Use Magic SysRq Combination Key to Recover from a Frozen System in Linux | publisher = Unixmen | date = 18 Oct 2010 | accessdate = 21 Sep 2014 | archive-url = https://web.archive.org/web/20140820013821/http://www.unixmen.com/use-magic-sysrq-combination-key-to-recover-from-a-frozen-system-in-linux-ubuntu/ | archive-date = 20 August 2014 | url-status = dead }}.</ref> or a hardware failure preventing the kernel from running properly.
==
The Linux kernel contains <code>sysrq.c</code>,<ref>{{Cite web |title=linux/drivers/tty/sysrq.c at master · torvalds/linux |url=https://github.com/torvalds/linux/blob/master/drivers/tty/sysrq.c |access-date=2025-03-27 |website=GitHub |language=en}}</ref> which implements magic SysRq functionality. Magic SysRq functionality is called by serial devices<ref name=":1">{{Cite web |title=linux/drivers/usb/serial/generic.c at 6537cfb395f352782918d8ee7b7f10ba2cc3cbf2 · torvalds/linux |url=https://github.com/torvalds/linux/blob/6537cfb395f352782918d8ee7b7f10ba2cc3cbf2/drivers/usb/serial/generic.c#L574 |access-date=2025-03-27 |website=GitHub |language=en}}</ref><ref>{{Cite web |title=linux/include/linux/serial_core.h at 6537cfb395f352782918d8ee7b7f10ba2cc3cbf2 · torvalds/linux |url=https://github.com/torvalds/linux/blob/6537cfb395f352782918d8ee7b7f10ba2cc3cbf2/include/linux/serial_core.h#L1170 |access-date=2025-03-27 |website=GitHub |language=en}}</ref> at a low level in the driver code.
The key combination consists of {{key|[[Alt key| Alt]]|[[SysRq]]}} and another key, which controls the command issued. {{key|SysRq}} may be released before pressing the command key, as long as {{key|Alt}} remains held down.▼
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|R}} key instead of {{key|O}}. Furthermore, some keyboards may not provide a separate {{key|SysRq}} key. In this case, a separate {{key|[[PrintScrn|PrtScr]]}} key should be present.▼
▲The key combination consists of {{key|[[Alt key|
▲The combinations always assume the [[QWERTY]] keyboard layout
On some devices, notably laptops, the {{key|[[Fn key|Fn]]}} key may need to be pressed to use the magic {{key|SysRq}} key, e.g. on Thinkpad Carbon X1 the {{key|SysRq}} is activated by pressing {{key|[[Alt key|Alt]]|Fn|[[S]]}} simultaneously, then releasing {{key|Fn}} and {{key|S}} while still holding {{key|Alt}}.<ref>{{cite web |title=Alt+SysRq on a laptop |url=https://superuser.com/a/1237766 |website=Super User |access-date=25 July 2023 |language=en}}</ref>
The magic SysRq key may also be accessible from the serial console (by sending an [[Universal asynchronous receiver/transmitter#Break condition|RS-232 break signal]]) if the [[sysctl]] option is set to allow it.<ref>{{cite web | url = http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/security-sysrq.html | title = Magic SysRq key | work = Remote Serial Console How-To | first1 = Glen | last1 = Turner | first2 = Mark F | last2 = Komarinski | publisher = The Linux Documentation Project | date = 2003-03-31 | accessdate = 2015-05-08}} </ref>▼
SysRq functionalities can also be accessed without a keyboard. See {{section link||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 <code>/proc/sys/kernel/sysrq</code>.<ref>{{Cite web|url=https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html|title=Linux Magic System Request Key Hacks — The Linux Kernel documentation|website=www.kernel.org}}</ref>
{| class="wikitable"
|-
! Action
! [[QWERTY]]
! [[Dvorak
! [[AZERTY]]
! [[Colemak]]
|-
| Set the console log level, which controls the types of kernel messages that are output to the console
| {{key|0}}
| {{key|0}}
| {{key|0}}
| {{key|0}}
|-
| Immediately reboot the system, without unmounting or syncing filesystems
Line 56 ⟶ 59:
| {{key|s}}
|-
| Send the {{tt|[[SIGTERM]]}} signal to all processes except {{Tt|init}} ([[Process identifier|PID]] 1)
| {{key|e}}
| {{key|.}}
Line 68 ⟶ 71:
| {{key|t}}
|-
| When using [[
| {{key|g}}
| {{key|i}}
Line 80 ⟶ 83:
| {{key|h}}
|-
| Send the {{tt|[[SIGKILL]]}} signal to all processes except {{tt|init}} ([[Process identifier|PID]] 1)
| {{key|i}}
| {{key|c}}
Line 86 ⟶ 89:
| {{key|u}}
|-
| Forcibly "
| {{key|j}}
| {{key|h}}
Line 92 ⟶ 95:
| {{key|n}}
|-
| Kill all processes on the current virtual console (can kill X and
| {{key|k}}
| {{key|t}}
Line 110 ⟶ 113:
| {{key|m}}
|-
| Reset the [[nice (Unix)|nice]] level of all high-priority and [[Real-time computing
| {{key|n}}
| {{key|b}}
Line 130 ⟶ 133:
| Display all active high-resolution timers and clock sources.
| {{key|q}}
| {{key|
| {{key|a}}
| {{key|q}}
|-
| Switch the keyboard from raw mode, used by programs such as [[X11]] and [[SVGALib|SVGAlib]], to [[XLATE]] mode
| {{key|r}}
| {{key|p}}
Line 140 ⟶ 143:
| {{key|p}}
|-
| Sync all mounted
| {{key|s}}
| {{key|o}}
Line 152 ⟶ 155:
| {{key|g}}
|-
| Remount all mounted filesystems in [[File system permissions|
| {{key|u}}
| {{key|g}}
Line 170 ⟶ 173:
| {{key|w}}
|-
| Used by xmon interface on [[PowerPC]] platforms.<br />Show global PMU Registers on [[SPARC64 V|sparc64]].<br />Dump all [[Translation lookaside buffer|TLB]] entries on [[MIPS architecture|MIPS]].<ref>{{cite web|url=https://www.kernel.org/doc/Documentation/admin-guide/sysrq.rst|title=Linux Magic System Request Key Hacks|date=2021-09-13|access-date=2022-09-25}}</ref>
| {{key|x}}
| {{key|q}}
Line 188 ⟶ 191:
| {{key|z}}
|-
| Debug dump of BPF scheduler
| {{key|
| {{
| {{
| {{
|-
| Replay the kernel log messages on consoles
| {{key|R}}
| {{dunno}}
| {{dunno}}
| {{dunno}}
|-
| Disables the BPF scheduler and revert to CFS
| {{key|S}}
| {{dunno}}
| {{dunno}}
| {{dunno}}
|}
Example output of the {{key|SysRq|h}} command:
▲== Uses ==
<syntaxhighlight lang=text>
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)
</syntaxhighlight>
== Configuration ==
The feature is controlled both by a [[wikt:compile|compile]]-time option in the kernel configuration, {{tt|CONFIG_MAGIC_SYSRQ}},<ref name=":1" /> and a [[sysctl]] kernel parameter, {{tt|kernel.sysrq}}.
On newer kernels (since 2.6.12<ref>{{cite web
Line 219 ⟶ 225:
| last=Calleja
| publisher=Linux Kernel Newbies
| accessdate=2013-08-31}}
</ref>), it is possible to have more fine-grained control over how the magic SysRq key can be used.<ref>{{cite web | url=https://fedoraproject.org/wiki/QA/Sysrq
| title=QA/Sysrq
Line 226 ⟶ 233:
| accessdate=2015-04-09
}}</ref> On these machines, the number written to {{tt|/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 {{tt|/etc/sysctl.d/10-magic-sysrq.conf}} .
== Uses ==
Before the advent of [[journaled filesystem]]s 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).<ref>{{cite web | publisher = Kernel | work = Git | type = commit | url = https://lore.kernel.org/lkml/20190909183817.GB12602@angband.pl/T/#m11316a7c03c12e46d140fae9c670fa736f3d8ccf | title = Documentation: sysrq: don't recommend 'S' 'U' before 'B'| date = 2019-09-06}}</ref> The default value of ''kernel.sysrq'' in distributions such as Ubuntu and Debian remains 176{{citation needed|date=August 2024}} (allowing the sync, unmount, and reboot functions) and 438<ref>{{cite web|url = https://www.debian.org/doc/manuals/securing-debian-manual/restrict-sysrq.html |title=4.9. Restricting the use of the Magic SysRq key |work=Securing Debian Manual |access-date=August 20, 2024}}</ref> (allowing the same functions plus loglevel, unraw, and nice-all-RT-tasks) respectively.
Another past use was to kill a frozen [[display modes|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 {{tt|textmode}} command,{{clarify|reason=what exactly does this refer to?|date=August 2024}} the key sequence {{key|Ctrl|Alt|F1}} may be able to force a switch to a text console. Some systems may require use of {{key|F2}} or {{key|F3}} instead of {{key|F1}}.
== 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 [[procfs|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 {{tt|/proc/sysrq-trigger}} (e.g., {{code|echo s > /proc/sysrq-trigger}}).<ref name=":0" />
▲
| accessdate=2013-08-31}}</ref> provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The {{tt|hangwatch}}<ref>{{cite web | url= https://github.com/jumanjiman/hangwatch | title= hangwatch | first= Paul | last= Morgan | publisher = [[GitHub]] | accessdate = 2013-08-31}}</ref> daemon will invoke pre-configured SysRq triggers when system [[Load (computing)|load average]] exceeds a certain threshold.▼
▲The Linux daemons {{tt|sysrqd}}<ref>{{cite web | type = project | url= https://github.com/jd/sysrqd | title= sysrqd | first= Julien | last = Danjou | website= [[GitHub]] | accessdate= 2016-09-13}}</ref> and {{tt|tcpconsole}}<ref>{{cite web | url = http://www.vanheusden.com/tcpconsole/ | title = tcpconsole | first = Folkert | last = van Heusden | accessdate = 2013-08-31 | archive-date = 2017-08-31 | archive-url = https://web.archive.org/web/20170831173944/https://www.vanheusden.com/tcpconsole/ | url-status = dead }}</ref> provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The {{tt|hangwatch}}<ref>{{cite web | url= https://github.com/jumanjiman/hangwatch | title= hangwatch | first= Paul | last= Morgan | publisher = [[GitHub]] | accessdate = 2013-08-31}}</ref> daemon will invoke pre-configured SysRq triggers when system [[Load (computing)|load average]] exceeds a certain threshold.
The [[Xen]] hypervisor has functionality to send magic commands to hosted domains via its {{tt|xm sysrq}} command.<ref>{{Citation | url = https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/chap-Virtualization-The_xm_command_quick_reference.html | chapter = 27. The xm command quick reference | title = Enterprise Linux 5 Virtualization Guide | publisher = [[RedHat]] | accessdate= 2013-08-31}}</ref> Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence {{key|Ctrl|O}} followed by the desired key.▼
▲The [[Xen]] hypervisor has functionality to send magic commands to hosted domains via its {{tt|xm sysrq}} command.<ref>{{Citation | chapter-url = https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Virtualization/chap-Virtualization-The_xm_command_quick_reference.html | chapter = 27. The xm command quick reference | title = Enterprise Linux 5 Virtualization Guide | publisher = [[RedHat]] | accessdate= 2013-08-31}}</ref> Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence {{key|Ctrl|O}} followed by the desired key.
The [[Kernel-based Virtual Machine]] (KVM) hypervisor has functionality to send magic commands to hosted domains via its {{tt|virsh send-key}} command. <ref>{{Cite web | title=20.26. Sending a Keystroke Combination to a Specified Guest Virtual machine {{!}} Virtualization Deployment and Administration Guide {{!}} Red Hat Enterprise Linux {{!}} 7 {{!}} Red Hat Documentation | url=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 | access-date=2025-07-29 | website=docs.redhat.com}}</ref>
[[Chromebook]]s have a keyboard but no dedicated SysRq key. They use {{key|Alt|VolumeUp}} ({{key|Alt|F10}}) instead<ref>{{cite web | url = https://chromium.googlesource.com/chromiumos/docs/+/master/debug_buttons.md | title = Debug Button Shortcuts |website = Chromium OS docs | accessdate = 2018-10-22 }}</ref><ref>{{cite web | url = https://chromium-review.googlesource.com/#/c/29110/2/drivers/tty/sysrq.c | title = Change 29110: CHROMIUM: sysrq: treat F10 as magic sysrq key | accessdate = 2016-07-11 }}</ref><ref>{{cite web | url = https://groups.google.com/a/chromium.org/d/msg/chromium-os-dev/HnW8maLcDas/NJU1HFmE76kJ | title = Chromium OS dev: SysRq in ChromiumOS' kernel | accessdate = 2016-07-11}}</ref>, however some keys have a different function.<ref>{{cite web | url = https://sites.google.com/a/chromium.org/dev/chromium-os/how-tos-and-troubleshooting/debugging-hangs | title = Helping debug system hangs | website = The Chromium Projects | accessdate = 2018-09-25}}</ref><ref>{{cite web | url = https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/39527 | title = CHROMIUM: sysrq: add ability for sysrq-x to signal chrome/X | accessdate = 2018-04-12}}</ref>▼
eg:<br />
<syntaxhighlight lang=text>
virsh send-key --___domain domainname --keycode KEY_LEFTALT KEY_SYSRQ KEY_S</syntaxhighlight>
▲[[Chromebook]]s have a keyboard but no dedicated SysRq key. They use {{key|Alt|VolumeUp}} ({{key|Alt|F10}}) instead,<ref>{{cite web | url = https://chromium.googlesource.com/chromiumos/docs/+/master/debug_buttons.md | title = Debug Button Shortcuts |website = Chromium OS docs | accessdate = 2018-10-22 }}</ref><ref>{{cite web | url = https://chromium-review.googlesource.com/#/c/29110/2/drivers/tty/sysrq.c | title = Change 29110: CHROMIUM: sysrq: treat F10 as magic sysrq key | accessdate = 2016-07-11 }}</ref><ref>{{cite web | url = https://groups.google.com/a/chromium.org/d/msg/chromium-os-dev/HnW8maLcDas/NJU1HFmE76kJ | title = Chromium OS dev: SysRq in ChromiumOS' kernel | accessdate = 2016-07-11}}</ref>
IBM [[Power Systems]] servers can invoke the Magic SysRq feature using {{key|Ctrl|O}} followed by the desired key from the [[Hardware Management Console]].
IBM mainframe partitions can invoke the Magic SysRq feature using {{key|^|-}} followed by the desired key on [[IBM 3270|3270]] or HMC
== See also ==
Line 253 ⟶ 271:
== External links ==
{{
{{Commons category}}
* {{cite web | url=https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/sysrq.rst | title=Documentation/sysrq.txt | work = Linux | type = kernel source tree | publisher= [[kernel.org]] | accessdate= 2017-01-31}}
* {{cite web | url=https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html | title=Linux Magic System Request Key Hacks | work = Linux | type = linux kernel documentation | publisher= [[kernel.org]] | accessdate= 2020-06-01}}
* {{cite web | url=https://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.5/2.5.64/2.5.64-mm7/broken-out/proc-sysrq-trigger.patch | title= Kernel patch to the -mm tree that added the /proc/sysrq-trigger feature: This makes sysrq facilities available to remote users | author-link = Andrew Morton (computer programmer) | first = Andrew | last = Morton | date=2013-03-13 | accessdate= 2015-04-09}}
* {{cite web | work = AP Lawrence | url=http://aplawrence.com/Words2005/2005_04_13.html | title= Magic Sysrq Key on Linux | first= Tony | last= Lawrence | date= 2005-04-13 | accessdate= 2015-04-09}}
* {{cite web | url=http://www.ibm.com/developerworks/linux/library/l-magic.html | title= Magic sys request | publisher= [[IBM]] | work =
[[Category:Linux kernel features]]
[[Category:System administration]]
[[Category:Out-of-band management]]
|