Bug 941758

Summary: grub-once isn't called at hibernate
Product: [openSUSE] openSUSE Tumbleweed Reporter: Takashi Iwai <tiwai>
Component: BasesystemAssignee: Cristian Rodríguez <crrodriguez>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: arvidjaar, bwiedemann, chcao, crrodriguez, jengelh, lmuelle, mchang, suse, systemd-maintainers
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
See Also: http://bugzilla.opensuse.org/show_bug.cgi?id=941682
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Takashi Iwai 2015-08-14 09:50:37 UTC
Since the recent change of systemd, grub-once isn't called any longer, thus at thawing, the normal GRUB menu is shown instead of the direct boot to the target kernel.

The regression was introduced in openSUSE:Factory/systemd changeset 215:

Wed Feb 18 05:01:38 UTC 2015 - crrodriguez@opensuse.org
....
- systemd-sleep-grub: moved to the grub2 package where it belongs as a
  suspend/resume hook (SR#286533) (drops prepare-suspend-to-disk.patch)

However, SR#286533 was declined and it's lost since then.

The fix would be either revert the change in systemd or put the hook properly into grub2 package.

The latter method has a potential bug, however.  systemd-sleep doesn't call hooks to restore when writing to /sys/power/state fails.  That is, if we have a hook to set up grubenv, it'll left when the hibernation fails, and the next boot would go wrong.  This didn't happen in the past because it invoked the grubenv setup in a different manner.
Comment 1 Michael Chang 2015-08-14 10:32:41 UTC
Here is the note from last review if considering it in grub2 package.

1. cleanup to not having any pm-util related environment variable
2. remove grub related part in the script
3  provide the package as conditional, maybe after some systemd version (or we may have conflicted file ?)
4. packaged as noarch subpackage and maybe "Supplements: packageand(systemd-sleep:grub2)" to install it if systemd-sleep and grub2 is to be installed , do not putting it in grub package.

Thanks.
Comment 2 Takashi Iwai 2015-08-14 12:28:25 UTC
(In reply to Michael Chang from comment #1)
> 4. packaged as noarch subpackage and maybe "Supplements:
> packageand(systemd-sleep:grub2)" to install it if systemd-sleep and grub2 is
> to be installed , do not putting it in grub package.

I wonder whether this gives any big merit.  systemd is mandatory, and grub2 is almost mandatory for x86.  So, this hook shall be installed always in the end.
Comment 3 Dr. Werner Fink 2015-08-14 13:02:40 UTC
(In reply to Takashi Iwai from comment #2)

Both Cristian and the grub2 maintainers seems to have a different opinion.  Compare with https://build.opensuse.org/request/show/286533

For both Cristian and Andrei: Please provide a user friendly solution for this problem.
Comment 4 Jan Engelhardt 2015-08-14 13:35:41 UTC
The supplements idea is just best (but perhaps we need EssentialFor:packageand()), because then you don't have to force either systemd or grub to carry the files.
Comment 5 Takashi Iwai 2015-08-14 13:46:49 UTC
(In reply to Jan Engelhardt from comment #4)
> The supplements idea is just best (but perhaps we need
> EssentialFor:packageand()), because then you don't have to force either
> systemd or grub to carry the files.

Well, to my eyes, this looks like a thing that is more relevant to grub2 than systemd.  The hook is placed in a public place, and the content of the hook is rather specific to grub.  But after all, this is a matter the maintainer should decide at best for the ease of maintenance.

The worst thing is the brokenness like now.  Please fix ASAP.
Comment 6 Michael Chang 2015-08-17 07:01:47 UTC
I will work on this. Thanks.
Comment 7 Michael Chang 2015-08-31 07:17:27 UTC
Hi,

Close this bug as systemd-sleep-plugin subpackage has been added to grub2.
Thanks.
Comment 8 Michael Chang 2015-08-31 07:19:49 UTC
*** Bug 941682 has been marked as a duplicate of this bug. ***
Comment 9 Thomas Blume 2016-08-01 11:11:59 UTC
*** Bug 991350 has been marked as a duplicate of this bug. ***
Comment 10 Thomas Leineweber 2016-08-01 16:08:35 UTC
Although sleep has been moved to a subpackage of grub, there are some remains in the systemd package (as shown in bug 991350):

* The script /usr/bin/systemd-sleep-grub is called from the systemd-units /usr/lib/systemd/system/systemd-hibernate.service and /usr/lib/systemd/system/systemd-hybrid-hibernate.service

> [Service]
> Type=oneshot
> ExecStart=/usr/bin/systemd-sleep-grub pre
> ExecStart=/usr/lib/systemd/systemd-sleep hibernate                  
> ExecStopPost=/usr/bin/systemd-sleep-grub post

* But this script has been removed with https://build.opensuse.org/request/show/407291

This error exists at least in Leap 42.2.
Comment 11 Thomas Leineweber 2016-08-02 16:15:24 UTC
I created a pull request on github with the fix for the SLE12-SP2 branch of systemd. It removes the calls to systemd-sleep-grub from the two units for hibernate.

https://github.com/openSUSE/systemd/pull/2
Comment 14 Bernhard Wiedemann 2019-10-22 19:08:50 UTC
This seems to be long fixed.
In 15.0 and later there is bug 1154783 though with a similar effect.