{{Short description|Keyboard commands for recovering a Linux machine}} {{Redirect|Magic key|the TV series|The Magic Key}} {{how-to|date=June 2012}} [[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 freezes, or to reboot a computer without corrupting the file system.<ref name=":0">{{cite web | url=https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html | title=Linux Magic System Request Key Hacks | date=2013-08-12 | publisher=kernel.org | accessdate=2017-05-21 }}</ref>

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<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.

== Implementation == 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.

== Commands == The key combination consists of {{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<ref>{{Cite web |title=Magic SysRq key |url=https://linuxreviews.org/Magic_SysRq_key#Commands |access-date=2026-04-11 |website=LinuxReviews |language=en}}</ref>. For example, on the Dvorak keyboard layout, the combination to shut down the system 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|PrtScn}} key should be present<ref>{{Cite web |title=Linux Magic System Request Key Hacks — The Linux Kernel documentation |url=https://www.kernel.org/doc/html/next/admin-guide/sysrq.html#how-do-i-use-the-magic-sysrq-key |access-date=2026-04-11 |website=www.kernel.org}}</ref>.

On some devices, notably laptops, the {{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|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>

A complete list of commands is available in the official [https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html Linux Kernel Documentation on Linux Magic System Request Key Hacks].

== Configuration == The feature is controlled both by a 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 | url=http://kernelnewbies.org/Linux_2_6_12 | title=Linux 2.6.12 | date=2012-07-17 | first=Diego | 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 | date=2013-05-09 | publisher=Fedora Project | 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 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).<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 graphical program, as the X Window System used to have complete control over the graphical mode and input devices.

== 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 {{tt|/proc/sysrq-trigger}} (e.g., {{code|echo s > /proc/sysrq-trigger}}).<ref name=":0" />

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.<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>

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 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 | 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> eg:<br /> <syntaxhighlight lang=text> virsh send-key --domain domainname --keycode KEY_LEFTALT KEY_SYSRQ KEY_S</syntaxhighlight>

Chromebooks 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>

Some Dell Laptops require the following sequence<ref>{{cite web | url = https://www.dell.com/community/en/conversations/linux-general/how-to-generate-sysrq-key-combos-on-dell-xps-7390/647f8596f4ccf8a8de47f448?commentId=647f9d21f4ccf8a8de15fd2a | title = how to generate SysRq key combos on Dell XPS 7390 {{!}} DELL Technologies | accessdate = 2026-03-16}}</ref>:

# Sequentially press & hold {{key|Alt|Fn|R}} # Release {{key|Fn|R}} # While still holding {{key|Alt}}, press the desired key e.g., {{key|H}}

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 3270 or HMC.

== See also == * Stop-A, key sequence used to access Sun Microsystems's Open Firmware (OpenBoot) * Console server * KVM switch * System console

== References == {{reflist|30em}}

== External links == {{Wikibooks|Linux Guide|Freezes}} {{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 = 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}}

Category:Linux kernel features Category:System administration Category:Out-of-band management