QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2901|回复: 4

Magic SysRq key

[复制链接]
发表于 2009-4-23 14:01:01 | 显示全部楼层 |阅读模式
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.[1]
To be able to use this functionality the CONFIG_MAGIC_SYSRQ option has to be enabled at kernel compile time.
Contents [hide]

[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.[2]
ActionQWERTYDvorakAZERTY
Set 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 syncingbxb
Reboot kexec and output a crashdumpcjc
Display all currently held Locksded
Send the SIGTERM signal to all processes except init (PID 1)e.e
Call oom_kill, which kills a process to alleviate an OOM conditionfuf
When using Kernel Mode Setting, provides emergency support for switching back to the kernel's framebuffer console[3]gig
Output a terse help document to the console
Any key which is not bound to a command should also do the trick
hdh
Send the SIGKILL signal to all processes except initici
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
ktk
Show a stack backtrace of all currently executing taskslnl
Output current memory information to the consolemm,
Reset the nice level of all high-priorty and real-time tasksnbn
Shut off the systemoro
Output the current registers and flags to the consoleplp
Display all active high-resolution timers and clock sources.q'a
Switch the keyboard from raw mode, the mode used by programs such as X11 and svgalib, to XLATE moderpr
Sync all mounted filesystemssos
Output a list of current tasks and their information to the consoletyt
Remount all mounted filesystems in read-only modeugu
Output Voyager SMP processor informationvkv
Display 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.[4]

[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.[5] 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.[6]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.[7] The advent of the procfs interface has rekindled debate over this subject.

[edit] See also
The Wikibook Linux Guide has a page on the topic ofFreezes

[edit] External links
[edit] References
发表于 2009-4-23 14:12:49 | 显示全部楼层
BS 楼主总是无脑的复制粘贴。
回复

使用道具 举报

发表于 2009-4-23 17:02:03 | 显示全部楼层
	
回复

使用道具 举报

发表于 2009-4-23 17:03:13 | 显示全部楼层
不过还是很有用的。
回复

使用道具 举报

发表于 2009-4-23 17:03:37 | 显示全部楼层
我是说SysRq,不是说lz所有的复制文章。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-3-29 16:52 , Processed in 0.048130 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表