Saturday, June 09, 2007

How to recover an Ubuntu/Linux PC

People often claim that Linux is more stable than Windows. Without hard statistics, this can't really be proven. One thing I do know however, is that when things go wrong it is much easier to recover a Linux PC than a Windows one, without restarting. In this post I will explain what to do, in easy steps, to get your Linux back running as safely as possible.

1. Kill a single graphical application
If you know the problem is a single application that you have open that maybe just froze then it is simple to fix. Press Alt+F2 and type 'xkill' (without the quotes) then press enter. This runs the xkill program, and the next application that you click on will be forced to close. If you change your mind, press the right mouse button to exit from this mode.

It may be worth setting a keypress that will automatically start xkill when you need it. In Ubuntu/GNOME, go to System->Preferences->Keyboard Shortcuts

2. Restart the graphical interface
If you are still having problems, or the whole of the graphical interface is not responding, press Ctrl+Alt+Backspace. This will attempt to stop the graphical display, and then restart it. Any applications you had open will be killed.

3. Switch to a console to end the application
If this didn't work, or you know a certain program is causing the problem, you can kill that program without using the graphical interface. Press Ctrl+Alt+F1. If your PC is running, but slowly, this may take a minute. Eventually you should end up at a text login screen. Log in with your usual username and password, and wait for the prompt to appear.

If you know the name of the program causing the problems, type: killall <program name>. If it continues, you can try to force it to stop, with: killall -KILL <program name>. For system process you may get "Permission Denied" errors. Prefix the above commands with "sudo ", ie. sudo killall...

If you are not sure which program is making the PC unresponsive, use the 'top' command. It shows a list of running programs, and their name, and in the CPU column it shows how much of the computer's processor they are using up. Once you identify the application press 'q' to exit top, and use the commands above to kill the program.

If all is now working, Ctrl+Alt+F7 will switch back to the graphical interface.

4. Emergency reboot procedure
If the steps above all failed, there is one last way to reboot your computer, and it is much safer than pressing the reset button on your PC's case, or pulling out the power cable.

It is important that you type these key combinations in the correct order, allowing the PC some time to complete the command between each one. The SysRq key on your keyboard is often also labelled as "Print" or "Print Screen".

Ctrl+Alt+SysRq+R
Switches the keyboard mode.
Ctrl+Alt+SysRq+S
Writes all data to the disks, necessary to avoid data corruption, unsaved files will still be lost.
Ctrl+Alt+SysRq+E
Tries to end processes in a nice way. Allow a little bit of time before you use the next command.
Ctrl+Alt+SysRq+I
Tries to forcefully kill processes that have not closed.
Ctrl+Alt+SysRq+U
Temporarily makes the hard disks read-only, this makes it safe to reboot.
Ctrl+Alt+SysRq+B
Force reboot.

5. Surrender
If that didn't reboot your PC, press the reset switch, or pull the plug, and cross your fingers :)


If you have any other methods, tips, or feedback to share, post a comment and let me know!

2 comments:

Paul said...

There's a runaway process killer applet for KDE :).

KWin/KDE also detects when an app has crashed and offers the possibility to terminate it.

Matthew said...

> There's a runaway process killer applet for KDE :).

GNOME too :P

> KWin/KDE also detects when an app has crashed and offers the possibility to terminate it.

(GNOME|Beryl) too :P :P

Still, xkill is as good as a panel applet (though I bind a keypress to it) and if KWin/GNOME detects an application is hung, a guide such as this is not needed anyway...