BOoRFGOnZ 发表于 2009-4-23 14:01:01

Magic SysRq key

The magic SysRq key is a key combination in the Linux kernel which 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.
To be able to use this functionality the CONFIG_MAGIC_SYSRQ option has to be enabled at kernel compile time.
Contents
[*]1 Purpose[*]2 Magic commands[*]3 Common usage[*]3.1 Command line access and configuration[*]3.2 Remote access[*]3.3 Graphical programs[*]3.4 In hypervisors[*]4 "Raising Elephants" mnemonic device[*]5 Security concerns[*]6 See also[*]7 External links[*]8 References
[edit] PurposeMuch like the Sun Microsystems Open Firmware,this key combination provides the ability to have access to powerfultools for software development and disaster recovery. In this sense, itcan be considered a form of escape sequence.Principal among the offered commands are options to forcibly unmountfile systems, kill processes, recover keyboard state, and writeunwritten data to disk. With respect to these tasks, they provide atool of last resort.

[edit] Magic commandsThe 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 QWERTY have to remember that their layout becomes QWERTY when they use one of these combinations. For example, on a Dvorakkeyboard, the key below '9' and '0' counts as a 'o', not as an 'r', soit shuts the system down instead of switching the keyboard to raw mode.Furthermore, some keyboards may not provide a separate SysRq key. In this case, a separate "Print" key should be present. The AltGr key, if present, can be used in place of Alt keyin order to avoid alternative uses of these combinations such asScreenshot for Alt+SysRq+s under Gnome. It also can be accessed fromthe serial console.
ActionQWERTYDvorakAZERTYSet the console log level, which controls the types of kernel messages that are output to the console0 through 90 through 90 through 9
(without using shift)Immediately reboot the system, without unmounting partitions or syncingbxbReboot kexec and output a crashdumpcjcDisplay all currently held LocksdedSend the SIGTERM signal to all processes except init (PID 1)e.eCall oom_kill, which kills a process to alleviate an OOM conditionfufWhen using Kernel Mode Setting, provides emergency support for switching back to the kernel's framebuffer consolegigOutput a terse help document to the console
Any key which is not bound to a command should also do the trickhdhSend the SIGKILL signal to all processes except initiciKill 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 KeyktkShow a stack backtrace of all currently executing taskslnlOutput current memory information to the consolemm,Reset the nice level of all high-priorty and real-time tasksnbnShut off the systemoroOutput the current registers and flags to the consoleplpDisplay all active high-resolution timers and clock sources.q'aSwitch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE moderprSync all mounted filesystemssosOutput a list of current tasks and their information to the consoletytRemount all mounted filesystems in read-only modeuguOutput Voyager SMP processor informationvkvDisplay list of blocked (D state) tasksw,z
[edit] Common usage
[edit] Command line access and configurationWhile this was originally implemented as part of the kernel'skeyboard handler for debugging, the functionality has been also exposedvia the proc filesystemand are commonly used to provide extended management capabilities toheadless and remote systems. As an example, shell script can be simplyused:
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. This can be accessed through the proc filesystem as well, e.g.:
echo 1 > /proc/sys/kernel/sysrq


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

[edit] Graphical programsWhen 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] In hypervisorsThe Xen hypervisor has functionality to send magic commands to hosted domains via its "xm" command.

[edit] "Raising Elephants" mnemonic deviceA common idiom 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", "Reboot Even If System Utterly Broken" or simply remembering the word "BUSIER" backwards, is often useful. It stands for
unRaw      (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.
This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work.
Another common version of this mnemonic device is "Raising SkinnyElephants Is Utterly Boring", which performs the same task, but in analternate order. There is debate regarding whether the Sync commandshould come earlier or later.
Wait a few seconds between each command. For example, manyapplications will do an emergency save on receiving SIGTERM, but ifSIGKILL is sent too soon, the application will not have time. Likewise,the Sync and Unmount processes need a few seconds before the system isrebooted.

[edit] Security concernsSome people view this key as giving access to dangerous system-levelcommands to anyone who has physical access to the keyboard or serialconsole.It has been argued that this perceived security is illusory, as anyonewith physical access to the computer would already have the capabilityto compromise its security. The advent of the procfs interface has rekindled debate over this subject.

[edit] See alsohttp://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Wikibooks-logo-en-noslogan.svg/40px-Wikibooks-logo-en-noslogan.svg.pngThe Wikibook Linux Guide has a page on the topic ofFreezes
[*]Console server[*]KVM switch[*]Power distribution unit[*]System console
[edit] External links[*]Documentation/sysrq.txt in the Linux kernel source tree[*]Original kernel patch to the -mm tree adding the /proc/sysrq-trigger feature[*]General notes on magic sysrq[*]Magic sys request
[edit] References[*]^ http://lxr.linux.no/linux/Documentation/sysrq.txt[*]^ http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/index.html[*]^ DRM: i915: add mode setting support[*]^ http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.2/html/Virtualization/sect-Virtualization-Commands_for_Red_Hat_Virtualization-The_xm_command_line_interface.html[*]^ http://fosswire.com/2007/09/08/fix-a-frozen-system-with-the-magic-sysrq-keys/[*]^ http://linuxgazette.net/issue81/vikas.html[*]^ http://lkml.indiana.edu/hypermail/linux/kernel/9806.1/0737.html

jiangtao9999 发表于 2009-4-23 14:12:49

BS 楼主总是无脑的复制粘贴。

тролль 发表于 2009-4-23 17:02:03

:P

тролль 发表于 2009-4-23 17:03:13

不过还是很有用的。

тролль 发表于 2009-4-23 17:03:37

我是说SysRq,不是说lz所有的复制文章。
页: [1]
查看完整版本: Magic SysRq key