SysRq key

Материал из Webko Wiki
Версия от 11:28, 10 мая 2017; Sol (обсуждение | вклад) (Новая страница: «Категория:Linux == What is the magic SysRq key? == It is a 'magical' key combo you can hit which the kernel will respond to regardless of whatever…»)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к навигации Перейти к поиску


What is the magic SysRq key?

It is a 'magical' key combo you can hit which the kernel will respond to regardless of whatever else it is doing, unless it is completely locked up.

How do I enable the magic SysRq key?

You need to say "yes" to 'Magic SysRq key (CONFIG_MAGIC_SYSRQ)' when configuring the kernel. Stock Fedora and RHEL kernels do have this functionality enabled at compile-time, but the distributions disable it at boot time, by default, using sysctl.conf.

To re-enable it at boot time create config file in the sysctl.d directory (e.g. /etc/sysctl.d/90-sysrq.conf) with this line:

kernel.sysrq = 1

When running a kernel with SysRq compiled in, /proc/sys/kernel/sysrq controls the functions allowed to be invoked via the SysRq key. Here is the list of possible values in /proc/sys/kernel/sysrq:

  • 0 - disable sysrq completely
  • 1 - enable all functions of sysrq
    • >1 - bitmask of allowed sysrq functions (see below for detailed function description):
    • 2 - enable control of console logging level
    • 4 - enable control of keyboard (SAK, unraw)
    • 8 - enable debugging dumps of processes etc.
    • 16 - enable sync command
    • 32 - enable remount read-only
    • 64 - enable signalling of processes (term, kill, oom-kill)
    • 128 - allow reboot/poweroff
    • 256 - allow nicing of all RT tasks

You can set the value in the file by the following command.

echo "number" >/proc/sys/kernel/sysrq 

So to enable it would be.

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

Or also can enable it by doing.

sysctl -w kernel.sysrq=1

How do I use the magic SysRq key?

x86

You press the key combo '<Alt><SysRq><command key>'.

SPARC

You press '<Alt><Stop><command key>'

Serial Console (PC style standard serial ports only )

You send a BREAK, then within 5 seconds a command key.

Sending BREAK twice is interpreted as a normal BREAK.

PowerPC

Press '<Alt><Print Screen>(or <F13>)<command key>

All Architectures

Write a character to /proc/sysrq-trigger:

echo t > /proc/sysrq-trigger

Some keyboards may not have a key labeled 'SysRq'. The 'SysRq' key is also known as the 'Print Screen' key. Also some keyboards cannot handle so many keys being pressed at the same time, so you might have better luck with "press Alt", "press SysRq", "release SysRq", "press <command key>", release everything.

What are the 'command' keys?

  • 'b' - Will immediately reboot the system without syncing or unmounting your disks.
  • 'c' - Will perform a kexec reboot in order to take a crashdump.
  • 'd' - Shows all locks that are held.
  • 'e' - Send a SIGTERM to all processes, except for init.
  • 'f' - Will call oom_kill to kill a memory hog process.
  • 'g' - Used by kgdb on ppc and sh platforms.
  • 'h' - Will display help (any key that is not listed here will bring forth help )
  • 'i' - Send a SIGKILL to all processes, except for init.
  • 'k' - Secure Access Key (SAK) Kills all programs on the current virtual terminal.

See important comments below in SAK section.

  • 'l' - Shows a stack backtrace for all active CPUs.
  • 'm' - Will dump current memory info to your console.
  • 'n' - Used to make RT tasks nice-able
  • 'o' - Will shut your system off (if configured and supported).
  • 'p' - Will dump the current registers and flags to your console.
  • 'q' - Will dump a list of all running timers.
  • 'r' - Turns off keyboard raw mode and sets it to XLATE.
  • 's' - Will attempt to sync all mounted filesystems.
  • 't' - Will dump a list of current tasks and their information to your console.
  • 'u' - Will attempt to remount all mounted filesystems read-only.
  • 'v' - Dumps Voyager SMP processor info to your console.
  • 'w' - Dumps tasks that are in uninterruptable (blocked) state.
  • 'x' - Used by xmon interface on ppc/powerpc platforms.
  • '0'-'9' - Sets the console log level, controlling which kernel messages will be printed to your console. ('0', for example would make it so that only emergency messages like PANICs or OOPSes would make it to your console.)