4

I have access to the system console of a KVM guest through VNC. What key codes do I need to send for the magic sysrq sequence (Ctrl+Alt+"REISUB") in Linux?

Edit: In Linux under qemu, running showkey and the command sendkey alt-sysrq-h in the QEMU monitor reveals keycodes 99 (SysRq?), 56 (Alt), and 35 (H). Using UltraVNC Viewer's Send Custom Key command, none of those numeric codes came out correctly when entered and viewed through showkey.

  • Do you have access to the qemu commandline (usually Ctrl-Alt-3) or virsh? Because I'm pretty sure this does not work over VNC. Here is the HOWTO do this with virsh. – mirabilos Dec 24 '13 at 0:03
  • I do not, unfortunately. Out of curiosity, why do you think this wouldn't work over VNC? Does QEMU filter the keycode for SysRq from the VNC console? – user314104 Dec 24 '13 at 5:14
  • I think there is no such thing as SysRq in VNC, that’s why… sadly, the docs imply that you cannot access the “Qemu monitor” (which is what I meant with “commandline” above) via VNC, only via -nographics or SDL, or, possibly, when binding (redirecting) the monitor to some character device. Sorry. – mirabilos Dec 24 '13 at 8:46
  • @mirabilos your link is dead. web.archive.org/web/20140122204434/http://… – n611x007 Jan 5 '16 at 15:06
1

Yes, this is possible, at least from NoVNC with KVM based guest. The trick is to understand that VNC has been built for X11. Hence, on the wire, the keycodes you need to send are the one used internally by X11.

In this specific use case, this is:

0xffe9 --> alt
0xff15 --> sysrq
0x0062 --> b

Sources

5

The documentation for sysrq is in the linux source code (https://github.com/torvalds/linux/blob/master/Documentation/sysrq.txt). I very highly recommend that you read it.

Is SysRq key enabled?

First, please ensure that the use of the magic SysRq key is enabled:

$ cat /proc/sys/kernel/sysrq
1

If it says 0 then SysRq is disabled. You can enable it with:

$ echo 1 > /proc/sys/kernel/sysrq

And it will be effective immediately. There are security implications in enabling the magic key and there is some good documentation on the TLDP website.

Based on some keyboard layouts found on wikipedia. You can try the combination involving PrtScr / Print Screen.

On my system: Alt + PrtScr + "OTHER". This is the same sequence as described on this wikipedia article.

Getting SysRq keycode:

You can run showkey to scan keycodes / get scancodes:

$ showkey -s
0x38                 - i'm pressing Alt
0xb8                 - releasing Alt
0xe0 0x2a 0xe0 0x37  - print screen
0xe0 0xaa 0xe0 0xb7  - release print screen
0x38                 - i'm pressing Alt
0x54                 - i'm also pressing print screen
0x23                 - letter H
0xa3                 - bye bye letter H
0xd4                 - releasing print screen
0xb8                 - releasing Alt

0x54 = 84 would be the Alt+PrtScr which becomes SysRq.

Let's confirm that:

$ getkeycodes 
Plain scancodes xx (hex) versus keycodes (dec)
for 1-83 (0x01-0x53) scancode equals keycode

 0x50:   80  81  82  83  99   0  86  87
 0x58:   88 117   0   0  95 183 184 185
 0x60:    0   0   0   0   0   0   0   0
 0x68:    0   0   0   0   0   0   0   0
...

My system maps that scancode 0x54 to keycode 99 which is KEY_SYSRQ. Double checking:

# rpm -ql kernel-headers | grep input.h | xargs grep KEY_SYSRQ
/usr/include/linux/input.h:#define KEY_SYSRQ        99

SysRq useful combinations:

  • Alt + PrtScr + D - this is a bad combo for my system and gives me the help

    SysRq : HELP : loglevel(0-9) reBoot Crash terminate-all-tasks(E)
    memory-full-oom-kill(F) kill-all-tasks(I) thaw-filesystems(J) saK
    show-backtrace-all-active-cpus(L) show-memory-usage(M) nice-all-RT-tasks(N)
    powerOff show-registers(P) show-all-timers(Q) unRaw Sync show-task-states(T)
    Unmount show-blocked-tasks(W) dump-ftrace-buffer(Z)
    
  • Alt + PrtScr + H - actual help keystroke

    SysRq : HELP : loglevel(0-9) reBoot Crash terminate-all-tasks(E)
    memory-full-oom-kill(F) kill-all-tasks(I) thaw-filesystems(J) saK
    show-backtrace-all-active-cpus(L) show-memory-usage(M) nice-all-RT-tasks(N)
    powerOff show-registers(P) show-all-timers(Q) unRaw Sync show-task-states(T)
    Unmount show-blocked-tasks(W) dump-ftrace-buffer(Z)
    
  • Alt + PrtScr + B - reboot
  • Alt + PrtScr + C - crash the system (with crashdump)
  • Alt + PrtScr + E - SIGTERM every task except init
  • Alt + PrtScr + F - call OOM killer
  • Alt + PrtScr + M - outputs memory / swap stats
  • Alt + PrtScr + O - power off
  • Alt + PrtScr + S - sync all mounted filesystems
  • Alt + PrtScr + U - remounts all filesystems as read-only
  • Alt + PrtScr + T - outputs list of tasks with traces

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.