71 lines
2.7 KiB
Markdown
71 lines
2.7 KiB
Markdown
|
---
|
|||
|
title: Safely reboot a frozen Linux System - SysRq
|
|||
|
date: "2018-02-18"
|
|||
|
categories:
|
|||
|
- misc
|
|||
|
tags:
|
|||
|
- english
|
|||
|
- linux
|
|||
|
summary: Sometimes your Linux is just utterly broken and hung up. This is how you make your system shut down in an orderly fashion to avoid data corruption on your file-system
|
|||
|
cover:
|
|||
|
image: "/images/crashed.jpg"
|
|||
|
showtoc: false
|
|||
|
---
|
|||
|
|
|||
|
|
|||
|
Until today, I thought the SysRq-Key (like the Scroll Lock Key) is one
|
|||
|
of the useless keys on a modern keyboard. Today I got asked if modern
|
|||
|
operating systems handle the startup triggered by a reboot different
|
|||
|
from a cold boot.
|
|||
|
|
|||
|
While I <s>didn't find an answer to the initial
|
|||
|
question</s> ([Wikipedia](https://en.wikipedia.org/wiki/Reboot_(computing)#Cold_vs._warm_reboot)
|
|||
|
to the rescue) I stumbled upon
|
|||
|
[this](https://en.wikipedia.org/wiki/Magic_SysRq_key).
|
|||
|
|
|||
|
Basically, the Linux kernel is permanently waiting for special key
|
|||
|
events. Whenever you press Alt + SysRq + B, your machine will
|
|||
|
immediately reboot. This is nice to know, but not really "save" as it
|
|||
|
doesn't gracefully stop the running programs and also doesn't finish
|
|||
|
writing to disk. So we have to tell the Kernel to do exactly this.
|
|||
|
|
|||
|
The Wikipedia mentions a nice acronym to remember the keystrokes.
|
|||
|
|
|||
|
> **R**eboot **E**ven **I**f **S**ystem **U**tterly **B**roken
|
|||
|
|
|||
|
**Slowly** pressing those keys together with Alt + SysRq will trigger
|
|||
|
the following events.
|
|||
|
|
|||
|
R — will take keyboard control away from X.
|
|||
|
|
|||
|
E — will send a so-called SIGTERM, this is the request the kernel
|
|||
|
sends whenever a program should stop gracefully. You could imagine this
|
|||
|
as a bouncer asking you to leave.
|
|||
|
|
|||
|
I — will go one step further, it will send SIGKILL, this signal tells
|
|||
|
the process to just go away, imagine the bouncer violently throwing you
|
|||
|
out. This will close all processes which are hung up or refuse to shut
|
|||
|
down.
|
|||
|
|
|||
|
S — will sync all data to disk. Now give it some seconds until you do
|
|||
|
the next step, to make sure it really wrote everything to disk.
|
|||
|
|
|||
|
U — will remount all file-systems as read-only. It's not possible to
|
|||
|
unmount all file-systems while running, so this is the closest you'll
|
|||
|
get.
|
|||
|
|
|||
|
Now press B which forcefully and immediately reboots.
|
|||
|
|
|||
|
If all this didn't work, then either your kernel crashed (at which point
|
|||
|
your system is already shut down) or this feature is disabled in your
|
|||
|
current OS/Kernel release. If you want to enable it, have a look at the
|
|||
|
[ArchWiki](https://wiki.archlinux.org/index.php/Keyboard_shortcuts#Kernel),
|
|||
|
it's a great resource for Linux tutorials even if you don't use an
|
|||
|
ArchLinux derivative.
|
|||
|
|
|||
|
## tl; dr
|
|||
|
|
|||
|
Pressing Alt + SysRq and then very slowly entering "REISUB" while still
|
|||
|
holding the Alt key will restart your system gracefully. If it doesn't
|
|||
|
work, either the kernel crashed or this functionality is disabled.
|