Posts tagged ‘Magic SysRq Keys’

When Linux Hangs or Completely Freezes

When Windows hangs itself we all know what to do right? Were just reaching for the combination [Ctrl]+[Alt]+[Del] (Control Alt Delete). But if you try this in Linux nothing happens (in some distributions, like Ubuntu, you actually get the menu for shutting down your system, but this don’t work when your system hags or freezes).

So what to do?

There is 3 keyboard combinations every Linux user should remember (or write down). But before we begin I want you to understand some of the signs I use: If a symbol is surrounded by [ ] means that it is a button or key on your keyboard. + means that you have to hold the keys down at once. And > means that you have to click the buttons one by one, remember that you have to press each key for 2-3 seconds. Now that you have learned this we can move on to the commands:

Fist you have the combination [Ctrl]+[Alt]+[BackSpace] (backspace is the [←] over [Enter]) that restarts X or GDM (you will be logged out), and you can kind of call it Linux’s Control Alt Delete equivalent. This command gives your programs time to make emergency backups of unsaved files (for example if you writing on a document in Open Office) and it  prevents that you get a file system error during the crash.If you use Ubuntu or a distribution based on Ubuntu you will have to use [Alt]+[PrtSc]+[K] (PrtSc = Print Screen) instead, but you should note that some Ubuntu based distros (like Linux Mint) still use the universal [Ctrl]+[Alt]+[BackSpace]. (Note 14.11.2013: For newer versions of Ubuntu, and some of it’s derivatives, even this combination does not seemto work any more, to get it working again check out the update in the end of the post)

But what to do if this combination doesn’t work? Then you have to use something called Magic SysRq Keys. In short they are keys which allows you to perform various commands regardless of the system’s state, like in this case get the system to recover from a freeze. Note that these keys wont work if your system is in kernel panic. Like I said there are tree combinations that you will have to remember and since we have already learned one, there are two to go:

This command will get your freezed system to restart safely:
Hold [Alt]+[PrtSc] then type [R]>[S]>[E]>[I]>[U]>[B] (press each key for 2-3 seconds). In short the keys mean: 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), reBoot (restart).

This command will get your freezed system to shut down in a safe way:
Again hold [Alt]+[PrtSc] then type [R]>[S]>[E]>[I]>[U]>[O] (press each key for 2-3 seconds). These keys mean: unRaw, tErminate, kIll, Sync, Unmount , shutdOwn (does it really need an explanation?).

To learn more about Magic SysRq Keys visit: Wikipedia: Magic SysRq Key.




As Andy E points out in his comment; [Alt]+[PrtSc]+[K] does not seem to work in newer versions of Ubuntu and some of it’s derivatives.

To get it working again first type this into the terminal (if you prefer using a dedicated text manager and not the terminal, change nano into your preferred text editor, like for example gedit):
sudo nano /etc/sysctl.d/10-magic-sysrq.conf

You will now see this line of code in the end of the file:
kernel.sysrq = 176

Change this into:
kernel.sysrq = 180

Then save and reboot, and [Alt]+[PrtSc]+[K] will “magically” work again!

04/06/2010 at 14:55 7 comments

Licensed Under:

Creative Commons LicenseExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

Tux and GNU are published under the GNU General Public License.



%d bloggers like this: