4

On Ubuntu 15.10 and 15.04 on Lenovo t440p when I'm writing a code in Netbeans and accidently click button AltGr and PrtSc on same time it's crashed and reboot system. This not take action with fresh installed Ubuntu.

This is backtrace from syslog:

Feb  5 19:47:43 mycomputername kernel: [   15.485327] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:44 mycomputername kernel: [   16.966879] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:44 mycomputername kernel: [   17.115697] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:44 mycomputername kernel: [   17.115844] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:45 mycomputername kernel: [   17.644247] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:45 mycomputername kernel: [   17.829425] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:46 mycomputername kernel: [   18.698713] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:47 mycomputername kernel: [   20.033534] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)
Feb  5 19:47:48 mycomputername kernel: [   21.061323] sysrq: SysRq : HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) force-fb(V) show-blocked-tasks(w) dump-ftrace-buffer(z)

How can I disable PrtSc or prevent to accidently clicking PrintScreen on Lenovo keyboard? Or what's problem on this backtrace?

Thanks

1 Answer 1

5

The problem:

On your keyboard, the Print Screen (PrtSc) and System Request (SysRq) are on the same physical button, like on most layouts I know.

The key combinations Alt+SysRq+[SPECIFIC LETTER] are generally known as Magic SysRq Commands which directly send commands to the kernel.

They're mainly used as a safer alternative to a cold reset if the system is completely crashed, because there are e.g. commands to sync and unmount the file system to prevent damage and data corruption and to reset/reboot (if you press B as 3rd key) or power off (3rd key O). More information and a full list of combinations, even with respect to different keyboard layouts, can be found in the corresponding Wikipedia article Magic SysRq Key.

So what you're accidentally doing is to directly send the kernel the command to reboot, and that's what it does.


The solution:

Depending on how your kernel was compiled, you are however able to specify on which SysRq commands the kernel should listen when the system is running. I just tested this on 15.10 with kernel 4.2.0-27-generic and it worked, but it would be nice to learn since when or for what kernels this is enabled. Please comment if you know.

  • Find out the current SysRq command filter value:

    We can learn which SysRq commands are currently enabled by checking the content of the virtual file /proc/sys/kernel/sysrq:

    cat /proc/sys/kernel/sysrq
    

    The result will be a number that must be interpreted like this:

    0 - disable SysRq
    1 - enable SysRq completely
    >1 - bitmask of enabled SysRq functions:
        2 - control of console logging level
        4 - control of keyboard (SAK, unraw)
        8 - debugging dumps of processes etc.
        16 - sync command
        32 - remount read-only
        64 - signalling of processes (term, kill, oom-kill)
        128 - reboot/poweroff
        256 - nicing of all RT tasks
    

    My default value when I'm on the desktop is 176, which is 128+32+16. So according to the table above, I can reboot, poweroff, sync and remount file systems to read-only.

  • Disable all SysRq commands:

    Execute the command below and try whether the SysRq shortcuts still work afterwards (e.g. Alt+SysRq+B to reset/reboot):

    echo 0 | sudo tee /proc/sys/kernel/sysrq
    

    This should disable all SysRq commands for the current session, until you reboot the next time.

  • Enable all SysRq commands:

    To manually enable all SysRq commands, we write the value 1 to the same virtual file instead:

    echo 1 | sudo tee /proc/sys/kernel/sysrq
    
  • Enable previous default SysRq command filter:

    You restore your default configuration by either rebooting, or if you checked and remembered the value before tweaking it, you can set that value again instead of 0/1 to enable/disable all commands.

    So in my case where the original value was 176, I would run:

    echo 176 | sudo tee /proc/sys/kernel/sysrq
    
2
  • 3
    Your solution only holds until the next reboot. The proper permanent solution is to edit /etc/sysctl.d/10-magic-sysrq.conf file.
    – Ruslan
    Sep 22, 2019 at 11:23
  • Hooray. This happened to me three times and this answer (plus comment by @Ruslan) saves a lot of pain.
    – feeela
    Apr 12, 2022 at 9:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .