Magic SysRq key

on July 29th, 2009 by - Comments Off on Magic SysRq key

Visão geral

É um conjunto de teclas “mágicas” que faz com que o kernel responda independentemente que esta a fazer, a não ser que o mesmo esteja completamente bloqueado.
Isto faz com que possamos desligar o sistema sem corromper os file systems ou até mesmo descobrir a causa do kernel panic.

Habilantando SysRq

editando diretamente o arquivo /proc/sys/kernel/sysrq

echo 1 > /proc/sys/kernel/sysrq

ou:

alterando o arquivo /etc/sysctl.conf:

kernel.sysrq = 1

Nota: Esta configuração é apenas para chamado através do teclado/console, não é necessário caso seja utilizado através do arquivo /proc/sysrq-trigger (este é permitido sempre por usuários com privilégio de root).

Para utilizar basta apertar as seguintes teclas:

ALT-SysRq-

Em alguns teclados a tecla SysRq é equivalenta a tecla PrtSc.

ALT-PrtSc-

Exemplo:

Faz com que o sistema realize um reboot imediatamente.

echo b > /proc/sysrq-trigger

Entendendo os 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 (actually any other key than those listed here will display help. but ‘h’ is easy to remember)
‘i’ – Send a SIGKILL to all processes, except for init.
‘j’ – Forcibly “Just thaw it” – filesystems frozen by the FIFREEZE ioctl.
‘k’ – Secure Access Key (SAK) Kills all programs on the current virtual console. NOTE: 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 per CPU lists of all armed hrtimers (but NOT regular timer_list timers) and detailed information about all clockevent devices.
‘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.
‘z’ – Dump the ftrace buffer
‘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.)

DICA:

Felizmente podemos utilizar combinações, como por exemplo:

Faz um sincronismo dos arquivos e remota os file system em modo de somente leitura, antes de fazer um reboot.

echo “susb” > /proc/sysrq-trigger

Esta opção é similar a anterior, porém enviado um sinal de TERM e KILL para todos os processos, exceto o processo init.

echo “seiusb” > /proc/sysrq-trigger

© TIAGO.DIAS.ETI.BR