Blog

SysRq – The not so known key

Tags: Server ManagementServersSysRq

Published on: January 7, 2019 by Smith Nevil

SysRq – The not so known key

Scenario:

Lot of details about SysRq is written in the documentation available at https://www.kernel.org/doc/html/v4.11/admin-guide/sysrq.html . If you are a person who prefers the RTFM mode, please go ahead and read the above URL.

What if a linux system seems unresponsive to you? For many years, as with many novices, I used to do a power reset. The normal Ctrl + Alt + Delete or any other keyboard shortcuts won’t work. And depending on the state of file system, I may be faced with a fsck. However there is something called SysRq key (System Request key) which will help you to shutdown the system cleanly. You can see the SysRq written in the PrintScr key or could be Break key. Something you need to use the Fn key as well, like Fn+Alt+SysRQ+ “x”. For a physical console connection, pressing and releasing break and then pressing the Magic SysRQ key would work. i.e no Alt key required.

Magic SysRq key, is a deadly key when used (read misused). Itʼs a direct line to the kernel or in other words, interrupt. You can easily check whether SysRq is enabled or not with the command ‘cat /proc/sys/kernel/sysrqʼ. If disabled, enable SysRq using one of several methods. Usually pass 1 to the file /proc/sys/kernel/sysrq. To make it permanently, add kernel.sysrq =1 in the /etc/ sysctl.conf. However do note that the disabling or enabling of Magic SysRq keys is only referring to the ability to physically trigger them. You can trigger them also by passing the keys as below.

echo “b” > /proc/sysrq-trigger

While passing the key, please make sure that you understand what each “b”s and “c”s do. For example, if you do —> echo c > /proc/sysrq-trigger <— it would crash the linux kernel.

Here is the list of possible values in /proc/sys/kernel/sysrq:

  • 0 – disable sysrq completely
  • 1 – enable all functions of sysrq
  • >1 – bitmask of allowed sysrq functions asee below for detailed function
  • description):
  • 2 = 0x2 – enable control of console logging level
  • 4 = 0x4 – enable control of keyboard aSAK, unraw)
  • 8 = 0x8 – enable debugging dumps of processes etc.
  • 16 = 0x10 – enable sync command
  • 32 = 0x20 – enable remount read-only
  • 64 = 0x40 – enable signalling of processes aterm, kill, oom-kill)
  • 128 = 0x80 – allow reboot/poweroff
  • 256 = 0x100 – allow nicing of all RT tasks

The normal value of `/proc/sys/kernel/sysrq` is as below:

$ cat /proc/sys/kernel/sysrq
176

The command returned a value of 176.  A “0” value disables all the SysRQ function and “1” enables all the features and values above 1 enables specific ones. Here we have a value of 176 which is obtained as a sum of “128” (which allows reboot and poweroff) + “32” (ability to remount filesystems in read-only mode) + “16”, which enables sync command.

To shut down the system after a really bad kernel panic, do the following, in sequence:

Alt+SysRQ+e (sends TERM-signal, processes can shutdown properly)

Alt+SysRQ+i (for the processes that didn’t listen for the TERM signal, this is (kill -9 process)

Alt+SysRQ+s (sync or properly flush any data to disks)

Alt+SysRQ+u (a sync will be done when unmounting anyway)

Alt+SysRQ+b (reboot)

First, you should send the “e” command to SIGTERM all processes thus allowing the opportunity for graceful exits. Processes unable or unwilling to respond to a SIGTERM will need to be handled with the “i” command (SIGKILL ALL THE THINGS). Then, youʼll want to perform Alt+SysRq+s to “sync” or properly flush any data to disks. Next, Alt+SysRq+u will remount all disks as read only. Finally, Alt+SysRq+b will reboot the system. When it comes up, you will not need to perform any file system checking, and you can rest peacefully knowing that you gave every running process your best try at allowing it to close gracefully and write any data to disk consistently.

To perform this process, press and hold the Alt + SysRq key combination and – while holding the Alt and SysRq keys down. To remember this, remember BUSIER, and apply in reverse, like REISUB. You may not need R always. R puts the keyboard to raw mode.

Let us take care of your servers 24/7/365. Get rid of all the hassles of server management.You can contact us at any time. We are always happy to help you.

Category : Sever management

Smith Nevil

Smith Nevil

Smith is always ready to learn new technologies and explore new territories. His never-ending passion towards technological advancements, unyielding affinity to perfection and excitement in the exploration of new areas, help him to be on the top of everything he is involved with. He is currently working as System Engineer at SupportSages.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Categories

Your Cart

Cart is empty.

Subtotal
₹0.00
APPLY
0
Send this to a friend