1 Linux Magic System Request Key Hacks 2 ==================================== 3 4 Documentation for sysrq.c 5 6 What is the magic SysRq key? 7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 9 It is a 'magical' key combo you can hit which 10 regardless of whatever else it is doing, unles 11 12 How do I enable the magic SysRq key? 13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14 15 You need to say "yes" to 'Magic SysRq key (CON 16 configuring the kernel. When running a kernel 17 /proc/sys/kernel/sysrq controls the functions 18 the SysRq key. The default value in this file 19 CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE config symbo 20 to 1. Here is the list of possible values in / 21 22 - 0 - disable sysrq completely 23 - 1 - enable all functions of sysrq 24 - >1 - bitmask of allowed sysrq functions ( 25 description):: 26 27 2 = 0x2 - enable control of consol 28 4 = 0x4 - enable control of keyboa 29 8 = 0x8 - enable debugging dumps o 30 16 = 0x10 - enable sync command 31 32 = 0x20 - enable remount read-only 32 64 = 0x40 - enable signalling of pro 33 128 = 0x80 - allow reboot/poweroff 34 256 = 0x100 - allow nicing of all RT t 35 36 You can set the value in the file by the follo 37 38 echo "number" >/proc/sys/kernel/sysrq 39 40 The number may be written here either as decim 41 with the 0x prefix. CONFIG_MAGIC_SYSRQ_DEFAULT 42 written in hexadecimal. 43 44 Note that the value of ``/proc/sys/kernel/sysr 45 via a keyboard. Invocation of any operation vi 46 always allowed (by a user with admin privilege 47 48 How do I use the magic SysRq key? 49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 50 51 On x86 52 You press the key combo :kbd:`ALT-SysR 53 54 .. note:: 55 Some 56 keyboards may not have a key labele 57 also known as the 'Print Screen' ke 58 handle so many keys being pressed a 59 have better luck with press :kbd:`A 60 release :kbd:`SysRq`, press :kbd:`< 61 62 On SPARC 63 You press :kbd:`ALT-STOP-<command key> 64 65 On the serial console (PC style standard seria 66 You send a ``BREAK``, then within 5 se 67 ``BREAK`` twice is interpreted as a no 68 69 On PowerPC 70 Press :kbd:`ALT - Print Screen` (or :k 71 :kbd:`Print Screen` (or :kbd:`F13`) - 72 73 On other 74 If you know of the key combos for othe 75 submit a patch to be included in this 76 77 On all 78 Write a single character to /proc/sysr 79 Only the first character is processed, 80 ignored. However, it is not recommende 81 as the behavior is undefined and might 82 E.g.:: 83 84 echo t > /proc/sysrq-trigger 85 86 Alternatively, write multiple characte 87 This way, all characters will be proce 88 89 echo _reisub > /proc/sysrq-tri 90 91 The :kbd:`<command key>` is case sensitive. 92 93 What are the 'command' keys? 94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 95 96 =========== ================================== 97 Command Function 98 =========== ================================== 99 ``b`` Will immediately reboot the system 100 your disks. 101 102 ``c`` Will perform a system crash and a 103 if configured. 104 105 ``d`` Shows all locks that are held. 106 107 ``e`` Send a SIGTERM to all processes, e 108 109 ``f`` Will call the oom killer to kill a 110 panic if nothing can be killed. 111 112 ``g`` Used by kgdb (kernel debugger) 113 114 ``h`` Will display help (actually any ot 115 here will display help. but ``h`` 116 117 ``i`` Send a SIGKILL to all processes, e 118 119 ``j`` Forcibly "Just thaw it" - filesyst 120 121 ``k`` Secure Access Key (SAK) Kills all 122 console. NOTE: See important comme 123 124 ``l`` Shows a stack backtrace for all ac 125 126 ``m`` Will dump current memory info to y 127 128 ``n`` Used to make RT tasks nice-able 129 130 ``o`` Will shut your system off (if conf 131 132 ``p`` Will dump the current registers an 133 134 ``q`` Will dump per CPU lists of all arm 135 timer_list timers) and detailed in 136 clockevent devices. 137 138 ``r`` Turns off keyboard raw mode and se 139 140 ``s`` Will attempt to sync all mounted f 141 142 ``t`` Will dump a list of current tasks 143 console. 144 145 ``u`` Will attempt to remount all mounte 146 147 ``v`` Forcefully restores framebuffer co 148 ``v`` Causes ETM buffer dump [ARM-specif 149 150 ``w`` Dumps tasks that are in uninterrup 151 152 ``x`` Used by xmon interface on ppc/powe 153 Show global PMU Registers on sparc 154 Dump all TLB entries on MIPS. 155 156 ``y`` Show global CPU Registers [SPARC-6 157 158 ``z`` Dump the ftrace buffer 159 160 ``0``-``9`` Sets the console log level, contro 161 will be printed to your console. ( 162 it so that only emergency messages 163 make it to your console.) 164 165 ``R`` Replay the kernel log messages on 166 =========== ================================== 167 168 Okay, so what can I use them for? 169 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 170 171 Well, unraw(r) is very handy when your X serve 172 173 sak(k) (Secure Access Key) is useful when you 174 trojan program running at console which could 175 when you would try to login. It will kill all 176 thus letting you make sure that the login prom 177 the one from init, not some trojan program. 178 179 .. important:: 180 181 In its true form it is not a true SAK like 182 c2 compliant system, and it should not be m 183 such. 184 185 It seems others find it useful as (System Atte 186 useful when you want to exit a program that wi 187 (For example, X or a svgalib program.) 188 189 ``reboot(b)`` is good when you're unable to sh 190 of pressing the "reset" button. 191 192 ``crash(c)`` can be used to manually trigger a 193 Note that this just triggers a crash if there 194 195 ``sync(s)`` is handy before yanking removable 196 shell that provides no graceful shutdown -- it 197 safely written to the disk. Note that the sync 198 the "OK" and "Done" appear on the screen. 199 200 ``umount(u)`` can be used to mark filesystems 201 running system's point of view, they will be r 202 isn't complete until you see the "OK" and "Don 203 204 The loglevels ``0``-``9`` are useful when your 205 kernel messages you do not want to see. Select 206 the most urgent kernel messages from reaching 207 still be logged if syslogd/klogd are alive, th 208 209 ``term(e)`` and ``kill(i)`` are useful if you 210 you are unable to kill any other way, especial 211 processes. 212 213 "just thaw ``it(j)``" is useful if your system 214 frozen (probably root) filesystem via the FIFR 215 216 ``Replay logs(R)`` is useful to view the kerne 217 or you are not able to use dmesg command to vi 218 User may have to press the key combination mul 219 busy. If it is completely locked up, then mess 220 messages depend on current console loglevel, w 221 sysrq[0-9] (see above). 222 223 Sometimes SysRq seems to get 'stuck' after usi 224 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 225 226 When this happens, try tapping shift, alt and 227 keyboard, and hitting an invalid sysrq sequenc 228 :kbd:`alt-sysrq-z`). 229 230 Switching to another virtual console (:kbd:`AL 231 should also help. 232 233 I hit SysRq, but nothing seems to happen, what 234 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 235 236 There are some keyboards that produce a differ 237 pre-defined value of 99 238 (see ``KEY_SYSRQ`` in ``include/uapi/linux/inp 239 which don't have a SysRq key at all. In these 240 an appropriate scancode sequence, and use ``se 241 this sequence to the usual SysRq code (e.g., ` 242 probably best to put this command in a boot sc 243 exit ``showkey`` by not typing anything for te 244 245 I want to add SysRQ key events to a module, ho 246 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 247 248 In order to register a basic function with the 249 the header ``include/linux/sysrq.h``, this wil 250 Next, you must create a ``sysrq_key_op`` struc 251 handler function you will use, B) a help_msg s 252 prints help, and C) an action_msg string, that 253 handler is called. Your handler must conform t 254 255 After the ``sysrq_key_op`` is created, you can 256 ``register_sysrq_key(int key, const struct sys 257 register the operation pointed to by ``op_p`` 258 if that slot in the table is blank. At module 259 the function ``unregister_sysrq_key(int key, c 260 which will remove the key op pointed to by 'op 261 only if it is currently registered in that slo 262 been overwritten since you registered it. 263 264 The Magic SysRQ system works by registering ke 265 lookup table, which is defined in 'drivers/tty 266 a number of operations registered into it at c 267 and 2 functions are exported for interface to 268 269 register_sysrq_key and unregister_sysr 270 271 Of course, never ever leave an invalid pointer 272 your module that called register_sysrq_key() e 273 unregister_sysrq_key() to clean up the sysrq k 274 Null pointers in the table are always safe. :) 275 276 If for some reason you feel the need to call t 277 within a function called by handle_sysrq, you 278 a lock (you are also in an interrupt handler, 279 you must call ``__handle_sysrq_nolock`` instea 280 281 When I hit a SysRq key combination only the he 282 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 283 284 Sysrq output is subject to the same console lo 285 other console output. This means that if the 286 as is common on distro kernels the output may 287 console, even though it will appear in the dme 288 via the dmesg command and to the consumers of 289 exception the header line from the sysrq comma 290 consumers as if the current loglevel was maxim 291 is emitted it is almost certain that the kerne 292 Should you require the output on the console c 293 to temporarily up the console loglevel using : 294 295 echo 8 > /proc/sysrq-trigger 296 297 Remember to return the loglevel to normal afte 298 command you are interested in. 299 300 I have more questions, who can I ask? 301 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 302 303 Just ask them on the linux-kernel mailing list 304 linux-kernel@vger.kernel.org 305 306 Credits 307 ~~~~~~~ 308 309 - Written by Mydraal <vulpyne@vulpyne.net> 310 - Updated by Adam Sulmicki <adam@cfar.umd.edu> 311 - Updated by Jeremy M. Dolan <jmd@turbogeek.org 312 - Added to by Crutcher Dunnavant <crutcher+kern
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.