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 must say that your blogpost

I must say that your blogpost was the most enjoying read I've seen in a long time. Greetings from gadgetterbaru and motorola moto g indonesia..

hello

Most people have no concept of how an automatic transmission works, yet they know how to drive a car. You don't have to study physics to understand the laws of motion to drive a car. You don't have to understand any of this stuff to use Macintosh.
Abstract wallpapers

Toko Obat Herbal Grosir

Toko Obat Herbal Grosir Amazon Plus menyediakan minuman alamiah berkualitas dengan maksud untuk membantu meningkatkan mutu kesehatan pribadi Anda. Kami merupakan toko online grosir produk obat herbal terpercaya di tanah air.
Ditangani oleh pekerja yang cekatan, sehingga menghadirkan mutu pelayanan Berdedikasi tinggi.
Jus Amazon Plus Herbal

Jus Amazon Plus adalah minuman kesehatan senyawa zaitun hydroxytyrosol satu-satunya di dunia.
Amazon Plus Herbal dalam bentuk jus yang berbahan dasar buah tropical alami dari seluruh pelosok dunia.
Salah satunya buah dari pedalaman Hutan Amazon, di amerika latin yang digabung dengan manggis, queen of fruit asal Indonesia yang juga terkandung kandungan antioksidan tinggi, juga dipadukan dengan zaitun yang kaya akan Hydroxytyrosol.

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.

Recently I came across your

Recently I came across your blog and read along. I thought I would leave my first comment. I do not know what to say except that I liked reading. Nice blog. alliance home warranty
extended home warranty

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?

Greetings I discovered your

Greetings I discovered your site by oversight when i was hunting hurray down this acne issue, I must say your site is truly useful I additionally love the outline, its astonishing!.
Watch Movies Online

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

stunning, incredible, I was

stunning, incredible, I was wondering how to cure skin inflammation regularly. furthermore discovered your site by google, took in a ton, now i'm a bit clear. I've bookmark your site furthermore include rss. keep us overhauled...
http://economie-automobile.hautetfort.com/

I concur with you. This post

I concur with you. This post is positively rousing. I like your post and all that you impart to us is present and exceptionally useful, I need to bookmark the page so I can return here from you that you have made an awesome showing .. - See more at:
sbi po recruitment

Took personal time to peruse

Took personal time to peruse all the remarks, yet I truly reveled in the article. It turned out to be Very useful to me and I am certain to all the commentators here! It's generally decent when you can be educated, as well as entertained!
brazilian virgin hair

his is my first time i visit

his is my first time i visit here. I discovered such a variety of engrossing stuff in your site, particularly its exchange. From the huge amounts of remarks on your articles, I figure I am by all account not the only one having all the relaxation here! Keep up the astounding work.
success

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

In my network connections

In my network connections dialogue I've got "ifupdown (wlan0)" under the wired tab - telling this set up is specific for wired connections https://www.rebelmouse.com/

Took personal time to peruse

Took personal time to peruse all the remarks, yet I truly reveled in the article. It ended up being Very useful to me and I am certain to all the commentators here! It's generally pleasant when you can be educated, as well as entertained!
best exercises to make you jump higher

I ought to say just that its

I ought to say just that its amazing! The website is instructive and dependably create stunning things.
Tarocchi

You have made an incredible

You have made an incredible showing. I will most likely burrow it and by and by propose to my companions. I am certain they will be profited from this site.
how do i get a guy to like me if i'm ugly

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

Took personal time to peruse

Took personal time to peruse all the remarks, yet I truly reveled in the article. It turned out to be Very useful to me and I am certain to all the commentators here! It's generally decent when you can be educated, as well as entertained!
columbia sedan taxi service

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

Effortlessly, the article is

Effortlessly, the article is really the best point on this registry related issue. I fit in with your decisions and will energetically anticipate your next overhauls.
telephone system installation

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

Great article full of

Great article full of beneficial suggestions! My ...
Texas Workforce Commission Login

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!

eople commonly believe that

eople 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 mor..
buy dofollow blog comments

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

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.