21

The magic SysRq key does not work on my Ubuntu 16.04 desktop. I imagine it's now disabled by default. My attempts to enable it did not work, and the only thing Google finds is a 2007 forum post from when it was apparently enabled by default.

Can I enable it? If so, how?

[Added the following after the first answer:]

According to https://en.wikipedia.org/wiki/Magic_SysRq_key "In Ubuntu the combination of Alt+SysReq acts as "print screen" command." This is in fact the behaviour I observe on a non-hung system, even after doing sudo sysctl -w kernel.sysrq=1 I get some kind of screen capture on my desktop. Not what I want.

It's not practical to write to /proc/sysrq-trigger from a system that's basically hung, trying to get information to debug the problem.

Kevin Bowen
  • 19,395
  • 55
  • 76
  • 81
Arlie Stephens
  • 329
  • 1
  • 3
  • 8
  • Looks like a dup to me too, or more correctly it looks like the answers also answer my question, which is not really the same - I'm not just interested in one specific non-working sysrq option. I'll try the suggestions there, and see whether they still work; it's possible that additional changes to Ubuntu have made them out of date. (The question dates to 2013.) – Arlie Stephens May 05 '17 at 03:48

1 Answers1

25

To enable sysrq magic keys temporarily:

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

or # sysctl -w kernel.sysrq=1

This enables sysrq magic keys for the current user session. You can disable it again by exchanging 1 with 0 in the above commands. Or go back to the standard value of 176.

To enable these changes at boot time one has to create config file in the sysctl.d directory (e.g. /etc/sysctl.d/90-sysrq.conf) with this line:

kernel.sysrq=1

So setting /proc/sys/kernel/sysrq to 1 enables the sysrq magic keys, setting it to 0 disables it.

wjandrea
  • 14,109
  • 4
  • 48
  • 98
jarleih
  • 696
  • 1
  • 6
  • 18
  • 3
    I tried that. Unfortunately this is ubuntu. Quoting wikipedia " In Ubuntu the combination of Alt+SysRequest acts as "print screen" command." And that's what I got – Arlie Stephens May 04 '17 at 14:56
  • Well, sorry about that. I'm using KDE Neon, which is based on Ubuntu 16.04, and it worked for me. – jarleih May 04 '17 at 18:58
  • 1
    Unity strikes again :-( – Arlie Stephens May 05 '17 at 03:42
  • 4
    @ArlieStephens no you can, just edit /etc/sysctl.d/10-magic-sysrq.conf to change at the value you wish. Read more carefully wikipedia ;-) – tmow May 04 '18 at 08:58
  • 2
    Still doesn't work, even after `/proc/sys/kernel/sysrq` and `/etc/sysctl.d/10-magic-sysrq.conf` are both set to '1' – Coder Guy May 01 '20 at 22:33
  • @ArlieStephens: to workaround the "print screen" aspect: keep pressing `Alt` key, release `SysRq` key, press command key (e.g., `f` key to kill a memory hog https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html ). To test it, try `Alt+SysRq+h` and see the help message in `dmesg|tail`. – jfs May 05 '22 at 05:24
  • Sudo version: `echo 1 | sudo tee /proc/sys/kernel/sysrq` – kenorb Oct 13 '22 at 17:40