What do elephants have to with me? Ehmmm, nothing! This post is not about elephants, of course, but about a not so well known feature of the Linux kernel which has to do with safe system termination or reboot.
Suppose you do something silly, like load an unstable kernel driver, or you use unstable versions of some applications or simply you stumble upon a weird bug, and suddenly your system appears to have hanged. Hmmm… what to do? If you were in a Windows environment, you would probably hit the notorious Ctrl+Alt+Delete key combo to get the task manager appear on screen. Then, you would either kill the process that’s causing all the fuss or you would hit reboot or shutdown to safely switch your system off without risking data corruption. I’m sure that everyone who uses windows has been in a situation where simply hitting Ctrl+Alt+Delete did not work, the task manager was nowhere and they were forced to hit the “evil” reset button in dreadful fear and guilt of doing something that could render precious data corrupted.
Unfortunately, you cannot do anything else in that sort of situation. That is, if you are a windows user…
Linux users can feel a lot safer than their friends, the windows users, for their daily chores, because there is more to Linux than hitting a Ctrl+Alt+Del combo each time something becomes unresponsive. Healing a system that appears to be hanged is a series of actions, each action to be taken if the previous fails. Now, here’s what to do in such a case:
- If you are in a desktop session, running GNOME, KDE or any other window manager, press Ctrl+Alt+F1 or F2 or F3… or F6. In Linux user sessions run in virtual terminals. Virtual terminals 7 and above are reserved for graphical sessions running on X, and terminals 1 to 6 are for console sessions. A user can switch any time between any virtual terminal by hitting the Ctrl+Alt+F# key combo, where # is the number of the virtual terminal. So, hitting Ctrl+Alt+F1 for example will switch to console mode and a login prompt will appear. Login, and use the standard shell tools, like top and ps to determine what process is causing the problem and kill it with the kill utility. Then logout and press Ctrl+Alt+F7 to get back to you desktop session.
- If the system refuses to switch to another VT (virtual terminal) try to kill the X session by hitting the Ctrl+Alt+Backspace key combination. This will effectively kill every graphical application and restart the X Server. In the end you should be brought back to the login screen.
- If step 2 fails, then try pressing Ctrl+Alt+Delete. The system will beep and initiate the reboot sequence.
- If you don’t hear a beep, or if you do hear it but the computer is not rebooting after some time, hit the Ctrl+Alt+Delete combo once more. CAUTION! This will do an unsafe reboot. If the system has not unmounted the filesystems in use skip to the next step.
- Something went extremely, horribly wrong. 99% of the time step 1 should suffice. However, even if all of the above fail to give a result, don’t worry. DO NOT in any case hit the reset or power off button. The kernel has a small communications channel open at all times. Even if everything goes wrong you will be able to use this channel to send commands to the kernel. These commands are sent by holding Ctrl+Atl+PrintScrn/SysRq and pressing a letter designating the command. What you need to do is to remember that Raising Elephents Is So Utterly Boring. The first letters of each word is the sequence of commands you must issue to trigger a safe reboot. In other words, if everything else fails hold down Ctrl+Alt+PrintScrn/SysRq and press R E I S U B by waiting a few seconds between each key-press to allow the kernel to finish executing each command. R E I S U B is easily remembered through the mnemonic; Raising Elephants Is So Utterly Boring. Or, you can think BUSIER spelled backwards. I prefer the elephants though .
The sequence of the commands executed are:
Ctrl+Atl+PrintScrn/SysRq + R: Get control of the keyboard device.
Ctrl+Atl+PrintScrn/SysRq + E: Send the SIGTERM signal to all processes except init (PID 1).
Ctrl+Atl+PrintScrn/SysRq + I: Send the SIGKILL signal to all processes except init.
Ctrl+Atl+PrintScrn/SysRq + S: Sync all mounted filesystems. This will flush any unwritten data to your devices and thus prevent data loss or corruption.
Ctrl+Atl+PrintScrn/SysRq + U: Remount all mounted filesystems in read-only mode.
Ctrl+Atl+PrintScrn/SysRq + B: Immediate system reboot. The previous commands must be executed before this one to do a safe reboot.
There are also other commands you may send, but these are the ones needed to reboot in a system hang.
More info on these magic commands can be found here.
So, if you ever get into a tough spot when using your tux machine you won’t have to worry, remember the elephants .