How to close down GNU/Linux safely after a system freeze with the SysRq key

How to close down GNU/Linux safely after a system freeze with the SysRq key


Despite jeering at Windows for the infamous system freezes and blue screens of death, there are and will be times when your computer just locks up: the cursor is frozen and even invoking a console by Ctrl + Alt + [F2, F3, ...] to close down the X windows session running on F7 is non-functional.

My fellow blogger, Andrew Min, has given excellent tips on this website when faced with stubborn processes and applications that just refuse to terminate. This tip may be of assistance to those whose entire system has frozen and aren’t happy to just do a hard power off and trust to luck that data will not be corrupted. Fortunately GNU/Linux has journalled filesystems so the chances of this happening are reduced and you will not suffer the indignity of being told that you performed an illegal operation or having to drum your fingers waiting impatiently for scandisk to complete.

Like Ctrl + Alt + Delete this tip is a three fingered Vulcan neck pinch. It consists of Alt + SysRq and a selection of one other key (of which there are thirteen!), the choice of which will determine what operation is performed. This has been described as a way to communicate with the Kernel. It used to be that you had to enable this “magic key combo” when compiling a kernel but this is no longer necessary. (If your computer does not have a SysRq key then look for the “Print Screen” key—usually abbreviated to Prt Scr Normally, after certain key combos you will see “OK” and “Done”. If your kernel is really locked up you might not see them at all. If you have a file called /proc/sys/kernel/sysrq then you are okay and man proc should list it and it will be enabled if there is a “1” in it.

Alt + SysRq + B

If you’re not running any crucial, scheduled tasks or in the middle of composing a letter or an e-mail then this key combination may be the one to use. It will reboot the system immediately without bothering to sync or unmount disks.

Alt + SysRq + R

If you cannot get to a terminal window by using Ctrl + Alt + F2 then use this key combination (pressed altogether) to get a keyboard (this is because this key combination turns off what is called keyboard raw mode. Pressing these keys allows keyboard input even after your X-Windows session has crashed/frozen). Now, try Ctrl + Alt + F2 again and you can close down from the terminal. If that fails move on to the next option.

Alt + SysRq + S

This key combo does just what it says on the tin: it (S)ync’s all filesystems which reduces the possibility of loosing any data and possibly obviating the need for the system to run fsck upon reboot.

Alt + SysRq + U

As you might guess, this one tries to unmount disks and remount them as read only.

Alt + SysRq + O

Not so obvious, but this will power off your machine without syncing or unmounting disks (but it won’t reboot. See above).

If in doubt use a mnemonic

If you are not sure about the sequence to use or just can’t remember, why not use a memory aid like: Raising Elephants Is So Utterly Boring (REISUB) or Everything Is Superb (EISUB) or So Everything Is Unusual - Boot (SEIUB). If even that was too much effort for you, just do Alt + SysRq + H which will bring up a helpful list of the command above.

Category: 

Comments

sonoftheclayr's picture

I found this article very useful as I sometimes find myself in a situation such as this and am forced to turn the computer off manually. I have on problem though. On my laptop SysRq is a function key and there is no key on my laptop to lock the function key down, if that makes sense. Is there some way I can change the combination or another solution?

mark541's picture
Submitted by mark541 (not verified) on

I've got a laptop with the same limitation. I've found that you can do it with the Function key with a little experimentation (and very flexible fingers). On my laptop I did it with this combination:

Alt + Function + SysRq + x (where x is one of R S E I U B etc.)

You may need to experiment if, for example, your laptop prefers it to be entered as:

Function + SysRq + Alt + x

I don't have my laptop with me at the moment, so I'm not sure if it works both ways (When it worked the first way, I didn't try the other).

Felipe Alvarez's picture

I use a HP laptop (nx7400) with opensuse 10.2 My keyboard has PRTSC, SYSRQ, Fn (function) and of course the letters. The only thing that usually comes up is "HELP" menu in Firefox (alt + Fn + sysrq + H) or ksnapshot (K desktop). I tried it on my desktop PC with same OS and KDE, and only ksnapshot opens up. Any ideas?

John Beisley's picture

If you enter the following into a terminal after you've done an Alt-SysRq-S, for example, you should see that in fact it *has* done something (well, it does for me):

$ dmesg | tail -n2
[ 4065.874162] SysRq : Emergency Sync
[ 4066.451217] Emergency Sync complete

Although in my case it also brings up the GNOME screenshot program, but the kernel *also* catches the SysRq, and does what is required.

Gonz's picture
Submitted by Gonz (not verified) on

Somebody's on crack ALT+SyRq+AnyKey will give you a nice screen shot and thats about it.

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

Incorrect. Press one of the desired screens and then read your dmesg output (as pointed out above). Try ALT+SysRQ+H for example.
Your dmesg should put out something like this:

SysRq : HELP : loglevel0-8 reBoot Crashdump tErm Full kIll saK showMem Nice powerOff showPc unRaw Sync showTasks Unmount shoW-blocked-tasks

Works fine, but it does take a screenshot as well (or at least open up the dialog box)

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

Sadly, on my laptop, the kernel sysreq handler seems to interpret all the UIOPJKL;M,./ keys as part of the number pad, so this mostly just changes the log level. (more complex than that, because I use dvorak, so these keys are actually GCRLHTNSMWVZ).

Btw, to turn off the screen capture, you just need to edit your key bindings in X windows. Makes it much easier to test. Do a tail -f /var/log/messages to see what its doing.

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

If the numeric keypad as well as the SysRq key is accessed by pressing a 'Fn' key, try to release the 'Fn' key (while holding Alt/AltGr) after you have pressed the SysRq key. And - AltGr instead of Alt doesn't give me a screenshot ... :-)

Andrew Min's picture
Submitted by Andrew Min on

I for one am thrilled. Kubuntu occasionally freezes, and I've just been holding down on the power button. Now, I finally can avoid that!

--
Andrew Min
http://andrew.timstown.net/dock.htm

Author information

Gary Richmond's picture

Biography

A retired but passionate user of free and open source for nearly ten years, novice Python programmer, Ubuntu user, musical wanabee when "playing" piano and guitar. When not torturing musical instruments, rumoured to be translating Vogon poetry into Swahili.

Most forwarded

Interview with Dave Mohyla, of DTIDATA

Dave Mohyla is the president and founder of dtidata.com, a hard drive recovery facility based in Tampa, Florida.

TM: Where are you based? What does your company do?
DTI Data recovery is based in South Pasadena, Florida which is a suburb of Tampa. We have been here for over 10 years. We operate a bio-metrically secured class 100 clean room where we perform hard drive recovery on all types of hard disks, from laptop hard drives to multi drive RAID systems.

Anybody up to writing good directory software?

Since the very beginning, directories (of any kind) have had a very central role in the internet. (I have recently grown fond of Free Web Directory. Even Slashdot can be considered a directory: a collection of great news and invaluable user-generated comments. As far as software is concerned, doing a quick search on Google about software directories will return the free (as in freedom) software directories like Savannah, SourceForge, Freshmeat and so on, followed by shareware and freeware sites such as FileBuzz, PCWin Download Center and All Freeware (great if you're looking for shareware and freeware, but definitely less comprehensive than their free-as-in-freedom counterparts).

Interview with Mark Shuttleworth

Mark Shuttleworth is the founder of Thawte, the first Certification Authority to sell public SSL certificates. After selling Thawte to Verisign, Mark moved on to training as an astronaut in Russia and visiting space. Once he got back he founded Ubuntu, the leading GNU/Linux distribution. He agreed on releasing a quick interview to Free Software Magazine.

Is better education the key to finding better software?

I read David Jonathon's article Anybody Up To Writing Good Directory Software? the other day, which got me thinking about software directories in general. As David mentioned, many of the software directories one finds when doing a quick google search are free as in beer, not as in freedom. But what interests me is the software directories that already exist, providing a combination of both free as in beer software, and open source software. Sites such as Freeware Downloads and Shareware Download don't advertise themselves as providing free as in liberty software, but each of them have a good selection of open source software available... if you know where to look.

Most emailed

Free Open Document label templates

If you’ve ever spent hours at work doing mailings, cursed your printer for printing outside the lines on your labels, or moaned “There has got to be a better way to do this,” here’s the solution you’ve been looking for. Working smarter, not harder! Worldlabel.com, a manufacture of labels offers Open Office / Libre Office labels templates for downloading in ODF format which will save you time, effort, and (if you want) make really cool-looking labels

Creating a user-centric site in Drupal

A little while ago, while talking in the #drupal mailing list, I showed my latest creation to one of the core developers there. His reaction was "Wow, I am always surprised what people use Drupal for". His surprise is somehow justified: I did create a site for a bunch of entertainers in Perth, a company set to use Drupal to take over the world with Entertainers.Biz.

Update: since writing this article, I have updated the system so that the whole booking process happens online. I will update the article accordingly!

So, why, why do people and companies develop free software?

More and more people are discovering free software. Many people only do so after weeks, or even months, of using it. I wonder, for example, how many Firefox users actually know how free Firefox really is—many of them realise that you can get it for free, but find it hard to believe that anybody can modify it and even redistribute it legally.

When the discovery is made, the first instinct is to ask: why do they do it? Programming is hard work. Even though most (if not all) programmers are driven by their higher-than-normal IQs and their amazing passion for solving problems, it’s still hard to understand why so many of them would donate so much of their time to creating something that they can’t really show off to anybody but their colleagues or geek friends.

Sure, anybody can buy laptops, and just program. No need to get a full-on lab or spend thousands of dollars in equipment. But... is that the full story?

Fun articles

Santa Claus - the most successful open source project

It dawned on me the other day, as I was shopping for the dozens of gifts it seems I have to buy every December, that Santa Claus is the most successful open source project in history. (Bridget @ Illiterarty would agree with that). Santa Claus is essentially a marketing development that is embodied by everyone who stuffs a sock, gives a gift, hosts a dinner or wishes Merry Christmas over the holiday season.

Most emailed

Editorial

When I first started thinking about Free Software Magazine, I was feeling enthusiastic about the dream. I had Dave, Gianluca, and Alan willing to help me, I had established members of the free software community willing to help me out, I had writers volunteering their time and energy for free, and I had a generous offer from OpenHosting for servers, all before I'd proved myself. There was a sense of excitement in the air, and I thought maybe, just maybe, I could make this work.

Free Software Magazine uses Apollo project management software and CRM for its everyday activities!