SARPi Project - Slacking 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 + 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 key mentioned but you might not see a key on your keyboard labelled as such. That's because on modern [Windows] keyboards the key is the key, which is more commonly labelled as the key.

SARPi Project muse views ... 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

SARPi Project muse views ... 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 + + 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:

+ + 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 + + (and other F-? key) combinations to switch to another console and restart X.

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

SARPi Project muse views ... 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 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.

SARPi Project muse views ... 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 + + ) is known to fix this problem. Switching to another virtual console + and then back again might solve this issue too.

Thanks!

Thank you for reading and taking part in this SARPi mini-project. We hope you enjoyed it and found it interesting and educational.

Thanks also to Patrick Volkerding, and the entire Slackware Team, for producing a truly wonderful OS. Without you, and the work you do, the SARPi Project would not exist.

If you have any questions or need help, visit the Slackware Linux Forum on Linux Questions. Or get in touch on the #SARPi IRC channel on irc.libera.chat.

Back to Top


Updated: 2024-03-13 05:02:33 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. SARPi Project is in no way affiliated with Slackware Linux, Inc, or the Linux Foundation, or Raspberry Pi Ltd., or any of their respective members, trustees, partners, or associates.


Accept!

SARPi Project uses cookies for website traffic data analytics purposes only. Cookies from this website do not collect or store any of your personal data.

Please read the SARPi Project website [ Cookie Policy ] for more details.