This is, in a way, a memo for myself in the future. I do not understand why hibernation on linux is not a simple feature that just works and why enabling it has to be so complicated. I hope it also helps people having questions about hibernation.
- First, you need to make sure you have a large enough swap file. Swap is where your RAM is save on disk when you hibernate.
- Check the size of your swap either through System Monitor -> Resources or by running
sudo swapon --show. You probably do not have enough. Your swap size should be somewhat larger than you RAM size. There are some guides online. I go for 5GB swap on my 4GB RAM machine.
- How to make your swap larger depends on how you have it set up. Maybe you need to create a larger swap file, maybe you need to open GParted and simply resize partitions there. I have an encrypted LVM with
/dev/vgmint/swapvolumes. You cannot resize LVM while it is mounted, so you boot from a USB stick with Linux Mint. There you can use Disks app to unlock your encrypted LVM and use this beautiful guide to safely reduce the size of your
/dev/vgmint/rootvolume. Then you can run
sudo lvextend -l 100%FREE /dev/vgmint/swap_1to extend your swap volume with the free space you have just created.
- Now, we need to update swap. We are done with a USB stick live system, boot into your regular system. If you check the size of your swap again, you will see that the size of it has not changed, even though we just gave it more space. We need to create a new swap. Run
sudo swapoff -ato disable all swaps and run
sudo mkswap /dev/vgmint/swap_1to create a new one.
- Now, test if your hardware supports hibernation and add hibernation button back by reading this lovely article.
- Power management. This is probably specific to Linux Mint with Cinnamon. I want my laptop to hibernate after a certain period of inactivity, but it is not possible to set this up using Power Management app. To edit inner Cinnamon settings, I use dconf editor (
sudo apt install dconf-editor). Open it up, go to /org/cinnamon/settings-daemon/plugins/power/ or just search for power.
sleep-inactive-battery-typeis what I am after – set it to ‘hibernate’. While here, I like to turn off
use-time-for-policyand use battery percentages instead of time remaining to determine "battery low", "battery critical" and "battery action" states. Battery percentage is a real value, while time remaining is an estimate and can vary a lot. You can also set percentage thresholds using
percentage-action. Take a look a round, there are some interesting settings in this tab. Be careful though.
- Now, the last piece of the puzzle prevent unwanted wakeups from suspend/hibernation. Write
sudo cat /proc/acpi/wakeup. You will see which devices are enabled and can lead to unwanted wakeups from hibernation. Devices that cause you trouble need to be disabled on boot and on return from suspend/hibernation.
- Here is how to disable a device:
echo DEVICE_NAME | sudo tee /proc/acpi/wakeup. (Thanks to this thread.)
- Figure out which devices cause you problems (I have disabled all) and write a bash script that would disable them. (File might need to be owned by root, since root will be executing it.) It would look something like:
#!/bin/bash echo RP01 | tee /proc/acpi/wakeup echo RP02 | tee /proc/acpi/wakeup echo RP03 | tee /proc/acpi/wakeup echo RP05 | tee /proc/acpi/wakeup echo RP06 | tee /proc/acpi/wakeup echo XHC1 | tee /proc/acpi/wakeup echo LID0 | tee /proc/acpi/wakeup
Do not forget to make your script executable for root.
sudo su and then
chmod +x /your-script.sh
- Now, we need to create a systemctl service that will be calling the script. (Thanks to this article and many other posts on this website for inspiration). I call the service wakeups. Create the file using
sudo nano /etc/systemd/system/wakeups.service. The contents of the file:
[Unit] Description=Fix unwanted wakeups from suspend [Service] Type=oneshot TimeoutSec=0 StandardOutput=syslog User=root ExecStart=/path-to-your-script/script.sh [Install] WantedBy=multi-user.target suspend.target hibernate.target
- Enable the service by running
systemctl enable wakeups.service
- Alright, that is all it takes to have hibernate properly functioning! Test and make sure everything works correctly when booting regularly and when returning from hibernate/suspend.