Skip to main content

How to shut down a frozen Linux system

Summary

This guide explains how to safely power off a frozen Linux system, emphasizing the risks of using the power button and offering alternative methods to prevent data corruption.

Introduction #

When a Linux system becomes unresponsive, knowing how to safely power it off can prevent potential data loss or corruption. This guide will walk you through the steps to shut down a frozen / unresponsive Linux system, using graceful methods that minimize the risk of damaging your files or system integrity.

Safe shutdown methods for unresponsive systems #

Do not simply press and hold the power button! Doing so forces an immediate power cut, which can lead to data corruption or loss. Without properly syncing and unmounting the file system, any unsaved data or ongoing processes may be interrupted, potentially damaging system files or causing other issues like data loss.

Use the safer shutdown methods below ensure the system can properly close processes and handle file system operations. This way the system can shut down gracefully.

Shutdown, halt, poweroff #

If you still have a responsive terminal open, or if you can open Alt + F2 (run command) to send commands to the system, the following might do the trick to shut down:

COMMANDDESCRIPTION
shutdown -hP nowShut down the system.
halt -pShut down the system.
poweroffShut down the system.

All these commands will attempt to shut down the system gracefully. If there is no option to feed commands to the system, try changing the virtual TeleTYpe (TTY).

Changing TTY #

If your desktop environment, typically on virtual TeleTYpe (TTY) 2, is frozen, you can try changing the TTY to be able to input commands or inspect logs.

COMMANDDESCRIPTION
Ctrl + Alt + F3-F6Access TTY F3 through F6.
Typically you can have 4 TTY sessions open at once.
Alt + PrtSc + rUnraw the keyboard, in case it is stuck, too.
Alt + </>Change between virtual TTYs with unrawed keyboard.

Once you have access to a responsive TTY, you can try to shut down the system with shutdown, halt, and poweroff again. If this does not work, you can try the systemd commands, or directly try the so called Magic SysRq key commands.

Systemd #

Administrative rights are needed. systemd will automatically ask you for the root password.

COMMANDDESCRIPTION
systemctl reboot Shut down and reboot the system.
systemctl poweroff Shut down and power-off the system.
systemctl suspend Suspend the system.
systemctl hibernate Put the system into hibernation (write RAM to disk).
systemctl hybrid-sleep Put the system into hybrid-sleep state (write RAM to disk, then suspend).
systemctl suspend-then-hibernate Suspend the system, then wake up after a configured time to just hibernate the system.
systemctl soft-rebootPerform a reboot of the userspace-only with a soft-reboot.

Magic SysRq key #

If just changing the virtual TeleTYpe (TTY) does not help then it makes sense to try the Magic SysRq key combinations. They are primarily used as a safer alternative to a cold reset when the system has completely crashed. This is because commands, such as those for syncing and unmounting the file system, can help prevent damage and data corruption before resetting or rebooting.

Some keyboards may not provide a separate SysRq key. In this case, a separate PrtSc (print screen) key should be present.

To initiate a graceful shut down of the system, perform all three commands in the given order (from top to bottom):

COMMANDDESCRIPTION
Alt + PrtSc + sSync all mounted filesystems.
Alt + PrtSc + uRemount all mounted filesystems read-only.
Alt + PrtSc + oShut down the system.

The key combinations Alt + SysRq + [LETTER] are generally known as Magic SysRq commands which directly send commands to the kernel.

On certain devices, particularly laptops, the Fn key may need to be pressed to use the magic SysRq key. For example, on the many Lenovo laptops, SysRq is triggered by pressing Alt + Fn + S simultaneously, then releasing Fn and S while continuing to hold Alt. On a ChromeOS device, SysRq is activated by pressing Alt + Volume Up (F10) + [LETTER].

By following safe shutdown methods for unresponsive Linux systems, you can avoid potential data corruption and system damage. Understanding these alternative techniques ensures you can handle crashes without risking your system’s integrity.

Always prioritize graceful shutdowns over forced power cuts!


Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

License: How to shut down a frozen Linux system by Jonas Jared Jacek is licensed under CC BY-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/instructions/how-to-shut-down-unresponsive-linux-system">How to shut down a frozen Linux system</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>

For more information see the DITig legal page.


“Good design comes from a deep understanding of the technologies behind the scenes.”

Jeffrey Veen, American designer and design strategistThe Art & Science of Web Design, - IT quotes