Magic SysRq key

From Wikipedia, the free encyclopedia

The magic SysRq key is a key combination in the Linux kernel which, if the CONFIG_MAGIC_SYSRQ option was enabled at kernel compile time, allows the user to perform various low level commands regardless of the system's state using the SysRq key. It is often used to recover from freezes, or to reboot a computer without corrupting the filesystem.

Contents

[edit] Magic commands

The key combination consists of Alt, SysRq and another key, which controls the command issued (as shown in the table below). Users with a keyboard layout other than US have to remember that their layout becomes US when they use one of these combinations. For example, on a Dvorak keyboard, the key below '9' and '0' counts as a 'o', not as an 'r', so it shuts the system down instead of switching the keyboard to raw mode.

Action QWERTY DVORAK AZERTY
Set the console log level, which controls the types of kernel messages that are output to the console 0 through 9 0 through 9 0 through 9
(without using shift)
Immediately reboot the system, without unmounting partitions or syncing b x b
Reboot kexec and output a crashdump c j c
Send the SIGTERM signal to all processes except init (PID 1) e . e
Call oom_kill, which kills a process to alleviate an OOM condition f u f
Output a terse help document to the console
Any key which is not bound to a command should also do the trick
h d h
Send the SIGKILL signal to all processes except init i c i
Kill all processes on the current virtual console (Can be used to kill X and svgalib programs, see below)
This was originally designed to imitate a Secure Access Key
k t k
Send the SIGKILL signal to all processes, including init l n l
Output current memory information to the console m m ,
Shut off the system o r o
Output the current registers and flags to the console p l p
Switch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE mode r p r
Sync all mounted filesystems s o s
Output a list of current tasks and their information to the console t y t
Remount all mounted filesystems in read-only mode u g u
Output Voyager SMP processor information v k v

[edit] Command line access and configuration

If the machine is headless or is being accessed remotely, magic commands may be run on the command line. This is, however, contingent upon being able to shell into the machine. To run magic commands, echo the desired trigger code to the SysRq trigger in the procfs. For example:

echo b > /proc/sysrq-trigger

This is equivalent to the key combination Alt + SysRq + B which reboots the machine.

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

To enable or disable SysRq calls,

echo 0 > /proc/sys/kernel/sysrq
 
echo 1 > /proc/sys/kernel/sysrq

turn the calls off and on respectively. Selectively enabling commands is also possible.

Alternatively, an appropriate entry may be added to /etc/sysctl.conf on supported systems:

kernel.sysrq = 1

[edit] Remote access

The linux daemon sysrqd provides a method of accessing SysRq features over TCP/IP port 4094 after authenticating with a plain-text password.

[edit] Graphical programs

When magic SysRq keys are used to kill a frozen graphical program, the program has no chance to restore text mode. This can make everything unreadable. The commands textmode (part of SVGAlib) and reset can restore text mode and make the console readable again.

[edit] Raising Elephants

To perform a safe reboot of a Linux computer which has otherwise locked up, the QWERTY (or AZERTY) mnemonic "Raising Elephants Is So Utterly Boring", or simply remembering the word "BUSIER" backwards, is often useful. It stands for

   Raw (take control of keyboard back from X),
  tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
  kIll (send SIGKILL to all processes, forcing them to terminate immediately),
   Sync (flush data to disk),
   Unmount (remount all filesystems read-only),
reBoot. These keystrokes should be entered a few seconds apart.

This should prevent a fsck being required on reboot; it also gives some programs a chance to save emergency backups of unsaved work.

[edit] See also

Wikibooks
Wikibooks Linux Guide has a page on the topic of

[edit] External links