21

"sudo systemctl start hibernate.target" worked fine with 16.04 on a Acer B117 using legacy boot; Updating to 18.04 forced me to use UEFI and (Acer requirement) secure boot enabled. Suspend still works, but I need hibernate.

Swap partition is active and equals RAM size + 2GB;

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=myswapuuid"

journalctl -xe revealed failure to access /sys/power/disk

cat /sys/power/disk: [disabled]

cat /sys/power/state: freeze mem

Any suggestions?

Braiam
  • 67,791
  • 32
  • 179
  • 269
olli61
  • 211
  • 1
  • 2
  • 4

2 Answers2

26

I have the same problem and, unfortunately, it's impossible with the official Ubuntu kernel since version 4.13 due to kernel lockdown patchset (efi-lockdown). Substantiation is:

There is currently no way to verify the resume image when returning from hibernate. This might compromise the signed modules trust model, so until we can work with signed hibernate images we disable it when the kernel is locked down.

Related Bionic commit you can see here.

This is a controversial decision and Linus declined to merge these changes to linux kernel.

A bit more details you can find is the article Kernel lockdown in 4.17? and its comments.

So while we wait some magic software, that will work with signed hibernate images, we can only use another kernel or disable secure boot.

Braiam
  • 67,791
  • 32
  • 179
  • 269
Snaker
  • 508
  • 1
    What kernel could I use? Hibernation is an essential feature to me. (I expect I must have one newer than 4.15, ideally 4.18, as my WiFi works on the latter, but not the former.) – nsandersen Jun 08 '19 at 19:27
  • @morgwai I'm sorry for your lost. After I encountered a similar case, I set up CriticalPowerAction to Hibernate and low battery notifications according to this post — https://askubuntu.com/a/800398/865173 It's better to leave more time for hibernation, for example 1200/600/300. – Snaker Apr 24 '20 at 13:01
  • 1
    btw: I think this limitation does not make sense if the swap is on an encrypted drive, right? is there any launchpad bug/feature request where we can upvote enabling hibernation on secure-boot+encrypted-swap? ;-) – morgwai May 18 '20 at 06:10
  • The "magic software" has now appeared: https://lore.kernel.org/lkml/20210220013255.1083202-1-matthewgarrett@google.com/T/#u. In kernels that have this merged, hibernation and secure boot should work together. – Nikratio Sep 04 '21 at 19:40
  • @Nikratio, have you tried this? – Snaker Nov 09 '21 at 14:31
  • 1
    I think the patch set might be paused? https://mjg59.dreamwidth.org/55845.html https://lwn.net/ml/linux-kernel/CAE=gft6Z1+kt_6sqRcpFh-=C0ir4cqEkC7p1WcPFhnkWgtprYA@mail.gmail.com/ – Thomas Grainger Jul 23 '22 at 17:40
  • Unfortunately on Ubuntu 22.04 LTS with Kernel 6 point something (as of 2023-10-27) it still doesn't work… I hope they add it (back) soon in Ubuntu, as that would be very handy for me to basically shut down my laptop for transport (so the battery doesn't drain) and then just continuing where I left off. – Lampe2020 Oct 27 '23 at 21:48
3

I was able to hibernate using s2disk or pm-hibernate, but resume was failing. To fix this, as my system is booted up using UEFI instead of grub. I just had to reinstall the boot loader. To check if you are running UEFI use the following:

[ -d /sys/firmware/efi ] && echo "Installed in UEFI mode" || echo "Installed in Legacy mode"

if in UEFI mode, then I followed this guide to reinstall the bootloader, it varies if you are using an nvme disk or sata disk: https://support.system76.com/articles/bootloader/

The key is to run this command:

sudo update-initramfs -c -k all

make sure that in your kernalboot options you specify the partition or UUID of where to resume from, eg something like this:

resume=UUID=ed8347ed-2eb4-40bc-bc77-cc53b987ed88

You can add this by either:

  1. sudo kernel-stub -a "resume=UUID=..."
  2. edit the /etc/initramfs-tools/conf.d/resume file and add: resume=UUID=ed8347ed-2eb4-40bc-bc77-cc53b987ed88

check your /var/log/syslog file for something like this:

Aug  4 22:26:42 pop-os /usr/bin/kernelstub[19639]: kernelstub           : DEBUG    kopts: root=UUID=b37019a8-91f5-445f-94c1-7359a49ed5df ro quiet loglevel=0 systemd
.show_status=false resume=UUID=ed8347ed-2eb4-40bc-bc77-cc53b987ed88

If the resume is missing or wrong then you'll need to update your boot kernal again.

Braiam
  • 67,791
  • 32
  • 179
  • 269
Lingster
  • 159
  • Thanks, this is the only answer that allowed me to resume without issue. – Emmanuel M. Smith Nov 27 '19 at 15:47
  • As a user of encryption, I did not need to change the initramfs, but I did have to disable cryptswap and re-enable normal swap by uncommenting and commenting appropriately in /etc/fstab and /etc/crypttab. cryptswap uses a random key each boot so doesn't work for hibernation. – fuzzyTew Feb 13 '20 at 12:40
  • If you want an encrypted swap partition, you can take a look at this: https://help.ubuntu.com/community/EnableHibernateWithEncryptedSwap – Lingster Feb 15 '20 at 17:54