The joy that is SysRq

I’m constantly surprised when I come across long-time Linux users who don’t know about SysRq. The Linux Magic System Request Key Hacks are a magic set of commands that you can get the Linux kernel to follow no matter what’s going on (unless it has panicked or totally deadlocked).

Why is this useful? Well, there are many situations where you can’t shut a system down properly, but you need to reboot. Examples:

  • You’ve had a kernel OOPS, which is not quite a panic but there could be memory corruption in the kernel, things are getting pretty weird, and quite honestly you don’t want to be running in that condition for any longer than necessary.
  • You have reason to believe it won’t be able to shut down properly.
  • Your system is almost-locked-up (i.e. the above point)
  • Your UPS has about 10 seconds worth of power left
  • Something is on fire (lp0 possibly?)
  • …Insert other esoteric failure modes here…

In any of those situations, grab a console keyboard, and type Alt+SysRq+s (sync), Alt+SysRq+u (unmount), wait for it to have synced, and finally Alt+SysRq+b (reboot NOW!). If you don’t have a handy keyboard attached to said machine, or are on another continent, you can

# echo u > /proc/sysrq-trigger

In my books, the useful SysRq commands are:

b
Reboot
f
Call the oom_killer
h
Display SysRq help
l
Print a kernel stacktrace
o
Power Off
r
Set your keyboard to RAW mode (required after some X breakages)
s
Sync all filesystems
u
Remount all filesystems read-only
0-9
Change console logging level

In fact, read the rest of the SysRq documentation, print it out, and tape it above your bed. Next time you reach for the reset switch on a Linux box, stop your self, type the S,U,B sequence, and watch your system come up as if nothing untoward has happened.

Update: I previously recommended U,S,B but after a bit of digging, I think S,U,B may be correct.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Raising Elephants

You can actually do a bit better by pressing Alt+SysRq+e, which sends SIGTERM to all processes. Processes which are still working can still terminate gracefully instead of being killed. There is a mnemonic to help remember the sequence.

There's a lot sewa bus

There's a lot sewa bus pariwisata to be desain interior rumah minimalis said about kebaya pengantin modern the way desain rumah minimalis the perfect rumah dijual combination of a info lokasi tempat obyek wisata movie and its music model rumah minimalis can move us

I always thought it was

I always thought it was supposed to be S,U,B?

re: S, U, B

You want to sync() the unmounted filesystem. If you sync it before it's unmounted, then the version on disk isn't guaranteed to be consistent.

S,U,B

Surely though if you wanted to sync data, you'd have to be able to write to the disk?

Yep, that's the way I know

Yep, that's the way I know it. You can't sync to an unmounted disk, as far as I'm aware. Once it's unmounted, it's totally unusable. You have to sync first. REISUB.

The only cases where I ever think of needing this, it turns out I can't use them anyway because it's panicked.

S, U vs U, S

I knew about "Raising Skinny Elephants Is Utterly Boring" for quite a while, and it does S before U. So are all the other similar elephant mnemonics listed on the Wikipedia page.

Are you sure data can be synced to a read-only filesystem?

REISUB

I've been a devotee of the R-E-I-S-U-B sequence for some time now, but it seems I'll have to change it to the less-pronounceable REIUSB. Amusingly some videos, when played in vlc, consistently cause my system to lock up so badly that the whole sequence goes unheeded.

Looks like I could be wrong here

I need to do some research on this. From my understanding of the sync() call, it syncs all write-cached data, not necessarily filesystems.
I guess I need to dig deeper / do some testing...

Research

I’ve been digging into the kernel (thanks Linux Cross Reference). While I’m a kernel newbie, and don’t know much about the structures Linux uses for this, it looks to me like you should sync first, yes.

emergency_remount() calls fsync_super(), which calls sync_inodes_sb(), which looks like it may sync the file-system.

However, emergency_sync() calls sync_filesystems() which won’t work if they’ve been remounted RO (it checks).

I’m not a kernel developer.

Sync

According to sysrq.txt,

's' - Will attempt to sync all mounted filesystems.

which means that it doesn't do anything for unmounted filesystems. Also from sysrq.txt: "I generally 'S'ync, 'U'mount, then re'B'oot when my system locks." I would guess that remounting a filesystem read-only includes syncing everything to disk.

U

Please note that 'u' doesn't actually unmount any filesystems, it just remounts them R/O. That said, it certainly seems like an emergency_sync() after emergency_remount() is useless; it might also be useless before-hand, but at least it'll actually do something that way.

The latest system tool for

The latest system tool for Linux provides excellent technical support for your computer. It really makes all your tasks much easier. Adding to that you get good technical support for resolving all errors, Thanks for sharing fir such rare information. http://www.outlookemailsetup.com

Wow! What an eye opener this

Wow! What an eye opener this post has been for me. Very much appreciated, bookmarked, I can’t wait for more!
Targeted Traffic

I surprised with the analysis

I surprised with the analysis you made to make this particular publish incredible. Wonderful activity!
buy instagram followers cheap

I should say only that its

I should say only that its awesome! The blog is informational and always produce amazing things.
FairPoint Login

Fantastic blog post. The post

Fantastic blog post. The post affects a lot of urgent challenges of our society. We can not be uninvolved to these challenges. This post gives good ideas and concepts. Very informative and practical.
FairPoint Login

Great post full of useful

Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”.
Targeted Adult Traffic

Thanks for the post and great

Thanks for the post and great tips..even I also think that hard work is the most important aspect of getting success.
Olga Peterson

Linux one of the secure and

Linux one of the secure and amazing OS i was using Linux Mint and i never find single error even its work far better then Windows OS.
uk twitter followers

Passbeemedia

Wow! Just what a close look opener this kind of article Passbeemedia continues to be for me personally. Greatly loved, added, We can’t lose time waiting for a lot more!

This paragraph gives clear

This paragraph gives clear idea in favor of the new people of blogging, that genuinely how to do running a blog.
Blog commenting service

Quality iBeacons Online

Great article full of beneficial suggestions! My own website is fairly new as well as We are furthermore getting difficulty receiving the visitors to get away Quality iBeacons Online from comments. Analytics shows they are coming to the website but I've got thoughts “nobody desires to end up being first”.

This topic is something that

This topic is something that I have been looking into for a while now and your insight is exceptional. Thanks for sharing this information.Elektronik Sigara

People commonly believe that

People commonly believe that it is good to breathe or inhale more air at rest. However, this makes the breather breathless due to anaerobic respiration in cells. Learn more at E-breathing.com. Breathing isn't as simple as it seems!

At the last tree before the

At the last tree before the traverse comes to ITILF2011 dumps a treacherous end, there is a cairn and a stick pointing you up the rock-band.Continue up to a beautiful pool beneath a large waterfall ITIL-F dumps This is the best swimming spot and makes an ideal lunch break. ITIL dumps

very inspiring discussion If

very inspiring discussion
If you're looking for a wedding reading article PlanningWeddingIdeas ..
There are also other interesting images in Free HD Wallpapers

needed infromações on SysRq

needed infromações on SysRq and found thank you festa lembrancinhas

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.