Magic SysRq

Posted by Marcus Folkesson on Sunday, August 27, 2017

Magic SysRq

Every kernel-hacker should knows about the magic SysRQ. Period.

To enable the magic, make sure CONFIG_MAGIC_SYSRQ is set in your Kernel hacking tab.

I use this feature a lot, mostly for set loglevel and reboot the system. But it is also very useful to get information out of the system even if it is completely frozen.

As everybody is using GNU Screen (what else?) as their TTY terminal, the keyboard combination is: ctrl+A B.

And here the magic begins. This combination sends a SysRq keycode to the target system.

To get information about available commands, press ctrl+A B h:

 1    [669510.910125] SysRq : HELP : 
 2    loglevel(0-9) 
 3    reBoot 
 4    Crash 
 5    terminate-all-tasks(E) 
 6    memory-full-oom-kill(F) 
 7    kill-all-tasks(I) 
 8    thaw-filesystems(J) 
 9    saK show-memory-usage(M) 
10    nice-all-RT-tasks(N) 
11    powerOff 
12    show-registers(P) 
13    show-all-timers(Q) 
14    unRaw 
15    Sync 
16    show-task-states(T) 
17    Unmount 
18    show-blocked-tasks(W) 
19    dump-ftrace-buffer(Z)

The ones that I find most useful are:

  • 0-9, set debug level
  • b, reboot the system (ingrained...)
  • p, show a register dump ( useful if the system hangs)
  • g, switch console to KGDB (I love KGDB)
  • 1, Show all timers (good when looking for power-thieves)

The best part is that Magic SysRq works in allmost every situation, even if the system is frozen.

For further details see the kernel source file Documentation/sysrq.txt