Chapter 4. Shutting down, suspending, and hibernating the system
To administer and manage data and settings on a system, use the systemd power management options. It includes tasks such as managing power consumption, performing proper system shutdowns to protect your data, and restarting the system to apply changes and updates.
4.1. Scheduling a system shutdown Copy linkLink copied to clipboard!
To perform maintenance tasks and apply updates to applications, you can schedule a delayed shutdown by using the shutdown command. It is important to schedule a shutdown for system maintenance tasks to avoid data loss and unexpected system failures.
Prerequisites
- You have administrative privileges.
Procedure
Shut down the system and power off the machine at a certain time:
shutdown --poweroff hh:mm
# shutdown --poweroff hh:mmCopy to Clipboard Copied! Toggle word wrap Toggle overflow Where
hh:mmis the time in the 24-hour time notation. To prevent new logins, the system creates the/run/nologinfile 5 minutes before the shutdown.When you specify time of the
shutdowncommand, you can notify users logged in to the system of the planned shutdown by specifying an optional wall message. For example:shutdown --poweroff 13:59 "Attention. The system will shut down at 13:59"
# shutdown --poweroff 13:59 "Attention. The system will shut down at 13:59"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Shut down and halt the system after a delay, without powering off the machine:
shutdown --halt +m
# shutdown --halt +mCopy to Clipboard Copied! Toggle word wrap Toggle overflow Where
+mis the delay time in minutes. You can use thenowkeyword as an alias for+0.Cancel a pending shutdown:
shutdown -c
# shutdown -cCopy to Clipboard Copied! Toggle word wrap Toggle overflow For details, see
shutdown(8)man page on your system.
4.2. Shutting down the system using the systemctl command Copy linkLink copied to clipboard!
To administer and manage data and settings on a system, use the systemd power management options. You can shut down the system and power off the machine or shut down and halt the system without powering off the machine by using the systemctl command.
Prerequisites
- You have administrative privileges.
Procedure
Shut down the system and power off the machine:
systemctl poweroff
# systemctl poweroffCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
--whenoption with thesystemctl poweroffcommand to specify time:systemctl poweroff --when="+15min"
# systemctl poweroff --when="+15min"Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteBy default, running either of these commands causes
systemdto send an informative message to all users that are currently logged into the system.To prevent
systemdfrom sending this message, run the selected command with the--no-wallcommand line option.
4.3. Restarting the system Copy linkLink copied to clipboard!
To apply pending changes and updates, you can restart the system by using the systemctl command. When you restart the system, systemd stops all running programs and services, the system shuts down, and then starts again immediately.
Prerequisites
- You have administrative privileges.
Procedure
Restart the system:
systemctl reboot
# systemctl rebootCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteBy default, running this command causes
systemdto send an informative message to all users that are currently logged into the system.To prevent
systemdfrom sending this message, run this command with the--no-walloption.
4.4. Optimizing power consumption by suspending and hibernating the system Copy linkLink copied to clipboard!
To save the current system state and reduce power consumption, you can suspend, hibernate, suspend-then-hibernate, or hybrid sleep the system by using the systemctl command.
To suspend the system, run:
systemctl suspend
# systemctl suspendCopy to Clipboard Copied! Toggle word wrap Toggle overflow Suspending saves the system state in RAM and powers off most devices, except the RAM module. When you turn the machine back on, the system restores its state from RAM without rebooting. Restoring from suspend mode is significantly faster than from hibernation because this operation saves the state in RAM, not on disk. However, the suspended system state is vulnerable to power outages.
To hibernate the system, enter:
systemctl hibernate
# systemctl hibernateCopy to Clipboard Copied! Toggle word wrap Toggle overflow Hibernating saves the system state on the hard disk drive and powers off the machine. When you turn the machine back on, the system restores its state from the saved data without rebooting. Restoring from hibernation is significantly slower than from suspend mode because this operation saves state on disk, not in RAM. However, the machine does not have to keep electrical power to the RAM module.
To hibernate and suspend the system, enter:
systemctl hybrid-sleep
# systemctl hybrid-sleepCopy to Clipboard Copied! Toggle word wrap Toggle overflow Hybrid sleep combines hibernation and suspend. The system saves the current state to disk and enters a low-power state, allowing faster resume. If there is power loss during the sleep operation, the system recovers the state from the saved disk image, similar to hibernation.
To suspend and then hibernate the system, run:
systemctl suspend-then-hibernate
# systemctl suspend-then-hibernateCopy to Clipboard Copied! Toggle word wrap Toggle overflow This mode first suspends the system, saving the state to RAM in low-power mode. If the system remains suspended for a duration you define in
HibernateDelaySec, it then hibernates. Hibernation saves the state to the hard disk and powers off the system completely. This mode conserves battery power while enabling quick resume. It also protects your data during power failures.
4.5. Changing the behavior of the power button when GNOME is not running Copy linkLink copied to clipboard!
To prevent the system from shutting down when you press the power button, you need to modify settings for the non-graphical systemd target. Select the option according to requirement.
Prerequisites
- You have administrative privileges.
Procedure
-
Edit the
/etc/systemd/logind.confconfiguration file to set theHandlePowerKeyvariable. To reboot the system when you press the power button, set the
rebootvalue:HandlePowerKey=reboot
HandlePowerKey=rebootCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use one of the following options:
-
poweroff: Shut down the computer. -
reboot: Reboot the system. -
halt: Initiate a system halt. -
kexec: Initiate akexecreboot. -
suspend: Suspend the system. -
hibernate: Initiate system hibernation. -
ignore: Do nothing.
-
Restart the
systemd-logindservice to apply the changes:systemctl reload systemd-logind
# systemctl reload systemd-logindCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.6. Changing the behavior of the power button in GNOME Copy linkLink copied to clipboard!
To prevent the system from suspending when you press the power button, modify settings for the GNOME login screen and user session. You can select one of the options: physically on a system or virtually from a remote console.
Prerequisites
- You have administrative privileges.
Procedure
Create a local database for system-wide settings in the
/etc/dconf/db/local.d/01-powerfile:[org/gnome/settings-daemon/plugins/power] power-button-action=<value>
[org/gnome/settings-daemon/plugins/power] power-button-action=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<value>with one of the following power button actions:-
nothing: Does nothing. -
suspend: Suspends the system. -
hibernate: Hibernates the system. interactive: Shows a pop-up query asking the user what to do.In the interactive mode, when you press the power button, the system automatically powers off after 60 seconds. You can select a different behavior from the pop-up query.
-
Optional: To override existing settings and prevent other users from changing it, edit configuration in the
/etc/dconf/db/local.d/locks/01-powerfile:/org/gnome/settings-daemon/plugins/power/power-button-action
/org/gnome/settings-daemon/plugins/power/power-button-actionCopy to Clipboard Copied! Toggle word wrap Toggle overflow Update the system databases:
dconf update
# dconf updateCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Log out and log in again for the system-wide settings to take effect.
Verification
- Press the power button and check if the system performs the action you configured.