Administration Linux

System mit magic SysRq neu starten

Es sind nun schon ein paar Jährchen, die ich im IT-Showgeschäft arbeite. Und ich schäme mich tatsächlich ein bisschen, dass ich erst im Jahr 2018 von der Existenz des großartigen “magic SysRq” erfahre.

Den “Klammergriff” kennen die meisten noch. Dieser wird aber relativ weit oben im Softwarestack vom OS abgefangen. So kann dem User durchaus erst eine grafische Rückfrage vorgelegt werden, ob man das System nun neustarten oder ausschalten möchte.

Doch ist der Rechner so sehr beschäftigt, dass er kaum noch oder gar nicht mehr reagiert, hiflt der nicht mehr. Hier kommt der “magic SysRq” als deutlich bessere Variante gegenüber dem forcierten Poweroff ins Spiel – sofern er aktiviert ist.

sysRq Status überprüfen

Viele Distributionen allerdings schalten diese Funktionalität im Auslieferungszustand allerdings ab – so zum Beispiel Fedora und Arch, bei debian hingegen ist ein Subset aktiv.

Dies kann man mit sysctl prüfen:

mscholz@didymos  ~ # sysctl kernel.sysrq
kernel.sysrq = 16Code-Sprache: CSS (css)

oder durch sysfs:

mscholz@didymos  ~ # cat /proc/sys/kernel/sysrq
16Code-Sprache: CSS (css)

Folgende Werte können in dieser sysctl-Variable stehen. Freigeschaltete Funktionen addieren ihre Werte – ähnlich den Dateirechten bei chmod – zusammen. So ergibt das debian stretch default von ‘438’ alle Rechte außer 64 und 8 (438-256-128-32-16-4-2=0).

Mögliche Werte / Funktionen in der folgenden Aufstellung:

 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 task

magic SysRq aktiveren

Aktivieren kann man den SysRq ebenfalls mit sysctl. Temporär mit:

mscholz@didymos ~ # sudo sysctl -w kernel.sysrq=1Code-Sprache: CSS (css)

Um die Änderung dauerhaft (beim Booten) zu aktiveren, kann man ‘kernel.sysrq = 1‘ in die /etc/sysctl.conf oder besser in eine neu zu erstellende /etc/sysctl.d/90-sysrq.conf einfügen.

Magic SysRq benutzen

Nun können die SysRq Befehle – auf verschiedene Arten – verwendet werden.

An der Tastatur des nicht reagierenden Systems

Direkt am Rechner sitzen, drückt man gleichzeitig Alt + Druck (PrntScrn) und ohne die Finger von den Tasten zu lösen die gewünschten Befehle. Die nützlichste und geläufigste Kombination dürfte REISUB sein.

Alt + Druck + R + E + I + S + U + B, kann sich gut mit diesen Eselsbrücken gemerkt werden: Reboot Even If System Utterly Broken oder BUSIER.

Über eine serielle Konsole

Nach dem Sendes eines BREAK hat man 5 Sekunden Zeit, die Befehle zu tippen. 2 BREAKs in Folge senden ein normales BREAK.

Überall und mit Skript

mscholz@didymos ~ # echo reisub > /proc/sysrq-triggerCode-Sprache: CSS (css)

Komplette Liste der SysRq Befehle:

    '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.
'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.)
  1. Sa’k’ (Secure Access Key) is useful when you want to be sure there is no trojan program running at console which could grab your password when you would try to login. It will kill all programs on given console, thus letting you make sure that the login prompt you see is actually the one from init, not some trojan program. Others find it useful as (System Attention Key) which is useful when you want to exit a program that will not let you switch consoles. (For example, X or a svgalib program.)

Autor

Seit Kindheitstagen ist der Computer sein Begleiter. Was mit Linux anfing, wurde 2005 ein/e Beruf/ung, die weit über den Arbeitsplatz hinausgeht. Durch stetige Weiterentwicklung fasste er auch im *BSD Segment Fuß und bietet mittlerweile professionelle Lösungen im Bereich Hosting, Networking und Infrastruktur an. Als Ausgleich beschäftigt er sich neben Computerspielen mit der Fotografie.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.