How to set up Ubuntu 24.04 for Hibernation?
In Ubuntu 24.04 there is no automatic hibernation. Similar problems exist in many versions of Linux Mint. They favour stability over the power saving. So, one is left with no option but to do it manually. This is the third time, I had to do it, so I decided to document it for myself as well as for others.
Hibernation can be set up manually if hardware supports it and swap space is adequate (at least as large as the RAM). Common issues preventing hibernation include missing or insufficient swap and pre-enabled Secure Boot.
In short, disable Secure Boot from bios. Create swap drive large enough to accommodate hibernation. Amend the fstab and grub. Change the power setting. It is done. First check the status.
Status Check
Run free -h and swapon --show. See the output. In my case this was the output:
total used free shared buff/cache available
Mem: 5.6Gi 3.6Gi 354Mi 35Mi 1.3Gi 2.0Gi
Swap: 4.0Gi 2.2Gi 1.8Gi
NAME TYPE SIZE USED PRIO
/swap.img file 4G 2.2G -2
To simplify, it shows 6 GB RAM and 4 GB Swap file. No dedicated drive. Since I had un-allocated space on hard drive, I installed gparted and created a 16 GB partition with label ‘Linux-Swap’.
Find UUID
Now was the time to get UUID of new partition. I used disks to note down the uuid but that was wrong. Use sudo blkid and look for partition with label swap. But I had to look for ‘Linux-Swap’ because that was the label name I had given in previous step.
Remember the output of blkid has two things. UUID and Part UUID. Use UUID, not PARTUUID for next step.
Edit fstab
Use editor of your choice and edit fstab, the file system reads after of booting. I used nano to edit /etc/fstab. The exact command is:
sudo nano /etc/fstab
This was the last line in the fstab: /swap.img none swap sw 0 0. A hash # was added to it to make it a comment. and added next line so that final editing looked like this:
# /swap.img none swap sw 0 0
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx none swap sw 0 0
Remember those spaces are tabs. Replace your UUID with your UUID. Now save it and close. Now reboot and check by using free -h
It should show something like this:
total used free shared buff/cache available Mem: 5.6Gi 4.3Gi 292Mi 54Mi 940Mi 1.3Gi
`Swap: 15Gi 3.6Gi 12Gi
If the output shows zero swap, it means the swap is not identified. Debug it by correcting the error. In my case UUID was wrong. Wrong output is like this:
total used free shared buff/cache available Mem: 5.6Gi 1.5Gi 3.4Gi 13Mi 1.0Gi 4.2Gi
Swap: 0B 0B 0B
The common to manually load swap is swapon -a. Use it to debug and see what error it returns. Now time to edit few more files.
Edit Grub config
1. Find the swap UUID and offset (for file, not needed for partition):
In case of a swap partition, offset is 0. Just note the UUID.
2. Edit the GRUB config:
sudo nano /etc/default/grub
Find this line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Change it to:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=your-swap-uuid"
Replace your-swap-uuid with your swap partition UUID.
3. Update GRUB:
sudo update-grub
4. Update initramfs:
sudo nano /etc/initramfs-tools/conf.d/resume
Add this line:
RESUME=UUID=your-swap-uuid
Then run:
sudo update-initramfs -u -k all
5. Reboot and check if it is working.
The initramfs and GRUB changes need a reboot to take effect. The next action is to be taken if reboot is successful. If not debug and recheck with reboot. Only if it works well, try next step.
6. Test hibernation:
sudo systemctl hibernate
The system should power off.
Wait for 5 minutes and reboot. It should restore the system on the next boot. But we can not manually hibernate each time we have to close the lid. The GUI provide no settings either. This is the headless way to set it up.
Hibernation Settings
First, check the status with this command:
cat /etc/systemd/sleep.conf
In my case, the last lines in sleep.conf was as under:
#AllowSuspend=yes
#AllowHibernation=yes
#AllowSuspendThenHibernate=yes
#AllowHybridSleep=yes
#SuspendState=mem standby freeze
#HibernateMode=platform shutdown
#HibernateDelaySec=
#SuspendEstimationSec=60min
Remember the following settings are for Ubuntu with the GNOME desktop but with the Ubuntu dock (dash) which is still GNOME underneath. The GUI power option does not show hibernate option by default in Ubuntu 24.04. it has to be enabled manually. Run this to check available options:
gsettings list-keys org.gnome.settings-daemon.plugins.power
And this to see current values:
gsettings list-recursively org.gnome.settings-daemon.plugins.power
This was the output in my case:
idle-brightness
idle-dim
lid-close-ac-action
lid-close-battery-action
lid-close-suspend-with-external-monitor
power-button-action
power-saver-profile-on-low-battery
sleep-inactive-ac-timeout
sleep-inactive-ac-type
sleep-inactive-battery-timeout
sleep-inactive-battery-type
Now run this to see current values:
gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type
gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type
gsettings get org.gnome.settings-daemon.plugins.power lid-close-battery-action
gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action
The output was suspendfour times. Now these are the exact commands to switch these keys to hibernate:
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'hibernate'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'hibernate'
gsettings set org.gnome.settings-daemon.plugins.power lid-close-battery-action 'hibernate'
gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action 'hibernate'
Also set the idle timeout. This sets hibernate after 15 minutes of inactivity:
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 900
900 is 15 minutes on battery.
Now if you desire to activate hibernation on ac charge too, this is the command:
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 1800
1800 is 30 minutes on AC. Change as needed. By the Way, I did not activate hibernation on ac charging. Saw no point.
Addition to Power Menu
This is the recommended method to show Hibernate options in the Power menu on Ubuntu 24.04. Run this in terminal to edit the file:
sudo nano /etc/polkit-1/rules.d/10-enable-hibernate.rules
Paste this:
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.login1.hibernate" ||
action.id == "org.freedesktop.login1.hibernate-multiple-sessions" ||
action.id == "org.freedesktop.upower.hibernate" ||
action.id == "org.freedesktop.login1.handle-hibernate-key" ||
action.id == "org.freedesktop.login1.hibernate-ignore-inhibit") {
return polkit.Result.YES;
}
});
Then apply:
sudo chmod 644 /etc/polkit-1/rules.d/10-enable-hibernate.rules
Check if new entries do not appear immediately, log out and log back in (or reboot). After that, Hibernate should appear in the Power menu (top right → Power Off / Log Out → you should see Hibernate).
All done.
There are gnome extension which promise to provide gui menu to tweak the setting but so far none worked. Compatibility issue with my gnome version of 46, perhaps. The above polkit entries eliminated the need for extensions altogether. It worked cleanly without any compatibility issues. Use this experience with care. Take help of AI but it is quite mechanical. It often suggest a person to run without telling it to stand up fist. So be careful.
All the best.