This tutorial explains how to perform various power management related tasks in a Linux system such as halt, power-off, shutdown, reboot, sleep (suspend), hibernate, and hibernate-sleep.
Before we understand how to perform various power management related operations in a Linux system, let’s briefly understand what power management related options/modes/states are available in the Linux and how they are different from each other.
In Linux, seven power management related options are available. These options are; halt, power-off, shutdown, reboot, sleep, hibernate, and hybrid-sleep. Broadly, these options can be categorized into two types; essential options and advanced options.
Essential power management options
These options completely turn off all running services and processes of the system. To start the system again, we have to boot the system again. Halt, power-off, shutdown, and reboot are the essential power management options.
In this mode/state, Linux terminates all processes and services and shuts down the CPU but it does not power-off the system.
This mode works same as the halt mode except in this mode, after terminating all processes and services, Linux also power-off the system.
This mode works exactly same as the power-off mode except in this mode, before terminating all processes and services, Linux allows us to execute commands and custom scripts. This mode allows an administrator to broadcast messages to other users, and perform various administrative tasks such as logging and backup before shutting down the system.
In this mode, Linux first performs the shutdown operation and then starts the system again. Usually, this mode is used for system management related tasks such as to detect hardware or software changes or to clean or turn-off a hanged process or service.
Comparing halt, power-off, shutdown, and reboot
|Mode/State||What does it do?||What does it not do?|
|Halt||Terminate all processes and services and shutdown CPU but leaves the system in a powered-on state.||Does not power-off the system.|
|Power-off||Turn off all services and process then send an ACPI command to the motherboard and then to the PSU to terminate the power supply of the system.||Does not execute any command or script before turning off the system.|
|Shutdown||Execute configured commands and scripts and then shuts down the system by following the same process which the power-off mode uses.||Does not keep the system in a powered-on state.|
|Reboot||First shutdown the system by following the same process which the shutdown mode uses then sends a reboot ACPI command to the motherboard and PSU to start the system again.||Does not keep the system in a powered-off state.|
The following image presents a basic overview of all the above four modes/states.
To switch a Linux system into these states/modes, you can use the following commands.
To halt the system, use any one of the following commands.
#systemctl halt #shutdown -H now #halt
To power-off the system, use any one of the following commands.
#systemctl poweroff #shutdown -P now #poweroff
To shut down the system, use any one of the following commands.
#systemctl poweroff #shutdown
To reboot the system, use any one of the following commands.
#systemctl reboot #shutdown -r #reboot
- In modern Linux, the systemd utility is used to manage all services and processes of the system.
- In systemd, the halt, poweroff, and reboot commands have been replaced with the systemctl halt, systemctl poweroff, and systemctl reboot commands respectively.
- For compatibility reasons the halt, poweroff, and reboot commands still exist but they are linked with their newer versions.
- Although it’s not recommended, still you can use these legacy commands to change the state of the system.
If you will use any of these commands, the systemd will execute the new linked command. For example, if you run the halt command,
the systemd will execute the systemctl halt command.
The shutdown command
You can perform all four operations; halt, power-off, shutdown, and reboot from the shutdown command. For example,
The following command halts the system.
#shutdown -H now
The following command powers off the system.
#shutdown -P now
The following command shuts down the system.
The following command reboots the system.
#shutdown -r now
The shutdown command shuts down the system gracefully. Before shutting down all services and processes, it broadcasts a warning message to all logged-in users and runs any specified commands or scripts. It can also schedule the operation.
Let’s take a few examples of this command.
The following command shuts down and powers off the system at 03:44 AM.
#shutdown -P 03:44
The following command halt the system after 10 minutes.
#shutdown -H 10
The following command reboots the system after 15 minutes.
#shutdown -r 15
The shutdown command accepts time in two formats; hh:mm and +mm where hh:mm is the time in 24 hours format and +mm the delay time in minutes.
Advanced power management options
These options save the running state of the system and use the saved state to start the system again. Since the system is restored from the saved state, to start the system, we don’t need to boot the system again. Sleep, hibernate, hybrid-sleep are the advanced power management options.
Sleep (suspend or standby)
This mode is also known as the standby, suspend, or suspend-to-ram mode. In this mode, Linux saves the current state of the system into the RAM and cuts the power supply of all devices except the RAM.
When the system is started/waked-up again, the Linux restores the saved state from the RAM instead of booting the system.
Since this mode saves the running state of the system into the RAM, the power supply to the RAM must be retained. During this state/mode, if the system is running on the battery and the battery completely runs out or if the system is running on the power supply and power supply is turned off, the saved state is lost.
This mode is also known as the suspend-to-disk. In this mode, Linux saves the current state of the system into the hard disk and shuts down the power supply of the system. Since the current state is saved in the disk, the saved stated does not depend on the battery or external power supply.
If we compare this mode with the sleep mode, this mode takes a few more seconds to restore the system but it is more reliable then the sleep mode.
This mode is a combination of the hibernate and sleep modes. In this mode, Linux stores the current state of the system into the RAM and hard disk. After saving the system state in both places, it cut the power supply of all devices except the RAM.
If the power supply to the RAM retains until the system is started again, Linux restores the system from the state that has saved in the RAM. If the power supply to the RAM is failed or due to any reason the state that has saved in the RAM is lost, Linux uses the state that has stored in the hard disk to restore the system.
Since both RAM and hard disk contain the same system state, the restore operation works similarly no matter which state is used to restore the system.
Switching a system into the sleep, hibernate, and hybrid-sleep modes is relatively simple.
To switch a system into the sleep (suspend/standby) mode, use the following command.
To switch a system into the hibernate mode, use the following command.
To switch a system into the hybrid-sleep mode, use the following command.
To bring the system back in normal condition, press the power key. If saved stated is available, instead of booting the system, Linux restores the system from the saved state.
That’s all for this tutorial. If you like this tutorial, please don’t forget to share it with friends.