ArticleslgStudy

science

Magic SysRq key

Magic SysRq key is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Magic SysRq key rather than just read about it. In short: The magic SysRq ("System Request") 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.

Magic SysRq key — main illustration
Magic SysRq key — illustration

Key takeaways

  • Magic SysRq key belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Magic SysRq key to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Magic SysRq key from memory before moving on to harder problems.

Reference excerpt

The magic SysRq ("System Request") 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. 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 or a hardware failure preventing the kernel from running properly.

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

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

Example output of the SysRq+h command:

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), 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 /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 .

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). The default value of kernel.sysrq in distributions such as Ubuntu and Debian remains 176 (allowing the sync, unmount, and reboot functions) and 438 (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 /proc/sysrq-trigger (e.g., echo s > /proc/sysrq-trigger). 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. The Linux daemons sysrqd and tcpconsole provide a method of accessing SysRq features over a TCP connection after authenticating with a plain-text password. The hangwatch 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. Additionally, a SysRq command can be invoked from a Xen paravirtual console by sending a break sequence 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 virsh send-key command. eg:

Chromebooks have a keyboard but no dedicated SysRq key. They use Alt+VolumeUp (Alt+F10) instead, however some keys have a different function. Some Dell Laptops require the following sequence:

Sequentially press & hold Alt+Fn+R Release Fn+R While still holding Alt, press the desired key e.g., H 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.

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

References

External links

"Documentation/sysrq.txt". Linux (kernel source tree). kernel.org. Retrieved 2017-01-31. "Linux Magic System Request Key Hacks". Linux (linux kernel documentation). kernel.org. Retrieved 2020-06-01. Morton, Andrew (2013-03-13). "Kernel patch to the -mm tree that added the /proc/sysrq-trigger feature: This makes sysrq facilities available to remote users". Retrieved 2015-04-09. Lawrence, Tony (2005-04-13). "Magic Sysrq Key on Linux". AP Lawrence. Retrieved 2015-04-09. Gall, Tom (2000-04-01). "Magic sys request". Developer works. IBM. Archived from the original on 2007-05-27. Retrieved 2013-09-03.

Worked examples

Example 1 — a first encounter with Magic SysRq key

Start with the simplest possible case. Write down what Magic SysRq key claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Magic SysRq key before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Magic SysRq key ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Magic SysRq key

In research
Magic SysRq key appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Magic SysRq key in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Magic SysRq key is common in secondary-school and first-year university syllabi. It links to neighbouring topics Linux kernel features, Out-of-band management, System administration, so understanding it makes those chapters shorter.
In everyday life
Look for Magic SysRq key outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Magic SysRq key in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Magic SysRq key means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Magic SysRq key out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Magic SysRq key in simple terms?

The magic SysRq ("System Request") 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.

Why does Magic SysRq key matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Magic SysRq key?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Magic SysRq key.

Tags

  • Linux kernel features
  • Out-of-band management
  • System administration

Keep exploring