Slackware ARM on a Raspberry Pi


The magic SysRq key

From time to time your Raspberry Pi system software may cause you problems. On the occasions when CTRL + C key combinations (etc.) aren't working or your system isn't responding to your commands, through key-presses or mouse-clicks, there's usually a means by which you can send instructions to the kernel directly.

In Linux, the kernel can be configured to accept commands, which provide functions for system debugging and crash recovery, and other eventualities These commands invoke the "magic SysRq key" as it's known. The magic SysRq key interacts with the kernel to perform various low-level commands regardless of the operating system's running status. It can be most useful when recovering from freezes, or to reboot a computer without corrupting the filesystem, and includes a lot of options and control functions.

On this page you will see the SysRq key mentioned but you might not see a key on your keyboard labelled as such. That's because on modern [Windows] keyboards the SysRq key is the Print Screen key, which is more commonly labelled as the Prt Scr key.

The magic SysRq key needs to be activated in the kernel before it can be used on the system. Most modern Linux distributions include this feature by default. Slackware certainly does.

NB: The magic SysRq key won't work under certain conditions, such as a kernel panic (or hardware failure) which prevents the kernel from running properly.

A common use of the magic SysRq key is to perform a safe reboot of a Linux computer which has otherwise locked-up or hung. This gives certain programs the opportunity to make emergency backups, etc. Magic SysRq key can also be accessed via the serial console, and utilised to provide extended administration capabilities to headless or remote systems.

How to use the magic SysRq key

You should take some time to do a bit of old school homework beforehand. There's a Wikipedia page for the Magic SysRq key that you should read. Read it twice, at least. Familiarise yourself with the magic SysRq key combinations in X windows enviroment, command structure, and how to invoke magic SysRq key through the command-line. It doesn't take long and will give you a very good understanding of the function before you start to play around with it.

Magic SysRq key guide: https://en.wikipedia.org/wiki/Magic_SysRq_key

HIGHLY recommended reading for further edification is The Linux keyboard and console HOWTO [.PDF file] from The Linux Documentation Project.

Magic SysRq key on command-line

One thing to note is that you need to be 'root' user in order to call on the magic SysRq key functions via the command-line. However, anyone who has access to your keyboard can invoke the magic SysRq key through key-press combination(s). For example, pressing ALT + SysRq + C will perorm a system crash! It might be, in similar situations, prudent to diable the magic SysRq key function unless you really need to use it.

You can check whether magic SysRq key is enabled by viewing the contents of following file:

root@slackware:~# cat /proc/sys/kernel/sysrq

The value specified in '/proc/sys/kernel/sysrq' file indicates that "1" enables the SysRq magic keys, and "0" disables it.

You can disable magic SysRq magic key temporarily from the command line by typing:

root@slackware:~# echo "0" > /proc/sys/kernel/sysrq

You can ensable magic SysRq key again by using "1" instead of "0" in the above command.

Magic SysRq key in X desktop

If/when your desktop freezes/crashes you may find yourself unable to use your system as normal. However, there are usually a few magic SysRq key combinations that can help you out of a bad situation:

Alt + SysRq + R takes the keyboard from 'raw mode' [i.e. the mode used by programs such as X11] to 'XLATE mode' After running this combination, you should be able to use the Ctrl + Alt + F1 (and other F-? key) combinations to switch to another console and restart X.

The key combination Alt + SysRq + K will kill all programs on the current virtual console. Pressing Alt + SysRq + R restores the keyboard to 'XLATE mode' where you can type.

Issues when running X windows can put your keyboard in a different mode [e.g. for keys that are assigned as triggers, for X events and mapped to a certain character-set and window, this can be a terminal problem]. In these situations it would be wise to refer to the magic SysRq key functions instead of reaching for the Reset button and risk damaging your filesystem!

If you haven't done so already, read the magic SysRq key guide: https://en.wikipedia.org/wiki/Magic_SysRq_key

Keyboard Mode

You can define which type of character code your keyboard sends to the system. This is achieved via the 'kbd_mode' command. You are also able to input the 'kbd_mode -options' command into '/dev/console'. It makes good sense to be aware of the different keyboard modes available, especially for times when your system is not operating within establshed parameters. Or when a program has unexpectedly changed the mode of your keyboard and you need to revert it.

kbd_mode -a > /dev/console

This command will put your keybord in 'ASCII' mode.

The following 'kbd_mode' options are quoted from the kbd_mode manpage:

-s: scancode mode (RAW)
-k: keycode mode (MEDIUMRAW)
-a: ASCII mode (XLATE)
-u: UTF-8 mode (UNICODE)

Warning! Changing the keyboard mode (other than between ASCII and Unicode) will probably make your keyboard unusable! The 'kbd_mode' command is only meant for use [via remote login] when, for example, a program left your keyboard in the wrong mode.

If you haven't done so already, read the magic SysRq key guide: https://en.wikipedia.org/wiki/Magic_SysRq_key

Magic SysRq key tips

Sometimes SysRq seems to hang after using it. Tapping the shift alt and control keys on on both sides of the keyboard, whilst selecting an invalid magic Sysq key sequence (such as Alt + SysRq + Z) is known to fix this problem. Switching to another virtual console ALT + Fn and then back again might solve this issue too.

Thanks

The SARPi Project hopes the information in this mini-project was helpful or useful. If you have any questions, or need assistance please use the Linux Questions Slackware ARM Forum.

Thanks for your interest in our efforts!

Regards,

SARPi Project Team

Back to Top



Updated: 31 Jul 2019 11:37:18