[HOWTO] Magic SysRq keys - more than just REISUB

Post tutorials, HOWTO's and other useful resources here.
Post Reply
User avatar
Rava
Contributor
Contributor
Posts: 2480
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc1 x86-64 XFCe
Location: Forests of Germany

[HOWTO] Magic SysRq keys - more than just REISUB

Post#1 by Rava » 04 Feb 2020, 16:38

Magic SysRq key
A common use of the magic SysRq key is to perform a safe reboot of a Linux computer which has otherwise locked up (abbr. REISUB).
[…]
● unRaw (take control of keyboard back from X),
● tErminate (send SIGTERM to all processes, allowing them to terminate gracefully),
● kIll (send SIGKILL to all processes except init, forcing them to terminate immediately),
Sync (flush data to disk),
Unmount (remount all filesystems read-only),
● reBoot.
Of special interest, especially even prior a system freeze, might be the command "Print a summary of available magic SysRq keys"

To access it only by itself (without any reboot and such), first you need to switch to a Virtual Console (VT), e.g. by pressing Ctrl+Alt+Fn (n could be anything from 1 to the configured numbers of VTs, in Porteus that is usually 6, but that can be adjusted via settings in /etc/inittab.
Cave! Changing the setting via /etc/inittab requires a reboot to take effect.)

Cave! VT7 / dev/tty7 is usually reserved for the X session. When you are in any VT, you can move to other VTs by either press Alt+Fn, e.g. return to X by pressing Alt+F7, or cycle through all available VTs by pressing Alt+{right arrow key} or Alt+{left arrow key} to move up one VT or move down one VT.

Cave! Once you reached VT7 you will switch back to your X Session: any Alt+{right arrow key} or Alt+{left arrow key} will no longer move you between VTs since the keyboard is returned back to the X session. That is also the reason why the reisub command always starts with the "r" command aka "take control of keyboard back from X".

When you have left your X session and entered the VT, you can either log into an unused VT, best as normal user, to not disrupt the tty1 which is in standard config the VT that auto-started the X session, or just use another VT for displaying the info.
Cave! Disrupting the session in /dev/tty1 could - worst case scenario - end in killing the X session, which would result in all X programs to crash, and none of the X programs would be given the chance to auto-save any changes. You have been warned! Therefore I advise you to not play around on VT1 aka /dev/tty1.

I recommend you log into another VT but tty1 as normal non-root user, e.g. by moving to VT2 via Ctrl+Alt+F2, log in e.g. as guest at the VT login, and then press the Magic SysRq key for "Print a summary of available magic SysRq keys", that is "space" by pressing Alt+SysRq+{Space}

Then the kernel will print onto the current VT the info. E.g. for 5.0rc1 Porteus it would print this:

Code: Select all

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)
(As you can see, all single commands that make up reisub are listed, as should be.)

HTH!
Cheers!
Yours Rava

Post Reply