Linux froze what to do

Frozen Linux System? Here are 3 Ways to Deal With It

Linux is known to be very stable, but even the most stable system can encounter situations that cause it to become unresponsive. Then comes the awful feeling as you push and hold “Power”. There are a few tricks with Linux one can attempt in such a case. At this point, we are not looking to save any unsaved work. We want to find a way to avoid a reboot or at least provide the cleanest reboot possible to avoid corruption.

For the purpose of this article, Linux can be seen as a set of 2 stacks: The Kernel Stack and The User Stack. Somewhere inside the User Stack, you have programs running. More than likely X server, a window manager and some programs. You can imagine that list of programs, including the X server, as another stack inside the User Stack. This concept will help newer Linux user understand some of the task we will perform later.

1. Kill an unresponsive program with xkill

If you are using a Linux desktop, your first step should be an attempt to use your window manager’s execute command (alt+f2 in Ubuntu) feature. If you are lucky, it will popup sooner then later.

Then you can execute xkill and point the cursor at the defunct window and click it away.

Xkill works faster than the traditional X icon or right-clicking the window on the taskbar and clicking close. Xkill kills instantly without questions asked.

2. Revive a frozen Linux system with virtual consoles (TTY)

Sometimes, you will not be so lucky, the system may seem completely dead.

This could just be an illusion. Remember the stack of programs inside the user stack? Let’s work with this image for a little bit.

While it may seem like the root of the User Stack would be X. It is not.

X Window System runs on a Virtual Console (VC), also referred to as TTY. They are represented on the filesystem as /dev/ttyX. Linux has multiple VC’s available to you. Attempting to access another one can give you back control.

You can request a different VC by pressing CTRL+ALT+F from a GUI environment or ALT+F from another VC. The above keystroke gives you access to VC 1 through 6. Graphical interface runs on VC 7+.

When dealing with an unstable system, even requesting a change of VC can take a little time, so be a little patient.

If your attempt to change virtual console is successful, you will be prompt for your user and password. You will then have a text mode console. Your system should regain some stability here, this is in parts because the virtual console where X and everything else is running is not a priority anymore.

Once you are logged in you have a few options.

  • You can attempt to kill a defunct program with thekill or killall command.
  • You can kill the window manager, X server or login manager. This will kill all child processes and, if all goes well, your login manager will restart presenting you with your graphical login screen.

3. When everything else fails, talk with the Kernel using SysReq

Sometime, even switching to a TTY does not work. The whole system is dead. Don’t give up yet, once again, more than likely an illusion. Linux holds one more feature for situations like this.

If compiled in the Kernel and enabled in a file, Linux provides you with the means to send preset requests directly to the kernel. This is useful in a situation when the entire user stack is dead. It is known as the Magic SysRq key. Compiled and enabled by default in most distribution, only a Kernel Panic should be able to prevent this from working.

To confirm the option was set when the kernel was compiled, you can attempt to locate your current kernel’s config file in /boot. Look for the option CONFIG_MAGIC_SYSRQ. As previously mentioned it is compiled and enabled in most distributions. To confirmed it is enabled, run the following:

On older systems, you had 2 options: 0 & 1. It was either OFF or ON. On newer ones, there is more fine control over which commands are enabled.

Any value above 1 means some commands are enabled. More details can be found here.

To set a different value temporarily, run the following command:

To change this value permanently, edit /etc/sysctl.conf. Search for kernel.sysrq, and set the desired value.

The easiest way to see if it works is to try. I also recommend testing and learning a set of keystroke while the system is stable. When you execute a SysRq call, the kernel will attempt to respond. This response can only be seen if you are in a virtual console 1 through 6. If the focus cannot be moved away from X, you will not see the responses. This does not mean it is not working.

There are numerous commands that can be sent. The full list can be seen here. I recommend memorizing the following:

Keys Description
Alt + SysRq + r Takes the keyboard out of raw mode, taking control away from X
Alt + SysRq + e Send SigTerm to all process, giving them a chance to quit gracefully
Alt + SysRq + i Send SigKill to all process
Alt + SysRq + k Kill all process in current virtual console
Alt + SysRq + s Sync all mounted filesystem, flushing all data to disk
Alt + SysRq + u Remount all filesystem read-only
Alt + SysRq + b Reboot system instantly, does not sync or unmount
Alt + SysRq + o Shutdown system

This short list of commands gives you a powerful new tool when dealing with an unstable system. When sending request, if you are unable to see the kernel’s responses, give a few seconds in between commands. Pay attention to HDD light when requesting HDD operation.

There is 2 sequence that are worth remembering.

This sequence is good to restart an unresponsive X server. You first get the keyboard out of raw mode with Alt + SysRq + r. You then request to send a SIGTERM to all processes with Alt + SysRq + e. X server may restart with this request. If so, you have rescued your system. If not, proceed with the third request, Alt + SysRq + k. Which will send SIGKILL to all processes within the current virtual console.

If your system is still unresponsive after the above sequence, you should proceed to this next sequence.

This last command will initiate an emergency reboot.

  • r : Get keyboard out of raw mode
  • e : Send SIGTERM to all processes
  • i : Send SIGKILL to all processes
  • s : Sync all mounted filesyste
  • u : Emergency remount read only
  • b : Instantly reboot system

You are now equipped with the best tool against an unresponsive system that I know. You may follow this video from my YouTube channel for a demonstration.

I hope you learned something new about dealing with a frozen Linux system with this article. I would like to know your feedback on it. Please use the comment section and share your thoughts.

Источник

Jovica Ilic

linux | vim | life

Linux gets frozen, what do you do?

Somehow, you crashed your Linux. It’s completely frozen. You try pressing Ctrl + Alt + Backspace, but doesn’t help.

What to do? Someone would press the power button and restart or shut down the system. You shouldn’t do this. This can make you a lot of problems.

What you can do, is to perform a gentle Linux restart. This is much safer way to restart your frozen Linux. To do this, you need to press:

Ctrl + Alt + PrtSc (SysRq) + reisub

Just to make it clear. You need to press and hold Ctrl, Alt and PrtSc(SysRq) buttons, and while holding them, you need to press r, e, i, s, u, b

This will restart your Linux safely.

It’s possible that you’ll have problem to reach all the buttons you need to press. I’ve seen people type reisub with their nose 🙂

So, here’s my suggestion: With your smallest finger on the left hand, press Ctrl. With your thumb on left hand, press Alt. With the smallest finger on your right hand press PrtSc(SysRq) button. This way, you’ll be able to access to reisub buttons with your other fingers.

Okay, but what this REISUB means?

  • R: Switch the keyboard from raw mode to XLATE mode
  • E: Send the SIGTERM signal to all processes except init
  • I: Send the SIGKILL signal to all processes except init
  • S: Sync all mounted filesystems
  • U: Remount all mounted filesystems in read-only mode
  • B: Immediately reboot the system, without unmounting partitions or syncing

You can find the complete list here. There you can see that o shuts down the system. So, if you want to turn off your PC when your Linux crash, you can use this combination:

Ctrl + Alt + PrtSc (SysRq) + reisuo

If you liked the post, we should get connected — follow me on Twitter

ABOUT THE AUTHOR

42 Comments → Linux gets frozen, what do you do?

Note that you should wait a couple seconds after each step (at least after syncing). Also, if you need help remembering the reisub sequence, it’s “busier” backwards 🙂

Good point, thanks for mentioning!

Or REISUB = “Reboot even if system utterly broken”!

“Raising Elephants Is So Utterly Boring”

Never can remember who told me this for the first time, or why they chose that mnemonic, but it’s sure stuck in my head now.

Does this work on systemd based linuxes?

Is that for real?:)

It is for real–but the kernel has to be compiled with , “Magic SysRq” support (I think most stock kernels nowadays are), and then it actually needs to be turned on. I think GNOME/Ubuntu have an option for it in the keyboard layout preferences; otherwise there’s a device file in /proc/ you can write to enable it. See http://en.wikipedia.org/wiki/Magic_SysRq_key for more information.

You can do rk instead of reisub, it will kill all thing on the current vt, you can then do ctrl+alt+f1 and change to the vt1 where you have a shell and can fix all the things without a reboot

I agree with Aleksander. The first thing I would do is switch to a different virtual terminal to see if I can just restart X. If my machine is still accepting keyboard inputs, then it’s a lot cleaner to just Ctrl+Alt+F1 over and kill/restart xorg.

What do you do when Linux gets frozen? Let it go, obviously.

If you watch the screen, you can see the keys I press in the upper right. I change colors to BLUE by typing invisibly “$BLUE$”.

If you need a more deep explanation about this please read :
http://en.wikipedia.org/wiki/Magic_SysRq_key

The classic mnemonic for this sequence is “Raising Elephants Is So Utterly Boring” 🙂 I think you should include it in the post!

As far as I remember sysrq feature can be disabled in kernel, so this can not work by default in some cases.

reisub = Reboot Even If System Utterly Broken 🙂

it still work without to hold prtsc button. only hold ctrl+alt

Ctrl is not needed, Alt + SysRq + is sufficient.

Note that the “magic sys-rq keys” do not take your keyboard layout into account. Dvorak users, for example, need “p.cogx” instead of “reisub”

Also, your system might have this disabled. Check the contents of /proc/sys/kernel/sysrq to see (should be either a 1 or a 0).

“(should be either a 1 or a 0)”

Do such a trick exists on FreeBSD ? .. Nah, it never crash ! :p

FreeBSD does crash. But it takes so long to do anything, you don’t realize that its crashing. In FreeBSD’s case, the best thing to do would be to use the Windows technique of pressing the restart button. Do this after FreeBSD has finally booted up into XWindows, which can take a looong time. You’ll be fine after that. :p

Install Windows instead. Linux freezes a lot. Unless you don’t install anything at all. Then it freezes a bit less.

LOL Have fun with your windows! When windows crashes bill gates can restart it for you remotely.

Or, just tap the power button.

If your box is less than

10 years old and your Linux flavor isn’t strangely configured, it’s a soft power button which will tell the system to initiate a clean shutdown, and bypasses whatever X did to mess up the video and keyboard.

Some systems have that button configured to initiate a hibernation. Probably a better idea to spend your time changing that from hibernation to shutdown than to do the SysRq enabling stuff.

Linux gets frozen? Are we talking the GUI here? How about launch a tty session, ctl+alt+F1? But then, I’ve never had my Linux frozen, must be an Ubuntu thing. Not with my Slackware. 🙂

Yikes. Why would you tolerate an OS that requires restarting?

I am spoiled by WinNT technology (which today’s Windows gets its stability from) as well as Mac OSX. They run for days without crashing.

I remember Windows ME crashing a lot.

Oh! that’s interesting…

But.. But.. I can just hold left-alt + left-ctrl + prtsc with my right hand and hit the other keys with my left hand easily.

Thank You very much for this information. 🙂

Holding down control is optional, but generally helps prevent you taking a screenshot after hitting the “Print Screen” hey.

For hitting the keys, I find using my thumb for alt, the edge of my pinky for control, and my middle finger for Print Screen lets me hit all the keys without stretching too hard. (I do this with my right hand… why would you use your left? Keyboard twister? :D)

You will want to wait 10 seconds after sending the SIGTERM before sending SIGKILL, otherwise you are doing no better than just resetting the power. SIGTERM asks a process to shut down safely by allowing it to do any required housekeeping (like saving files to disk) before exiting. SIGKILL terminates a process immediately. Sending SIGTERM and then immediately SIGKILL can really mess things up as you have basically just told a process to go ahead and do things like writing to disk before then saying “No never mind, die this instant and you are not allowed to do so safely”.

You also want to wait a few seconds between the kill, sync, unmount, and reboot commands too.

To the people saying to use another operating system… The Linux KERNEL never crashes unless there is a serious hardware problem. Generally when a Linux system “freezes”, It’s generally a driver issue. This is every bit true on FreeBSD and Windows as it is Linux. The main difference with Windows is that there are built-in mechanisms for resetting (or even changing to a generic driver) to make things work again. This does not always succeed either…

While it would be great if Linux detected this and recovered in a similar way… you can generally do so yourself by switching to a console. (And then doing something like killing X11 and possibly reloading the kernel module if required.)

Cool, although Alt Gr + PrtScn + seems to be enough on my comp, i.e., no ctrl

> I’ve seen people type reisub with their nose

Источник

Читайте также:  Windows good music player
Оцените статью