Browse Source

Add tool for sending Alt-SysRq to VMs

This tool is a helper for sending Alt+SysRq+<key> combination
to the guest OS in VirtualBox VM, which is used in Linux for
printing different sorts of debug messages to the kernel log,
like list of processes, stack traces of CPUs and so on, or for
performing actions: reboot, sync e.t.c. It's very useful when
all other ways to communicate to the VM become unavailable.

Closes-Bug: #1588383
Change-Id: I63864d8e575a73f5efec6e55cc02483a59935307
Dmitry Guryanov 2 years ago
parent
commit
30af233b8a
1 changed files with 82 additions and 0 deletions
  1. 82
    0
      contrib/send-sysrq/send-sysrq

+ 82
- 0
contrib/send-sysrq/send-sysrq View File

@@ -0,0 +1,82 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+#    Copyright 2016 Mirantis, Inc.
4
+#
5
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+#    not use this file except in compliance with the License. You may obtain
7
+#    a copy of the License at
8
+#
9
+#         http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+#    Unless required by applicable law or agreed to in writing, software
12
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+#    License for the specific language governing permissions and limitations
15
+#    under the License.
16
+
17
+import subprocess
18
+import sys
19
+
20
+commands = {
21
+    'reboot': 0x30,
22
+    'crash': 0x2e,
23
+    'terminate-all-tasks': 0x12,
24
+    'memory-full-oom-kill': 0x21,
25
+    'kill-all-tasks': 0x17,
26
+    'thaw-filesystems': 0x24,
27
+    'sak': 0x25,
28
+    'show-backtrace-all-active-cpus': 0x26,
29
+    'show-memory-usage': 0x32,
30
+    'nice-all-RT-tasks': 0x31,
31
+    'poweroff': 0x18,
32
+    'show-registers': 0x19,
33
+    'show-all-timers': 0x10,
34
+    'unraw': 0x13,
35
+    'sync': 0x1f,
36
+    'show-task-states': 0x14,
37
+    'unmount':  0x16,
38
+    'show-blocked-tasks': 0x11,
39
+    'dump-ftrace-buffer': 0x2c,
40
+    'loglevel-0': 0x0b,
41
+    'loglevel-1': 0x02,
42
+    'loglevel-2': 0x03,
43
+    'loglevel-3': 0x04,
44
+    'loglevel-4': 0x05,
45
+    'loglevel-5': 0x06,
46
+    'loglevel-6': 0x07,
47
+    'loglevel-7': 0x08,
48
+    'loglevel-8': 0x09,
49
+    'loglevel-9': 0x0a,
50
+}
51
+
52
+
53
+def usage():
54
+    print("Usage: vbox-sysrq <VM NAME> <COMMAND>\n\n"
55
+          "This tool is a helper for sending Alt+SysRq+<key> combination \n"
56
+          "to the guest OS in VirtualBox VM, which is used in Linux for \n"
57
+          "printing different sorts of debug messages to the kernel log, \n"
58
+          "like list of processes, stack traces of CPUs and so on, or for \n"
59
+          "performing actions: reboot, sync e.t.c. It's very useful when \n"
60
+          "all other ways to communicate to the VM become unavailable.\n\n"
61
+          "Please, set sysctl kernel.sysrq to 1 in the guest OS to make all \n"
62
+          "sysrq commands available:\n\t"
63
+          "sysctl -w kernel.sysrq=1 # in the guest OS\n\n"
64
+          "Examples of usage (useful for fuel developers):\n\n"
65
+          "Increase log verbosity:\n\t"
66
+          "send-sysrq fuel-slave-1 loglevel-7\n\n"
67
+          "Print processes information to the kernel log:\n\t"
68
+          "send-sysrq fuel-slave-1 show-task-states\n\n"
69
+          "Print verbose memory usage to the kernel log:\n\t"
70
+          "send-sysrq fuel-slave-1 show-memory-usage\n\n"
71
+          "Print, what system is doing right now:\n\t"
72
+          "send-sysrq fuel-slave-1 show-registers\n\n\n"
73
+          "Commands:\n\t%s""" % '\n\t'.join(sorted(commands.keys())))
74
+
75
+if len(sys.argv) != 3 or sys.argv[2] not in commands:
76
+    usage()
77
+    sys.exit(1)
78
+
79
+code = commands[sys.argv[2]]
80
+subprocess.call(['VBoxManage', 'controlvm', sys.argv[1], 'keyboardputscancode',
81
+                 '1d', '38', '54', '%.2x' % code,
82
+                 '%x' % (code + 0x80), 'd4', 'b8', '9d'])

Loading…
Cancel
Save