enabling sysrq
sysrq is a lowlevel keybinding implemented in the kernel to debug the system when it’s not responsive.
§ enable on archlinux (systemd)
on archlinux sysrq is disabled by default.
via. changing kernel parameters
by default the sysrq parameter only allows “sync”.
$ (sudo) sysctl --system
kernel.sysrq = 16 (0x10)
# note this command will bring your sysctl config to system default.
# if you already have manual settings they may get lost.
Configurations 1
0 = 0x0 - disable sysrq completely
1 = 0x1 - enable all sysrq functions
2 = 0x2 - enable control of console logging level
4 = 0x4 - enable control of keyboard (SAK, unraw)
8 = 0x8 - enable debugging dumps of processes etc.
16 = 0x10 - enable sync command
32 = 0x20 - enable remount read-only
64 = 0x40 - enable signalling of processes (term, kill, oom-kill)
128 = 0x80 - allow reboot/poweroff
256 = 0x100 - allow nicing of all RT tasks
do with care
# replace N with proper permission bits. Use 1 to enable all
# via sysctl
sysctl kernel.sysrq=<N>
# or via proc fs
echo "<N>" > /proc/sys/kernel/sysrq
persistent config:
modify /etc/sysctl.d/<parameter file>
kernel.sysrq = <N>
§ use
on x86: Alt-SysRq-CommandKey
. Or Alt-PrintScreen-CommandKey
.
(my case) where PrintScreen
needs Fn
to trigger (Home
and PrtScr
on the
same key): Keep holding down Alt
, press Fn + Home(PrtScr)
, then release Fn+ Home(PrtScr)
(keep Alt
pressed, then press the CommandKey
Example usage:
- in case the display server freezes (xorg, wayland …) and doesn’t respond to
keboard, can use
Sysrq + r
to “unraw” the keyboard mode, then bring up the tty usingCtrl+Alt+F<1234>
. - “recover” the keyboard mode from
Sysrq+r
, if you fixed your issue and dicide to continue using the system without rebooting.
where$ sudo kbd_mode -s -C /dev/ttyN
/dev/ttyN
poitns to thetty
that X (or wayland) is running. To figure that out, perhaps usesudo fgconsole
[+] click to expand the commandkeys
CommandKey
b Will immediately reboot the system without syncing or unmounting your disks.
c Will perform a system crash and a crashdump will be taken if configured.
d Shows all locks that are held.
e Send a SIGTERM to all processes, except for init.
f Will call the oom killer to kill a memory hog process, but do not panic if
nothing can be killed.
g Used by kgdb (kernel debugger)
h Will display help (actually any other key than those listed here will display
help. but h is easy to remember :-)
i Send a SIGKILL to all processes, except for init.
j Forcibly “Just thaw it” - filesystems frozen by the FIFREEZE ioctl.
k Secure Access Key (SAK) Kills all programs on the current virtual console.
NOTE: See important comments below in SAK section. (see link)
l Shows a stack backtrace for all active CPUs.
m Will dump current memory info to your console.
n Used to make RT tasks nice-able
o Will shut your system off (if configured and supported).
p Will dump the current registers and flags to your console.
q Will dump per CPU lists of all armed hrtimers (but NOT regular timer_list
timers) and detailed information about all clockevent devices.
r Turns off keyboard raw mode and sets it to XLATE.
s Will attempt to sync all mounted filesystems.
t Will dump a list of current tasks and their information to your console.
u Will attempt to remount all mounted filesystems read-only.
v Forcefully restores framebuffer console
v Causes ETM buffer dump [ARM-specific]
w Dumps tasks that are in uninterruptible (blocked) state.
x Used by xmon interface on ppc/powerpc platforms. Show global PMU Registers on
sparc64. Dump all TLB entries on MIPS.
y Show global CPU Registers [SPARC-64 specific]
z Dump the ftrace buffer
0-9
Sets the console log level, controlling which kernel messages will be printed to
your console. (0, for example would make it so that only emergency messages like
PANICs or OOPSes would make it to your console.)
R: Replay the kernel log messages on consoles.
§ more context
what is “raw” keyboard mode
https://unix.stackexchange.com/questions/16530/
I think that’s a post on its own about how keyboard works. Basically there are
kbd_mode
, man 1 kbd_mode
-s
scancode (RAW)-k
keycode (MEDUIMRAW)-a
ASCII (XLATE): Sysrq + r sets kbd mode to this.-u
UTF-8 (UNICODE)
Extra: kbdkbmode (since linux 2.6.39) can be set to K_OFF
(0x04). Which is the
case for my environment (wayland/sway). Interestingly kbd_mode
doesn’t support
this yet. (And it tells me the keyboard is in “UNKNOWN” mode)