As I see too many people using a hard power off during freezes, I'm creating this small tutorial on how to turn off your computer when everything is frozen. Whenever you see someone saying they had to "Power Off" their system without mentioning they had to REISUB their system, send them here!
REISUB (reboot)
REISUB (also known as the magic SysRq key) is a mnemonic for:
-
Rise up (from the dead) if you're inclined to Zombie movies, like me...
- Reboot Even If System Utterly Broken
- Raising Elephants Is So Utterly Boring
and is a gentle way of rebooting your system by doing the following:
- Switch the keyboard from Raw mode, used by programs such as X11 and SVGALib, to XLATE (translate) mode
- Send an End signal (SIGTERM) to all processes, except the boot process, allowing all processes to end gracefully
- Send an Instant kill (SIGKILL) to all processes, except the boot process, forcing all processes to end .
- Sync all mounted filesystems, allowing them to write all data to disk.
- Unmount and remount all mounted filesystems in read-only mode.
- ReBoot the system
In fact, the only data you lose is since your last [auto]save as the system is shut down gracefully.
Before you read any further, ensure all your work is saved!
How to invoke the REISUB procedure?
First we have to unlock the SysRq key so:
- Add to your grub
GRUB_CMDLINE_LINUX_DEFAULT
thesysrq_always_enabled=1
variable.
OR - Execute
echo kernel.sysrq=1 | sudo tee --append /etc/sysctl.d/99-sysctl.conf
AND - Reboot normally if you had to add one of these parameters, come back here and read the rest of the blurb...
There is a special System Request key on all keyboards called SysRq and:
- on full-size keyboards it's called by pressing Alt+SysRq
- on most laptop keyboards it's called by pressing Fn+Alt+PrtSc if the SysRq key is missing.
If you're on a full-size keyboard, keep the Alt key pressed, on a laptop keyboard, keep the Fn+Alt key combination pressed.
Now lightly tap these keys waiting at least 1 second in-between keypresses: R E I S U B
There! If you actually followed the above instructions, your system just rebooted gracefully and you did not damage your HDD (if you still have one) by forcing it into PARK mode forcefully nor was your EXT4 or NTFS transaction journal rolled back.
Congratulations!
For even more info, Read the Fine Manual here
REISUO (Turn off)
- Read the REISUB section above and then you'll know what this means:
- R E I S U O will turn your machine Off instead of reBooting it...
Light tap on power button (<5 seconds)
- Sometimes (If only the UI is frozen), you can still switch to one of the TTYs by pressing Ctrl+Alt+F2 or F3, ... and gently tap the power button there.
- If your entire system is frozen, it depends on your Desktop Environment (DE) and has to be set up beforehand!
To ensure that your power button effectively shuts down your computer instead of going to sleep / Hibernate / ... in the future, follow these steps for your DE:
-
In Gnome:
Details
Execute the following command:
gsettings set org.gnome.settings-daemon.plugins.power button-power 'shutdown'
-
In KDE:
Details
- Go to System Settings
- Type
energy
- in all of the On AC Power, On Battery and On Battery tabs, set the check-mark on Button events handling and the Even when an external monitor is connected
-
When power button pressed to
Shut Down
as per below screenshot:
-
In XFCE:
Details
- Go to the Applications menu or System settings
- Clock Power Manager
- From When Power Button is pressed: select Shutdown.
That's it! If all of your data is saved, just press the power button lightly and your system will shut down gracefully from now on!
Keep power button suppressed (>5 seconds)
See section "Pull circuit breaker on House / Street / Block" below...
Yank power cord from a laptop without battery or a PC without UPS
See section "Pull circuit breaker on House / Street / Block" below...
Pull circuit breaker on House / Street / Block
Please! Do not do this!
Unless you're using ZFS or BTRFS and have ensured they use redundancy, you will lose data!
Maybe not the first time, maybe not the second time, but eventually, you will!
Use REISUB, REISUO or a light tap instead!