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.

Actually I read it yesterday

Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
Preveri ponudbo

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.

This is a superb post I seen

This is a superb post I seen because of offer it. It is truly what I needed to see trust in future you will proceed for imparting such a magnificent post.
cheap mattresses stores calgary

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.

Nice share of information

Nice share of information here. I really find this information really helpful for me. Thanks a lot, dude, for putting up this vital information on the internet for everybody to use.
cheap lambo doors

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

I love the blog. Great post.

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . . High Pr backlinks

“ The rest of the content

“ The rest of the content works prove as it has great value to perform right strategy on the loyal circle Ian Filippini

Good posting... | homestay di

Thanks for sharing.... Nice

Thanks for sharing.... Nice posting...

| guest house jogja | tiket pesawat promo

There is a big difference

There is a big difference with these OS. I prefer windows because it's more friendly to use. www.spectra.com

Pass bee Media

This kind of part offers obvious idea in favor of the Pass bee Media revolutionary individuals connected with running a blog, which truly tips on how to carry out blogging and site-building.

I most likely appreciating

I most likely appreciating each and every bit of it. It is an incredible site and decent impart. I need to much obliged. Great employment! You all do an incredible blog, and have some extraordinary substance. Keep doing awesome.
pos software

Disability insurance Lawyer

My spouse and i possibly appreciating each and every bit of the idea. It is a wonderful web site and decent impart. I want to very much need. Disability insurance Lawyer Great career! An individual many complete a wonderful website, and have a few outstanding element. Retain carrying out wonderful.

You have made an

You have made an extraordinary showing. I will most likely burrow it and generally suggest to my companions. I am sure they will be profited from this site.
pos software

Hmm… I read writes on a

Hmm… I read writes on a comparative subject, however i never went by your online journal. I added it to top choices and i'll be your steady followers.
Comic Memorabilia

The primary a few months of

The primary a few months of my site there were no remarks; simply provide for it time; now they come in like insane consistently! Much obliged.
brampton car battery charging

Really great post. I simply

Really great post. I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries. Any way I'll be subscribing to your food and I trust you post again soon.
Katie Barclay

Extraordinary, This

Extraordinary, This particular net page is genuinely exciting and delight to learn. I'm a colossal fan from the subjects specified.
church

I simply want to tell you

I simply want to tell you that I am new to weblog and definitely liked this blog site. Very likely I’m going to bookmark your blog . You absolutely have wonderful stories. Cheers for sharing with us your blog.
voyance sans cb

This is an excellent post I

This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post.
Mobile Car Body Repairs

I believe there are many more

I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. lean six sigma

Took me time to read all the

Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here cool street wear brand

Thanks for writing such a

Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing. display panel hire

You have made an

You have made an extraordinary showing. I will most likely burrow it and generally suggest to my companions. I am sure they will be profited from this site.
ontario corporate tax planning

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.