Feb 102011

magic sysrqSometimes happen that your desktop freeze and you cannot do anything, so the only choice is to unplug the power cord ?
No, Linux has the magic SysRq key that can sync your disk and issue a reboot of your system…and many more things.

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 to enable the magic SysRq key

If you use a custom kernel you need to say “yes” to ‘Magic SysRq key (CONFIG_MAGIC_SYSRQ)’ when configuring the kernel. When running a kernel with SysRq compiled in, /proc/sys/kernel/sysrq controls the functions allowed to be invoked via the SysRq key.

On the latest Ubuntu/Debian and Red Hat based distributions, SysRq is compiled but not enabled, so you must enable it at boot by editing the following file:

For Ubuntu – Debian

sudo vi /etc/sysctl.conf


For Red Hat – Fedora – CentOS

sudo vi  /etc/sysctl.config

In both cases you need to add this parameter:

 kernel.sysrq = 1

Using SysRq

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. To avoid this Print Screen feature the magic SysRq combination should be additionally prefixed by Ctrl, becoming ‘Ctrl’+’Alt’+’SysRq’+key.

Keys combinations

Full documentation is included in the kernel sources in Documentation/sysrq.txt.

These are some of the most useful keys:

‘b’ – Will immediately reboot the system without syncing or unmounting your disks.

‘o’ – Will shut your system off (if configured and supported).

‘s’ – Will attempt to sync all mounted filesystems.

‘u’ – Will attempt to remount all mounted filesystems read-only.

‘p’ – Will dump the current registers and flags to your console.

‘t’ – Will dump a list of current tasks and their information to your console.

‘m’ – Will dump current memory info to your console.

‘e’ – Send a SIGTERM to all processes, except for init.

‘i’ – Send a SIGKILL to all processes, except for init.

‘l’ – Shows a stack backtrace for all active CPUs.

Common use

A common idiom to perform a safe reboot of a Linux computer which has otherwise locked up, is “Raising Elephants Is So Utterly Boring”, “Reboot Even If System Utterly Broken” or simply remembering the word “BUSIER” backwards, is often useful. It stands for:

unRaw      (take control of keyboard back from X),
 tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
 kIll      (send SIGKILL to all processes, forcing them to terminate immediately),
  Sync     (flush data to disk),
  Unmount  (remount all filesystems read-only),

This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work.

In practice, each command may require a few seconds to complete, especially if feedback is unavailable from the screen due to a freeze or display corruption. For example, sending SIGKILL to processes which have not yet finished terminating can cause data loss.




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?

    • 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.


  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

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>