The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

When Ctrl-Alt-Del fails on Linux: Fix a Frozen System with the Magic SysRq Keys (via FOSSwire)

Posted by jpluimers on 2024/04/26

Ctrl-Alt-Del will not safely reboot all systems under all circumstances.

If you run Linux, your keyboard has a magic RysRq key (sometimes not marked, but its the same key as the Print-Scrn key) and the Linux kernel is still running not all is lost.

Due to link rot, the archived links are the most recent that have all the comments for [Wayback/Archive] Fix a Frozen System with the Magic SysRq Keys | FOSSwire which amend

You finally got your Linux environment to crash. Ctrl+Alt+Backspace does nothing, nor do the F-keys. You know you shouldn’t have installed that bad driver, but you did it anyway.
So you reach for the power button.
Stop.
Mashing in the power button to reboot could cause a problem if your hard drive is still being written to, and usually causes more problems than it solves. The Linux kernel includes a secret method of restarting your PC should it ever stop doing its job.
  1. Hold down the Alt and SysRq (Print Screen) keys.
  2. While holding those down, type the following in order. Nothing will appear to happen until the last letter is pressed: REISUB
  3. Watch your computer reboot magically.

This 2007 comment makes it easier to remember: REISUB is the reverse of BUSIER:

R E I S U B – is just the word busier in reverse.

Sometimes keep less keys pressed down

Not all keyboards support keeping many keys pressed down at once (modern keyboards are worse with the exception of Das Keyboard a grammatically wrong play on German as “Die Tastatur” is the correct translation of “the keyboard”), so you might need to try what does.

For more details see

[Wayback/Archive] linux – Why does Alt+SysRq+B not always trigger while REISU do? – Unix & Linux Stack Exchange (thanks [Wayback/Archive] Ruslan):

The problem is not in software, it’s in hardware. Keyboard keys are not independent: there’re about 100 keys, but only about 26 wires going into keyboard’s internal controller

This means that not all keys can be detected when simultaneously pressed. Because RAlt is much closer to SysRq than LAlt, I always use it to free one hand for entering chars.

Then the sequence which appears to work is:
  • Press RAlt
  • Press SysRq
  • Release SysRq
  • Press B
  • See reboot
For LAlt things appear much simpler: the keyboard is able to detect B when LAlt+SysRq is held, so there’s no problem

SysRq has been there since very long

The cool thing is that a completer list of SysRq commands has been on Wikipedia all along; the above article “just” made this sequence famous (and isn’t quoted or referenced often enough).

Luckily another 2007 comment mentions Magic SysRq key – Wikipedia

The article has a table for these keyboard layouts: QWERTY, Dvorak, AZERTY, Colemak.

It also mentions this small help text the kernel can emit if text output still functions:

Output of the SysRq+h on a x86_64 kernel:

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)

Via

The below links got me to the above Wikipedia and FOSSwire articles:

  • [Wayback/Archive] centos – Ctrl-Alt-Del equivalent on Linux? – Unix & Linux Stack Exchange (thanks [Wayback/Archive] Michael, [Wayback/Archive] user000001, [Wayback/Archive] Quasímodo and [Wayback/Archive] marcelm)

    Q

    On Windows, Ctrl-Alt-Del helps in these situations; does Linux has a way to knock through into an overloaded system?

    A

    Ctrl + Alt + F4 opens a console window, where you can login and kill stuff as necessary or reboot the system. Use Ctrl + Alt + F2 or Ctrl + Alt + F1 to go back.
    In some cases you can restart the gnome session by pressing Alt + F2, and the R in the window that opens. This should leave all programs running, but gnome itself will restart, so if the issue is in gnome it may help.
    If the above don’t help, you can do a warm reboot, by pressing the following key sequence:
    While keeping pressed down both the Alt and Print Screen keys, sequentially (one by one) press the keys:
    R E I S U B

    C

    If resorting to Sysrq, I like to try F, which invokes the OOM killer, before sending any other signal to all processes. Many times I’ve recovered from a stray, memory hogging process without losing my current session.

    C

    “While keeping pressed down both the Alt and Print Screen keys, …” – You don’t need to hold down Print Screen while doing the other keys! Just hold down Alt, and then press, in sequence, Print ScreenRE, etc. Much easier. Also consider SysRq+K, which will kill all processes on the current virtual terminal. You’d lose your graphical session, including hopefully your runaway process, but not the system. (I’m not 100% sure SysRq+K still works as expected with Wayland, never tried it)

  • [Wayback/Archive] REISUB – the gentle Linux restart | Andrew Kember
    • R: Switch the keyboard from raw mode to XLATE mode
    • E: Send the SIGTERM signal to all processes except init
    • I: Send the SIGKILL signal to all processes except init
    • S: Sync all mounted filesystems
    • U: Remount all mounted filesystems in read-only mode
    • B: Immediately reboot the system, without unmounting partitions or syncing
  • [Wayback/Archive] Gently Restart a Frozen System

–jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.