The Magic SysRq Key

     When compiling your own Linux kernel, have you ever wondered just what the last option having to do with the "Magic SysRq Key" is? As luck would have it, this is one of the most useful options a small Linux system can enable.

     Linux is stable, but let's face it -- there's a lot of beta-quality hardware and software out there. Sometimes things just lock up, and then you're forced to hit reset, wait for fsck to do its thing, and potentially even lose data because you didn't get a chance to sync before restarting. This is where the magic SysRq key comes in. When enabled, it provides a set of "emergency" options which will usually work even when the rest of the system (even X) seems to be locked up hard. With this option enabled, the following keystrokes will be available at all times:

ALT-SysRq-k Kills all processes (including X) which are running on the currently active virtual console. This keystroke can be very useful if your graphics hardware has a habit of freezing with your version of XFree86.
ALT-SysRq-s Will attempt to run an emergency sync on all mounted filesystems. This won't eliminate the need to fsck when the system starts again if you have to use the reset button, but it can certainly prevent data loss. Note that the sync won't always be successful -- for example, if the cause of your freeze is disk-related in the first place.
ALT-SysRq-u Will attempt to remount all mounted filesystems as read-only. This has the same effect as the sync keystroke above, but with one important difference: if the operation is successful, fsck won't have to check all filesystems after a reset.
ALT-SysRq-e
ALT-SysRq-i
These two keystrokes have a similar effect, but one is more violent than the other. The ALT-SysRq-e keystroke will send the TERM signal to all running processes except init, asking them to exit. This can be useful if you have a number of runaway processes that you need to kill quickly. The ALT-SysRq-i keystroke does the same thing, but with the KILL signal instead, which may be more successful in killing runaway processes, but may cause some of them not to exit normally.
ALT-SysRq-r Pulls the keyboard out of raw mode. This can be useful when an X session freezes; after issuing this keystroke you may, for example, be able to use CTRL-ALT-DEL and a little patience to get a clean reboot.