Merge ~jefferyto/ubuntu/+source/initramfs-tools:ubuntu-core-dev-hibernate-fixes into ~ubuntu-core-dev/ubuntu/+source/initramfs-tools:ubuntu/devel

Proposed by Jeffery To
Status: Needs review
Proposed branch: ~jefferyto/ubuntu/+source/initramfs-tools:ubuntu-core-dev-hibernate-fixes
Merge into: ~ubuntu-core-dev/ubuntu/+source/initramfs-tools:ubuntu/devel
Diff against target: 22 lines (+4/-6)
1 file modified
scripts/local-premount/resume (+4/-6)
Reviewer Review Type Date Requested Status
Benjamin Drung Needs Information
Review via email: mp+467060@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Benjamin Drung (bdrung) wrote :

Your change drops the check for the swap type and your commit message does not convince me to drop it. What value does $SWAPTYPE have in the failing case?

Why are moving around the plymouth code?

review: Needs Information
Revision history for this message
Jeffery To (jefferyto) wrote :

> Your change drops the check for the swap type and your commit message does not convince me to drop it.

I wish I had some definitive documentation on how /sys/power/resume is to be set and/or used, that would really help in this case. I believe if /sys/power/resume is set (i.e. not "0:0") that indicates that hibernation is enabled, i.e. the system can be put into hibernation with the resume image written to the indicated device, and the system can be resumed from the indicated device.

* I copied part of the commit message from https://git.launchpad.net/~ubuntu-core-dev/ubuntu/+source/initramfs-tools/commit/?id=f65627d96f16388deb7c3e1c88b1098baec6a59b.

  The next commit that changes scripts/local-premount/resume is https://git.launchpad.net/~ubuntu-core-dev/ubuntu/+source/initramfs-tools/commit/?id=b3a78e4f80570efda6ae480e8915288a93b9a488. Before this commit, the resume device was always set in the kernel, either by calling /bin/resume or writing to /sys/power/resume directly.

  This commit, b3a78e4f80570efda6ae480e8915288a93b9a488, also caused the issue with setting RESUME=UUID=... (by assuming the resume variable was always a device path). I am not convinced this commit was sufficiently tested.

* As part of the change in systemd to save the hibernation device to EFI (https://github.com/systemd/systemd/blob/953c60e2f1022ade270ebb623a9cf1c679d888c1/NEWS#L2398-L2402), I believe it became more strict about checking that hibernation was explicitly enabled (with either resume= being set on the kernel command line or with /sys/power/resume being set).

  If you read through https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/2057687, users have been manually setting /sys/power/resume to fix the issue of not being able to initiate hibernation. (I also could not initiate hibernation but the error I got was different, I believe because I am using a swap partition instead of a swap file.) I have also been using the change in this commit for several days and it has been working for me.

* AFAICT dracut (https://salsa.debian.org/debian/dracut/-/blob/a350037a46942ee345a9a335acedc3586aaa0309/modules.d/95resume/resume.sh#L17) and mkinitcpio (https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/blob/a8e6ee59acb93c604ab7649d26c07588bc056926/hooks/resume#L34) always set /sys/power/resume.

> What value does $SWAPTYPE have in the failing case?

The failing case is during a normal boot, so the swap partition/file does not contain a resume image. I haven't checked with a swap file, but for a swap partition $SWAPTYPE is "swap".

> Why are moving around the plymouth code?

Setting /sys/power/resume does not cause something to immediately happen, so I see no reason to split the calls to plymouth into two separate sections. (I assume this was done in the past because /bin/resume may exit with an error.) I can revert the changes to the plymouth code if you prefer.

Revision history for this message
Benjamin Drung (bdrung) wrote :

I tried to test it in a VM and both the swap file and the swap partition report `swap` as type. I propose following simpler approach as solution: https://git.launchpad.net/~bdrung/ubuntu/+source/initramfs-tools/commit/?id=a9bd6db70c0fd19a19480604a259432af00b8158

Can you test if that would be enough?

Revision history for this message
Jeffery To (jefferyto) wrote :

That change "works" but is misleading/incorrect. The case statement is testing for when the system is resuming. By adding "swap", this changes the case to apply for all boots, both normal and resume; with this change, plymouth will print "Resuming from ..." for normal boots.

Setting /sys/power/resume with an "invalid" value is not harmful. systemd (as part of the EFI change) will not allow hibernation to start unless the resume value refers to a swap device. The kernel will not attempt to resume unless the device contains a resume image (the resume value is ignored and the kernel continues with a normal boot).

Revision history for this message
Benjamin Drung (bdrung) wrote :

No, that is not the case. SWAPTYPE is tested to be a swap. There is no check for being a normal boot or resume. I tested that in a VM (only the normal boot part since the VM does not support suspend).

Revision history for this message
Jeffery To (jefferyto) wrote :

Umm, no... "swsuspend", "s1suspend", "s2suspend", etc. are types of resume images.

Revision history for this message
Benjamin Drung (bdrung) wrote :

What value does SWAPTYPE have when you do a resume? Will it still be "swap" or one of "swsuspend|s1suspend|s2suspend|ulsuspend|tuxonice"?

Revision history for this message
Jeffery To (jefferyto) wrote :

I tried this with a VM (hibernated, then booted from an iso to examine the swap partition), the value I got is "swsuspend".

All of the other values in the case statement (s1suspend, s2suspend, ulsuspend, tuxonice) are older signatures that are no longer relevant.

Revision history for this message
Jeffery To (jefferyto) wrote :

To clarify further, when there is a resume image written to the swap partition, SWAPTYPE is "swsuspend". When there is no resume image (the swap partition is normal swap), SWAPTYPE is "swap". (I would assume the kernel also reads this value to determine if there is a resume image on the device, but this is just a guess.)

It would be great to have this resolved soon as users continue to need to work around this issue to get hibernation working again.

Revision history for this message
Benjamin Drung (bdrung) wrote :

Sorry for the late response. With your feedback I changed the proposed fix to following:
https://code.launchpad.net/~bdrung/ubuntu/+source/initramfs-tools/+git/initramfs-tools/+merge/468584

Can you review/test that solution? Then I'll upload it to oracular and prepare the SRU for noble. The noble SRU will be combined with changes for bug #2065180.

Unmerged commits

ef83547... by Jeffery To

Fix hibernate for systemd v255

The resume device should always be written to the kernel, either (a) to
resume, if a suspend image is found, or (b) to enable suspend to that
device later.

More specifically, systemd v255 will not allow hibernate to start if the
resume device has not be set in the kernel.

This changes the resume local-premount script to always write the resume
device to /sys/power/resume so that hibernate can start.

Fixes: b3a78e4f8057 (" - resume: only resume when the partition contains a resume image - Fix resuming a hibernate session from a swapfile")
Fixes: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/2057687
Signed-off-by: Jeffery To <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/local-premount/resume b/scripts/local-premount/resume
2index 6bd98e8..76e7391 100755
3--- a/scripts/local-premount/resume
4+++ b/scripts/local-premount/resume
5@@ -64,13 +64,11 @@ case "${SWAPTYPE}" in
6 # the message is even visible. Wait just a moment to make
7 # that less likely.
8 sleep 0.1
9- fi
10
11- echo "${MAJMIN}" > /sys/power/resume
12+ # plymouth hide-message does not work yet
13+ plymouth display-message --text=""
14+ fi
15 ;;
16 esac
17
18-if "$use_plymouth"; then
19- # plymouth hide-message does not work yet
20- plymouth display-message --text=""
21-fi
22+echo "${MAJMIN}" > /sys/power/resume

Subscribers

People subscribed via source and target branches