Bug 856392

Summary: systemd - point grub at the right entry before hibernating
Product: [openSUSE] openSUSE Tumbleweed Reporter: Vojtech Dziewiecki <vdziewiecki>
Component: BasesystemAssignee: Thomas Blume <thomas.blume>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Major    
Priority: P5 - None CC: fcrozat, forgotten_GTSR6JWjet, ihno, jslaby, mchang, systemd-maintainers, thomas.blume, tiwai
Version: 13.2 Milestone 0   
Target Milestone: ---   
Hardware: All   
OS: SUSE Other   
Whiteboard:
Found By: Development Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: grub.sh, should go to /usr/lib/systemd/system-sleep
Updated script (that should still go to /usr/lib/systemd/system-sleep)
Script updated again
systemd-sleep-grub

Description Vojtech Dziewiecki 2013-12-19 19:14:29 UTC
Created attachment 572623 [details]
grub.sh, should go to /usr/lib/systemd/system-sleep

Hi,
I believe this functionality has to be added before switching from pm-utils to
systemd suspend/hibernate.
When a computer is turned on after hibernating, grub must chose the right entry automatically, and not let the user chose. If the user would choose to boot into another OS, bad things could happen.

To fix this, just put the attached script to /usr/lib/systemd/system-sleep.

Thanks,
Wojtek
Comment 1 Forgotten User GTSR6JWjet 2014-01-18 22:38:01 UTC
Created attachment 574877 [details]
Updated script (that should still go to /usr/lib/systemd/system-sleep)

This script is slightly improved version of previously attached (by Wojtek). This one works good for me.
Comment 2 Forgotten User GTSR6JWjet 2014-01-18 22:45:44 UTC
(In reply to comment #0)
> Created an attachment (id=572623) [details]

Hello Wojtek,

Thanks for the script, I've tested it on my box and made some small fixes and
modifications. You can review them, my version is attachment #2 [details] here.

Nikolai
Comment 3 Forgotten User GTSR6JWjet 2014-01-18 22:53:37 UTC
And sorry for messing up attachments, I'm not too used to this bugzilla...
(Luckily there is still "Show obsolete" button)
Comment 4 Vojtech Dziewiecki 2014-01-20 13:34:52 UTC
What exactly is this change about? I've seen the diff but it's still not clear to me..
Comment 5 Forgotten User GTSR6JWjet 2014-01-20 16:44:34 UTC
(In reply to comment #4)
> What exactly is this change about? I've seen the diff but it's still not clear
> to me..

Actually just 3 trivial things:

1. Instead of relying on previously saved copy of grub's environment file (/var/run/suspend.grubonce.default) to restore normal grub behaviour (unlock current entry), use grub2-editenv to explicitely remove (the previously added) "next_entry" from current environment file. This method seems to work more reliable for me, although in theory it should not matter much.

2. The invocation of grub2-editenv needs to explicitely specify actual grub's environment file name (/boot/grub2/grubenv = GRUBDEFAULT) as first argument, otherwise it sees to complain and not work;

3. The "prepare-parameters" line was added to "grub-once-restore()". Without this line, all used variables (like GRUBDEFAULT) are empty and so the function has no action.

That's all.

Thank you.
Nikolai
Comment 6 Vojtech Dziewiecki 2014-02-20 16:59:27 UTC
Created attachment 579344 [details]
Script updated again

There was one mistake, there was suspend_hybrid instead of hybrid-sleep, I fixed that.
BTW hybrid-sleep does not work I think, but that's off topic.
Comment 14 Michael Chang 2014-02-26 07:40:56 UTC
(In reply to comment #5)

> Actually just 3 trivial things:
> 
> 1. Instead of relying on previously saved copy of grub's environment file
> (/var/run/suspend.grubonce.default) to restore normal grub behaviour (unlock
> current entry), use grub2-editenv to explicitely remove (the previously added)
> "next_entry" from current environment file. This method seems to work more
> reliable for me, although in theory it should not matter much.

Good catch. This helps in the case that grub can't write to grubenv file and clear the flag, due to /boot partition is not physical (ie software raid or logical volume). This fixes the annoying bug which system permanently booting to the hibernated kernel entry.  

> 
> 2. The invocation of grub2-editenv needs to explicitely specify actual grub's
> environment file name (/boot/grub2/grubenv = GRUBDEFAULT) as first argument,
> otherwise it sees to complain and not work;

list does not require the environment file name and set/unset does. But agree that it's better practice we explicit specify it (and follow it's syntax described in man page).

> 
> 3. The "prepare-parameters" line was added to "grub-once-restore()". Without
> this line, all used variables (like GRUBDEFAULT) are empty and so the function
> has no action.

Yes this is required.
Comment 19 Thomas Blume 2014-03-25 10:18:29 UTC
Btw. using systemd for hibernation/suspend will obsolete: Forward-suspend-hibernate-calls-to-pm-utils.patch
Frederic, this was your patch from bug 790157.
Should I remove it?
Comment 20 Frederic Crozat 2014-03-25 10:30:26 UTC
(In reply to comment #19)
> Btw. using systemd for hibernation/suspend will obsolete:
> Forward-suspend-hibernate-calls-to-pm-utils.patch
> Frederic, this was your patch from bug 790157.
> Should I remove it?

yes, go ahead, you have my blessing to remove this dirty hack :)
Comment 22 Thomas Blume 2014-03-25 15:21:28 UTC
Created attachment 583605 [details]
systemd-sleep-grub

script together with patch from bug 856389 submitted to factory
Comment 24 Thomas Blume 2014-03-28 08:43:45 UTC
Patch submitted to SLE-12
Comment 29 Thomas Blume 2014-04-10 08:15:23 UTC
Checked usr/lib/pm-utils/sleep.d/99Zgrub from pm-utils on s390x. It is the same script like on the other architectures.
Hence my converted script should work on s390x too.

closing this bug as fixed.
Comment 30 Michael Chang 2014-05-22 06:48:16 UTC
*** Bug 869711 has been marked as a duplicate of this bug. ***
Comment 31 Swamp Workflow Management 2016-02-03 14:24:48 UTC
openSUSE-RU-2016:0320-1: An update that has 146 recommended fixes can now be installed.

Category: recommended (moderate)
Bug References: 737690,742774,750845,818044,838475,841544,849870,852015,852021,852232,853293,854884,856389,856392,856858,857204,858864,859072,859365,860574,860937,861316,861489,863217,864745,864904,865834,866732,866933,867128,867663,867664,867840,868019,868230,868439,868931,869142,869603,872929,873432,873444,874665,875502,876587,876694,877021,877674,878525,880438,880732,881125,881559,881942,882393,882714,883565,884271,884403,885232,885288,886211,886599,886852,888178,888215,888612,889297,889357,890977,892096,892162,892300,893797,895087,896664,897799,897801,897803,898233,898240,898432,900558,901481,902240,902901,903009,903963,904214,904517,904828,905550,906709,906900,907318,907393,908476,909358,910643,911347,912030,912334,913517,916420,918118,919095,920195,921831,921898,921920,926169,927250,927457,928265,931388,932284,933365,933512,933521,933533,934077,934901,937512,937900,938908,939571,940264,941576,944132,944799,945282,947212,948458,948555,948705,949574,949683,949739,950510,951265,951663,953241,954336,954781,955635,961576
CVE References: 
Sources used:
openSUSE 13.1 (src):    systemd-210-40.1, systemd-mini-210-40.1