part 3: SystemD - Shutting Down, Suspending, and Hibernating the Linux System

part 3: SystemD - Shutting Down, Suspending, and Hibernating the Linux System

3. SystemD - Shutting Down, Suspending, and Hibernating the Linux System


The systemctl utility from systemd replaces a number of power management commands used in previous versions of many linux distros like reboot, poweroff, halt and many more. We learn Power Management Commands with systemctl command that replace old power management commands.

Old commands are still available in the system for compatibility reasons, but it is advised that you use systemctl when possible.

Table 3.1 - Comparison of Power Management Commands with systemctl

Old Command New Command Description
halt systemctl halt Halts the system.
poweroff systemctl poweroff Powers off the system.
reboot systemctl reboot Restarts the system.
pm-suspend systemctl suspend Suspends the system.
pm-hibernate systemctl hibernate Hibernates the system.
pm-suspend-hybrid systemctl hybrid-sleep Hibernates and suspends the system.

3.1 Shutting Down the System


The systemctl utility provides commands for shutting down the system, however the traditional shutdown command is also supported. Although the shutdown command will call the systemctl utility to perform the shutdown, it has an advantage in that it also supports a time argument. This is particularly useful for scheduled maintenance and to allow more time for users to react to the warning that a system shutdown has been scheduled. The option to cancel the shutdown can also be an advantage.

Using systemctl Commands

To shut down the system and power off the machine, type the following at a shell prompt as root:

~]$ systemctl poweroff

To shut down and halt the system without powering off the machine, run the following command as root:

~]$ systemctl halt

By default, running either of these commands causes systemd to send an informative message to all users that are currently logged into the system. To prevent systemd from sending this message, run the selected command with the --no-wall command line option, for example:

~]$ systemctl --no-wall poweroff

Using the old shutdown Command


To shut down the system and power off the machine at a certain time, use a command in the following format as root:

~]$ shutdown --poweroff hh:mm

Where hh:mm is the time in 24 hour clock format. The /run/nologin file is created 5 minutes before system shutdown to prevent new logins. When a time argument is used, an optional message, the wall message, can be appended to the command.

To shut down and halt the system after a delay, without powering off the machine, use a command in the following format as root:

~]$ shutdown --halt +m

Where +m is the delay time in minutes. The now keyword is an alias for +0.

shutdown --halt now command - The now keyword is an alias for +0.

A pending shutdown can be canceled by the root user as follows: shutdown -c

3.2 Restarting the Linux System


To restart the system, run the following command as root:

~]$ systemctl reboot

By default, this command causes systemd to send an informative message to all users that are currently logged into the system. To prevent systemd from sending this message, run this command with the --no-wall command line option:

~]$ systemctl --no-wall reboot

3.3 Suspending the System


To suspend the system, type the following at a shell prompt as root:

~]$ systemctl suspend

This command saves the system state in RAM and with the exception of the RAM module, powers off most of the devices in the machine. When you turn the machine back on, the system then restores its state from RAM without having to boot again. Because the system state is saved in RAM and not on the hard disk, restoring the system from suspend mode is significantly faster than restoring it from hibernation, but as a consequence, a suspended system state is also vulnerable to power outages.

3.4 Hibernating the System


To hibernate the system, type the following at a shell prompt as root:

~]$ systemctl hibernate

This command saves the system state on the hard disk drive and powers off the machine. When you turn the machine back on, the system then restores its state from the saved data without having to boot again. Because the system state is saved on the hard disk and not in RAM, the machine does not have to maintain electrical power to the RAM module, but as a consequence, restoring the system from hibernation is significantly slower than restoring it from suspend mode.

To hibernate and suspend the system, run the following command as root: systemctl hybrid-sleep

Another parts of this guide: