How to gracefully shutdown your Linux system – Starline - Starline Computer: Storage und Server Lösungen von erfahrenen Experten

Gracefully shutting down Linux

How to shut down the system in a secure way.

What is graceful system shutdown?

Ungraceful shutdown is when the Linux system is suddenly and/or forcefully halted. This could be due to a power supply interruption or software stack crash. 

A graceful shutdown, on the other hand is when you switch off your Linux system using embedded software functions while allowing the OS to finalise and close remaining tasks and save any in-flight data to the disks. This is also called Planned Shutdown.

Although Linux is famous for its ability to run for years without a need for a single reboot, sometimes you might need to shut down your server and, assuming you have SSH access to the machine, here is the proper way to do it.

Commands to gracefully shutdown Linux

Shut down gracefully and immediately

$ shutdown -h now

 

Shut down gracefully after X number of minutes

$ shutdown -P +30 (P stands for Power Off)

This will shut the machine down after 30 minutes. 

 

To shut down at a specific hour run;

$ shutdown -P 3:00

This will shut the machine down at 3:00 AM

 

To cancel a pending/scheduled shutdown just do;

$ shutdown -c

The shutdown command will trigger the proper Init level resulting in the OS gracefully stopping all running services. Any stuck processes will be terminated using a kill -9 command then the machine will halt.

Important to note

When the time argument is used, 5 minutes before the system goes down the system will create a /run/nologin file to prevent users from logging into the system as it prepares for shutdown.

The halt, poweroff and reboot commands can also be used to shut the machine down.

$ reboot -P (P also stands for Power Off)
$ halt

 

If you want to forcefully halt the machine you can do;

$ halt -f or reboot -f

Any questions?

We are happy to advise you

starline_logo_kontur_300
Open Source Team
Technik

Our experts for Linux, Ceph and ZFS.