SARPi Project - 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:

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 disable 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:

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:

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.


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!


SARPi Project Team

Back to Top

Updated: 2021-04-06 12:46:18 UTC

Disclaimer: The SARPi Project website is for non-commercial and general information purposes only. The content is provided by Penthux.NET and while we endeavour to keep information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or any information, software, products, services, or related graphics which is available on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk. In no event will Penthux.NET be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this website or any of its contents. Through this website you are able to visit other websites which are not under our control. Penthux.NET has no influence over the nature, content or availability of any external URLs. The inclusion of any URLs does not necessarily imply a recommendation or endorsement of any content therein. Every effort is made to ensure the SARPi Project website remains accessible. However, Penthux.NET takes no responsibility for, and will not be liable for, the SARPi Project website being temporarily unavailable due to technical issues beyond our control. Penthux.NET is in no way affiliated with Slackware Linux, Inc, or the Linux Foundation, or the Raspberry Pi Foundation, or any of their members, trustees, partners, or associates.

SARPi Project uses cookies for website traffic & data analysis. [ Cookie Policy ]