How to force-shutdown your computer avoiding data loss in Linux

Sometimes you can have your computer frozen and you need to force-shutdown it, but this is very dangerous, so here are some tips about how to do it in the correct way:

The first, is to access to the console since your desktop is unresponsive, login on it from your user and you can proceed:

Restart your desktop

If what is blocked is your desktop (E17 and newer versions) you can try to restart it by sending a fake segfault to it:

kill -s SEGV $( pidof enlightenment )

It will make the desktop launcher (enlightenment_start) think that the desktop crashed and will restart it maintaining your apps opened, so this is the first thing to try.

sorry, not possible in e16 as enlightenment_start does not exist

Crash your entire desktop

You can try to send a force-kill signal to your desktop like:

killall -9 e16

Or you can try to restart your login manager too, but the first option is more reliable:

sudo service lightdm restart

Force-shutdown (safe mode) your computer

You can first try to run Ctrl Alt Del from the console to see if the computer simply reboots

If you have no way to recover your desktop, for example if your computer is entirely unresponsive, you can trigger the magic kernel keys to force a shutdown, this combination is:

  • Alt Gr PrtScr e: This will ask processes to terminate gracefully which can make corruption and other things avoided
  • Alt Gr PrtScr s: This will sync your data in your hard disks (wait 10 seconds)
  • Alt Gr PrtScr u: This will remount your hard disk in read-only mode (wait 5 seconds)
  • Alt Gr PrtScr b: This will reboot, instantly

note: PrtScr is also called Imp Pt in Latin keyboards

3 Likes

I don't have AltGR on any of my keyboards, which Alt is it?

The one on the right-hand side of the SpaceBar.
xev

This is the keycode with "xev"

KeyPress event, serial 39, synthetic NO, window 0x2000001,
root 0x184, subw 0x0, time 19226569, (196,-41), root:(196,262),
state 0x0, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
XKeysymToKeycode returns keycode: 92
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x2000001,
root 0x184, subw 0x0, time 19226616, (196,-41), root:(196,262),
state 0x80, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
XKeysymToKeycode returns keycode: 92
XLookupString gives 0 bytes:
XFilterEvent returns: False

1 Like

fixed :smiley:

BTW everybody is welcome to improve the howto's of the forum

different name in your keyboard? :thinking:

I just have two Alt's.

US keyboard (i really don't want to learn the multilingual Canadian keyboards, i'm used to US and I'm sticking with it lol)

Just for the people who care:

Here's a complete list of every single kernel magic key.

(Source: The Geek Stuff)

‘k’ – Kills all the process running on the current virtual console.
‘s’ – This will attempt to sync all the mounted file system.
‘b’ – Immediately reboot the system, without unmounting partitions or syncing.
‘e’ – Sends SIGTERM to all process except init.
‘m’ – Output current memory information to the console.
‘i’ – Send the SIGKILL signal to all processes except init
‘r’ – Switch the keyboard from raw mode (the mode used by programs such as X11), to XLATE mode.
‘s’ – sync all mounted file system.
‘t’ – Output a list of current tasks and their information to the console.
‘u’ – Remount all mounted filesystems in readonly mode.
‘o’ – Shutdown the system immediately.
‘p’ – Print the current registers and flags to the console.
‘0-9’ – Sets the console log level, controlling which kernel messages will be printed to your console.
‘f’ – Will call oom_kill to kill process which takes more memory.
‘h’ – Used to display the help. But any other keys than the above listed will print help.

(EDIT: First you will have to change /proc/sys/kernel/ssyrq from 438 to 1, I just noticed.)