Detecting Hibernation Phases: Suspend vs. Hibernate in Ubuntu
In Ubuntu, there are two ways to conserve power when a laptop is not in use: suspend and hibernate. These two power-saving modes are often confused, but they have distinct differences. This article will explain the key concepts of suspend and hibernate, how to detect the current power-saving phase, and how to configure Ubuntu to use suspend-then-hibernate mode.
Suspend Mode
Suspend mode, also known as sleep mode, is a power-saving state where the system appears to be off but can be quickly resumed. In suspend mode, the system's state is stored in RAM, and the power to the CPU and other components is reduced. This mode allows the laptop to quickly resume operation, typically in a matter of seconds.
Hibernate Mode
Hibernate mode, also known as suspend-to-disk, is a power-saving state where the system's state is saved to the hard drive, and the system is completely shut down. In hibernate mode, the laptop can be closed and reopened without using any power. This mode is useful for conserving battery power when a laptop will not be used for an extended period.
Detecting the Current Power-Saving Phase
To detect the current power-saving phase in Ubuntu, you can use the following command:
cat /sys/power/stateThis command will display a list of the available power-saving states. The current power-saving state will be highlighted. For example:
$ cat /sys/power/state
freeze mem diskIn this example, the current power-saving state is mem, which is the suspend mode.
Configuring Ubuntu to Use Suspend-then-Hibernate Mode
Ubuntu does not enable the suspend-then-hibernate mode by default. However, you can enable it by creating a script in the /lib/systemd/system-sleep directory. The script should contain the following commands:
#!/bin/sh
case $1 in
pre)
systemctl hibernate &
;;
post)
systemctl suspend
;;
esacSave this script as /lib/systemd/system-sleep/suspend-then-hibernate and make it executable:
sudo chmod +x /lib/systemd/system-sleep/suspend-then-hibernateNow, when the laptop is suspended, it will first hibernate and then suspend. This will ensure that the laptop's state is saved to the hard drive and that the power is completely cut off when the laptop is not in use.
- Suspend mode is a power-saving state where the system's state is stored in RAM, and the power to the CPU and other components is reduced.
- Hibernate mode is a power-saving state where the system's state is saved to the hard drive, and the system is completely shut down.
- To detect the current power-saving phase in Ubuntu, you can use the
cat /sys/power/statecommand. - To enable suspend-then-hibernate mode in Ubuntu, create a script in the
/lib/systemd/system-sleepdirectory with the commands shown in this article.