Feb 102011
 

magic sysrqA volte succede che il desktop si blocchi e non si possa fare nulla, quindi l’unica scelta è quella di scollegare il cavo di alimentazione?
No, Linux ha i magici tasti SysRq che possono sincronizzare il vostro disco ed poi dare un riavvio del sistema … e molte più cose.

Cosa sono i tasti magici SysRQ ?

Si tratta di una combinazione ‘magica’ di tasti che potete premere ed a cui il kernel risponderà indipendentemente da qualsiasi altra cosa stia facendo, a meno che non sia completamente bloccata.

Come abilitare i tasti magici SysRq

Se si utilizza un kernel custom è necessario dire “sì ” a ‘Magic SysRq key (CONFIG_MAGIC_SYSRQ)’ durante la configurazione del kernel. Durante l’esecuzione di un kernel con SysRq compilato, /proc/sys/kernel/sysrq controlla le funzioni che possono essere invocate con il tasto SysRq.

Sulle ultime Ubuntu/Debian e distribuzioni basate su Red Hat, SysRq è compilato nel kernel ma non abilitato, bisogna quindi abilitarlo al boot modificando il seguente file

Per Ubuntu – Debian

sudo vi /etc/sysctl.conf

O

Per Red Hat – Fedora – CentOS

sudo vi  /etc/sysctl.config

In entrambi i casi aggiungere questa opzione:

 kernel.sysrq = 1

Usare SysRq

Alcune tastiere non hanno un tasto separato SysRq. In questo caso, un apposito tasto “Stampa” dovrebbe essere presente. Sotto ambienti grafici (come Gnome o KDE), la combinazione di tasti ‘Alt’+’PrintScrn/SysRq’+tasto generalmente porta solo a una alla generazione di una schermata con uno screenshot. Per evitare questa caratteristica di screenshot la combinazione magica SysRq dovrebbe essere inoltre preceduta da Ctrl, diventando così ‘Ctrl’+’Alt’+’SysRq’+tasto.

Combinazioni di tasti

La documentazione completa è presente nei sorgenti del kernel in Documentation/sysrq.txt.

Questi alcuni tra i tasti più utili:

b – Riavvia immediatamente il sistema senza sincronizzare o smontare i dischi

o – Spenge immediatamente il sistema (se configurato e supportato)

s – Cerca di fare sync su tutti i filesystem montati

u – Cerca di rimontare tutti i filesystem montati read-only

p – Fa il dump dei registri e flags e la stampa sulla console

t – Fa il dump dei task correnti e stampa le informazioni relative in console

m – Fa il dump della memoria e lo stampa in console

e – Invia un SIGTERM a tutti i processi, tranne init.

i – Invia un SIGKILL a tutti i processi, tranne init.

l – Invia un SIGKILL a tutti i processi, INCLUSO init.

Usi comuni

Un idioma comune per eseguire un riavvio di sicurezza di un computer Linux che è altrimenti bloccato è “Raising Elephants Is So Utterly Boring”, “Reboot Even If System Utterly Broken” o semplicemente ci si può ricordare la parola “BUSIER” da eseguire alla rovescia. Questa sta per:

unRaw      (riprendi controllo della tastiera da X),
 tErminate (manda un SIGTERM a tutti i processi, permettendogli di terminare),
 kIll      (manda un SIGKILL a tutti i processi, forzandoli a terminare immediatamente),
  Sync     (sincronizza i dati su disco),
  Unmount  (rimonta tutti i filesystem in modalità read-only),
reBoot.

Questo può evitare che sia necessario un fsck al riavvio del sistema e da la possibilità ad alcuni programmi di salvare i backup di emergenza del lavoro non salvato.

In pratica, ogni comando può richiedere alcuni secondi per completarsi, soprattutto se il feedback non è disponibile sullo schermo a causa di un blocco o per problemi di visualizzazione. Per esempio, inviando il segnale SIGKILL ai processi che non hanno ancora finito può causare la perdita di dati.

Riferimenti:
http://lxr.linux.no/#linux+v2.6.37/Documentation/sysrq.txt

http://en.wikipedia.org/wiki/Magic_SysRq_key

Popular Posts:

Flattr this!

  11 Responses to “SysRQ in Linux”

  1. on my fedora-14 system it is sysctl.conf, not sysctl.config, FYI.

  2. Your title basically tells that Ubuntu != Linux – and is giving a lot of peoples a WTF face. Have we already reached the point where common users don’t know that Ubuntu is _just another_ Linux based system?

    • You have reason, and it’s due just to a bad choice for the title.
      At the start of the article i wanted to do something deeper for Ubuntu (just because i write from an Ubuntu), but i did not do it…and so just a bad choice in the article, changing it now 😉

  3. Awesome, thank you 🙂

  4. “Some keyboards may not provide a separate SysRq key. In this case, a separate “Print” key should be present. Under graphical environments (such as Gnome or KDE) ‘Alt’+’PrintScrn/SysRq’+key combination generally only leads to a screenshot to be dumped”

    I see that is exactly what Wikipedia says, but that description is seriously screwed up.

    A: I think it is pretty rare to have a separate ‘Sys Rq’ key these days, it’s most commonly ‘Print Screen/Sys Rq’, but on laptops you never know what they are going to do.

    B: If ‘Alt’ is the modifier for the ‘Print Screen/Sys Rq’ key, then pressing ‘Alt’+’Print Screen/Sys Rq’+key, should never cause a screenshot to be taken. That’s not to say it never happens, but should be the odd exception not common behavior. Hitting ‘Alt’+’Print Screen/Sys Rq’ without any other keys is another story.

    C: If some other key is the modifier for the ‘Print Screen/Sys Rq’ key (‘Fn’ commonly on laptops) then it is completely wrong to tell people with those keyboards to hit ‘Alt’+’Print Screen/Sys Rq’+key or as people more commonly seem to type ‘Alt’+’Print Screen’+key because they would need to be hitting ‘Fn’+Print Screen/Sys Rq’+key. On one laptop I have in front of me it is actually ‘Delete/Sys Rq’ with ‘Fn’ as the modifier.

    D: If the intention was to indicate that if your keyboard does not provide a ‘Sys Rq’ key that you could hit ‘Ctrl’+’Alt’+’Print Screen’+key (which seems to be the case), it should have been more plainly stated.

    E: You don’t tell people to hit ‘Shift’+’:/;’ to type a ‘:’ character. So should it *really* be considered wise for people to continually type ‘Alt’+’Sys Rq’ for the ‘Sys Rq’ function?

    In regard to D: above, I did actually try it, booting from System Rescue CD since I don’t have my own laptop to try it on. On the laptop with no indication that ‘Sys Rq’ is an option ‘Ctrl’+’Alt’+’Print Screen’+key works, another laptop where ‘Sys Rq’ is a ‘Fn’ option on one key and ‘Print Screen’ is a ‘Fn’ option on the ‘Insert’ key ‘Ctrl’+’Alt’+’Insert/Print Screen’+key works.

    Later, Seeker

    • I totally agree, there is too much confusion. On my laptop (FJS S7110) there are “insert/print” and “del/rsys” with the second function by “fn” key. With SysRQ enabled, I can’t obtain the solution. I tried all keys combinations, but nothing. 🙁

  5. Nice article! would it be possible to have in a printer friendly version? or did i miss the print button on the page?
    Cheers

    • Hello Gilles,
      I’ve installed a plugin to export articles in pdf format.
      You can find at the end of the article a linl “Download article as PDF”.

      i hope this can help.

      Bye

  6. I accidently hit ALT + SysRq on my Linux Ubuntu machine, it shut down immediately and now I can not get it to power back up.
    I removed the battery, but that did not help.

    How can I restart my system?

    Thanks for any help you can provide

Leave a Reply to stewart Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*