www.LinuxHowtos.org

edit this article

Magic SysRq Key

Linux is very stable, but sometimes a kernel panic could happen, sometimes this stops the X-server and you cant change to the console. What should be done? Hitting the reset button and risk filesystem integrity?

NO! There is a possibility to shut down the system cleanly or find out the source of the kernel panic.
For this purpose there is a kernel option called "Magic SysRQ Key" in the section kernel hacking.
If this option is enabled you can use a set of keyboard commands.

Alt+SysRq+r takes keyboard and mouse control from the X server. This can be useful if the X-Server crashed, you can change to a console and kill the X-Server or check the error log.

Alt+SysRQ+k kills all processes on the current terminal. Its a bad idea to do this on a console where X is running. The graphic will stop and you cant see what you type.

Alt+SysRQ+b is like a reset: a reboot without umounting or sync.

Alt+SysRQ+o shuts down via APM.

Alt+SysRQ+s writes all data from the disc cache to the harddiscs, its a sync.

Alt+SysRQ+u remounts all mounted filesystem readonly. After using this key, you can reboot the system with Alt+SysRQ+b without harming the system.

Alt+SysRQ+m prints memory information to the console.

Alt+SysRQ+e sends SIGTERM to all processes except init.

Alt+SysRQ+i sends SIGKILL to all processes except init.

Alt+SysRQ+l sends SIGKILL to all processes, inclusive init. (The system is not working after using this.)...

To shut down the system after a really bad kernel panic, do the following:
Alt+SysRQ+e (sends TERM-signal, processes can shutdown properly (e.g. save data))
Alt+SysRQ+u (a sync will be done when unmounting anyway)
Alt+SysRQ+i (for the processes that didn't listen for the TERM signal, this is a kill -9 process)
Alt+SysRQ+b (reboot).

To be able to use the SysRq feature, you need to do

echo "1" > /proc/sys/kernel/sysrq
or add an entry to /etc/sysctl.conf:
kernel.sysrq = 1

By the way, its a good idea to print this out and store near your PC, when it happens, you can't check back here...

Translated from http://www.pro-linux.de/news/2002/0019.html


rate this article:
current rating: average rating: 1.3 (399 votes) (1=very good 6=terrible)
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back