Friday, July 25, 2008

ATAD #5 - What’s that SysRq key on your keyboard?

The SysRq key is used to give input to the operating system without interfering with the software running (or rather hanged, which you can figure out later in the post) on your system. In essence it's a BIOS routine that triggers INIT 15, bypassing INIT 9 from reading the scan code, and thus the key pressed thereafter is not stored in the keyboard buffer, and to which the kernel will respond to. This will work unless the kernel is completely locked up, in which case you can give another try after tapping the Alt keys a couple of times or will have to head to the nearest "power" button.

In the Linux world the Alt + SysRq key is termed the Magic SysRq key that can be used to fix or debug a frozen system.

It's required to turn on SysRq in order to use it. So make sure this is done after your system installation in case you forecast (pun intended) a system hang. You can do this by setting the kernel parameter, which is in extension of my previous post on linux proc fs

# echo 1 > /proc/sys/kernel/sysrq

On X86 machines you can press ALT-SysRq-(command) to send useful commands (also listed in the wiki article) to the kernel.

ALT-SysRq-C can be used to manually trigger a 'C'rashdump when the system has hanged.

ALT-SysRq-REISUB can be used to manually trigger a neat and safe reboot when your machine has hanged, instead of pounding on the power button and risking HDD problems in the event where data is being written when the system hanged. Its easier remembered as BUSIER spelled in reverse.

And here is what's happening under the hood
R turns off keyboard raw mode and sets it to XLATE / gives back control of the keyboard
E send a SIGTERM to all processes, except for init.
I send a SIGKILL to all processes, except for init
S attempt to sync all mounted filesystems
U mounts all filesystem as read-only to prevent a fsck at reboot
B reboots the system no matter what

__tipped__

2 comments:

knottygal said...

somebody is becoming the "geek!! ;-)
I never realized that there is a key like dat in the keyboard till I read this article..
keep up the good work.. will come back for more "geekiness"!!

Vinay said...

naah, alwayz da "kid" wonlee. ;))

thanks, do visit :)