Bug 15695 - in UEFI mode rescue fails to restore bootloader in NVRAM
Summary: in UEFI mode rescue fails to restore bootloader in NVRAM
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: Installer (show other bugs)
Version: Cauldron
Hardware: x86_64 Linux
Priority: release_blocker major
Target Milestone: ---
Assignee: Mageia Bug Squad
QA Contact:
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: 416 14069
  Show dependency treegraph
 
Reported: 2015-04-14 12:06 CEST by Samuel Verschelde
Modified: 2015-04-15 16:59 CEST (History)
5 users (show)

See Also:
Source RPM: drakx-installer-rescue
CVE:
Status comment:


Attachments
output of efibootmgr (591 bytes, text/plain)
2015-04-14 17:11 CEST, Marja Van Waes
Details
screenshot after rescue finished (768.70 KB, image/x-xcf)
2015-04-14 17:16 CEST, Marja Van Waes
Details
screenshot of failed rescue (618.90 KB, image/x-xcf)
2015-04-15 12:05 CEST, Marja Van Waes
Details
fix reinstalling grub2 on UEFI (mga#15695) (1.02 KB, patch)
2015-04-15 13:16 CEST, Thierry Vignaud
Details | Diff
1.51 (820 bytes, patch)
2015-04-15 13:17 CEST, Thierry Vignaud
Details | Diff

Description Samuel Verschelde 2015-04-14 12:06:51 CEST
This is a follow-up to bug 13901 where 2 issues have been fixed already and a third one remains.

After removing the bootloader from NVRAM (I mean, in case it is technically incorrect "from the list of bootloaders the UEFI firmware is aware of so that it can offer to boot from them"), using for example "efibootmgr -O", the rescue mode is unable to restore it. Everything looks like it went fine, but the boot entry is not added back.

See https://bugs.mageia.org/show_bug.cgi?id=13901#c23 and https://bugs.mageia.org/show_bug.cgi?id=13901#c26

Reproducible: 

Steps to Reproduce:
Samuel Verschelde 2015-04-14 12:07:45 CEST

Priority: Normal => release_blocker
Blocks: (none) => 416, 14069
Assignee: bugsquad => thierry.vignaud
Source RPM: (none) => drakx-installer-rescue

Rémi Verschelde 2015-04-14 12:12:24 CEST

CC: (none) => rverschelde

Comment 1 Thierry Vignaud 2015-04-14 12:14:17 CEST
If one just to flip the mode, as you said:
* Switch to Legacy mode
* Switch back to UEFI mode

Then this looks more like a firmware bug to me if switching back & forth in firmware is enough to wipe the mageia entry without actually booting the OS...

CC: (none) => thierry.vignaud, tmb, zen25000
Assignee: thierry.vignaud => bugsquad

Comment 2 Rémi Verschelde 2015-04-14 12:18:31 CEST
> Then this looks more like a firmware bug to me if switching back & forth in firmware is enough to wipe the mageia entry without actually booting the OS...

I agree that the way Stormi triggers his issue is likely to be a firmware bug. On the other hand, it would be nice if drakx-installer-rescue could handle this nevertheless. Upgrading Mageia 5 with the installer manages to restore the bootloader, and this bug is more of a feature request to let drakx-installer-rescue have the same feature.
Comment 3 Samuel Verschelde 2015-04-14 12:33:32 CEST
(In reply to Thierry Vignaud from comment #1)
> If one just to flip the mode, as you said:
> * Switch to Legacy mode
> * Switch back to UEFI mode
> 
> Then this looks more like a firmware bug to me if switching back & forth in
> firmware is enough to wipe the mageia entry without actually booting the
> OS...

Yes it is and I said it already. However, I'm not opening this bug report about a firmware bug, but because, if for whatever reason you lost your boot entry (erased by firmware, mine is not the only to do that, wiped by another OS, for example a windows "rescue"), rescue mode is unable to restore it. The installer can, rescue can't. Marja's tests demonstrate it and that's what the bug is about.
Comment 4 Thierry Vignaud 2015-04-14 12:58:20 CEST
Strange.
What the installer does is calling install_grub2() which:
- calls write_grub2() which:
  o generates /boot/grub2/grub2.cfg
  o update /etc/default/grub,
  o update /boot/grub2/install.sh,
- then call install_grub2 which runs /boot/grub2/install.sh

Rescue only call the later, thus only run /boot/grub2/install.sh
(like we run /boot/grub/install.sh for grub or lilo for lilo)

Updating the other files shouldn't make a difference at all.

What's in your /boot/grub2/install.sh ?

Can you attach a screenshot of the rescue screen once it has finished restoring the bootloader?

Keywords: (none) => NEEDINFO

Comment 5 Marja Van Waes 2015-04-14 17:11:40 CEST
Created attachment 6268 [details]
output of efibootmgr

Here, both before and after testing, /boot/grub2/install.sh contains:

grub2-install --grub-setup=/bin/true /dev/sda --directory /usr/lib/grub/x86_64-efi

I'll attach a screenshot later, but I think the interesting part is the output of efibootmgr after rescue, so attaching that first.

Not only is Mageia not in the BootOrder list, Mageia is not listed at all!

CC: (none) => marja11

Comment 6 Marja Van Waes 2015-04-14 17:16:33 CEST
Created attachment 6269 [details]
screenshot after rescue finished
Comment 7 Marja Van Waes 2015-04-14 17:29:42 CEST
So maybe 

efibootmgr -c -d /dev/sdX -p Y -w -L mageia -l \EFI\mageia\grubx64.efi 

(X = disk letter Y = partion number)

wasn't run?

That command just correctly added Mageia as active entry in the list of efibootmgr entries, and also put it first in the BootOrder list
Comment 8 Marja Van Waes 2015-04-14 17:49:19 CEST
efibootmgr -c -d /dev/sda -p 2 -w -L mageia -l \EFI\mageia\grubx64.efi 

wasn't enough to get the Mageia efi bootloader working again.

After needed SuperGrub2disk again to boot into Mageia, I ran

update-grub2

that didn't do the trick, either, but running

grub2-install

did, and now the Mageia bootloader is back and working :-)

(Note that I chose to restore to a different partition than the one from which the bootloader had been created last)
Marja Van Waes 2015-04-14 17:54:42 CEST

Keywords: NEEDINFO => (none)

Comment 9 Thierry Vignaud 2015-04-15 06:17:43 CEST
That's exactly what does /boot/grub2/install.sh
So that's ought to work.
What contains your /boot/grub2/install.sh?

Keywords: (none) => NEEDINFO

Comment 10 Marja Van Waes 2015-04-15 07:28:10 CEST
(In reply to Thierry Vignaud from comment #9)
> That's exactly what does /boot/grub2/install.sh
> So that's ought to work.
> What contains your /boot/grub2/install.sh?

(In reply to Marja van Waes from comment #5)

>
> Here, both before and after testing, /boot/grub2/install.sh contains:
> 
> grub2-install --grub-setup=/bin/true /dev/sda --directory
> /usr/lib/grub/x86_64-efi
> 

The "after" in that comment was before I ran update-grub and grub2-install.

However, now it is still:

grub2-install --grub-setup=/bin/true /dev/sda --directory /usr/lib/grub/x86_64-efi
Comment 11 Marja Van Waes 2015-04-15 08:33:17 CEST
It would be nice if some more (including me) could test whether doing a fast upgrade-install fixes the problem, like it did for stormi. 
That would make this bug less severe (at least for RC).

Keywords: NEEDINFO => (none)

Comment 12 Thierry Vignaud 2015-04-15 09:17:25 CEST
(In reply to Marja van Waes from comment #10)
> However, now it is still:
> 
> grub2-install --grub-setup=/bin/true /dev/sda --directory
> /usr/lib/grub/x86_64-efi


Can you reconfigure grub2 through drakboot with latest drakxtools, it should write a simpler install.sh
I think rescue would then work.

Keywords: (none) => NEEDINFO

Comment 13 Marja Van Waes 2015-04-15 12:05:48 CEST
Created attachment 6271 [details]
screenshot of failed rescue

(In reply to Thierry Vignaud from comment #12)
> (In reply to Marja van Waes from comment #10)
> > However, now it is still:
> > 
> > grub2-install --grub-setup=/bin/true /dev/sda --directory
> > /usr/lib/grub/x86_64-efi
> 
> 
> Can you reconfigure grub2 through drakboot with latest drakxtools, it should
> write a simpler install.sh

It did, it then only contained: 
grub2-install

> I think rescue would then work.


However, rescue (using boot.iso, mirror updated this morning) gave an error now (tbh, I did not try whether it had worked despite the error it gave), see attached screenshot

After fixing it with a fast upgrade install, which had no problem writing the bootloader, /boot/grub2/install.sh still contains only:
grub2-install

Attachment 6269 is obsolete: 0 => 1

Marja Van Waes 2015-04-15 12:06:02 CEST

Keywords: NEEDINFO => (none)

Comment 14 Thierry Vignaud 2015-04-15 12:14:30 CEST
Please export as png next time, it's easier to handle. And smaller (which is nicer to bugzilla too)
That grub2 error happens when one has grub2-efi installed but is not running in UEFI mode.
Could you confirm you were not in UEFI mode?
I think you've switched in the firmaware...

Keywords: (none) => NEEDINFO

Comment 15 Marja Van Waes 2015-04-15 12:26:14 CEST
(In reply to Thierry Vignaud from comment #14)
> Please export as png next time, it's easier to handle. And smaller (which is
> nicer to bugzilla too)

Will do :-)

> That grub2 error happens when one has grub2-efi installed but is not running
> in UEFI mode.
> Could you confirm you were not in UEFI mode?
> I think you've switched in the firmaware...

Not according to the settings I see in the UEFI, they are still:

UEFI/Legacy Boot            [UEFI Only]
 - CSM Support              [No]

Besides, I did get the _EFI_bootloader_screen_ when booting boot.iso
Also, the upgrade install I ran immediately afterwards did not have a problem writing the bootloader
Marja Van Waes 2015-04-15 12:26:24 CEST

Keywords: NEEDINFO => (none)

Comment 16 Marja Van Waes 2015-04-15 12:28:54 CEST
However, I did use a boot.iso with "useless_thing_accepted", that can't mess this up, can it?
Comment 17 Thomas Backlund 2015-04-15 12:47:48 CEST
Hm, it just hit me...

We only have grub2 on rescue media, not grub2-efi...

And they can not be installed at the same time as they ship a lot of identical files...

I haven't checked how much difference there is between them, but we need better packaging like splitting out identical files to a grub2-common package and so on...
Comment 18 Thomas Backlund 2015-04-15 12:50:06 CEST
And since afaik only the grub2-efi one will call out to efibootmgr...
Comment 19 Thierry Vignaud 2015-04-15 12:51:56 CEST
No. Only changes in firmware are relevant.

@Barry: should we mount other FSes for grub2-install to work in UEFI rescue?
Such as /sys?
Comment 20 Thierry Vignaud 2015-04-15 12:52:45 CEST
(In reply to Thomas Backlund from comment #17)
> Hm, it just hit me...
> 
> We only have grub2 on rescue media, not grub2-efi...

Humm we run /boot/grub2/install.sh in the chroot, so that shouldn't matter.
Comment 21 Thomas Backlund 2015-04-15 12:53:56 CEST
Hm, we need access to /sys/firmware/efi
Comment 22 Thomas Backlund 2015-04-15 12:54:33 CEST
(In reply to Thierry Vignaud from comment #20)
> (In reply to Thomas Backlund from comment #17)
> > Hm, it just hit me...
> > 
> > We only have grub2 on rescue media, not grub2-efi...
> 
> Humm we run /boot/grub2/install.sh in the chroot, so that shouldn't matter.

Ah, yes indeed so correct files are available.
Comment 23 Thierry Vignaud 2015-04-15 13:08:54 CEST
Indeed mounting /sys in /mnt/sys fixes it
Comment 24 Thierry Vignaud 2015-04-15 13:16:59 CEST
Created attachment 6272 [details]
fix reinstalling grub2 on UEFI (mga#15695)
Comment 25 Thierry Vignaud 2015-04-15 13:17:13 CEST
Created attachment 6273 [details]
1.51
Thierry Vignaud 2015-04-15 13:17:23 CEST

Keywords: (none) => PATCH

Comment 26 Mageia Robot 2015-04-15 13:28:20 CEST
commit 5095bce7a4c941684cf10cb1f671af9a7f90f110
Author: Thierry Vignaud <thierry.vignaud@...>
Date:   Wed Apr 15 07:14:17 2015 -0400

    fix reinstalling grub2 on UEFI (mga#15695)
---
 Commit Link:
   http://gitweb.mageia.org/software/drakx/commit/?id=5095bce7a4c941684cf10cb1f671af9a7f90f110
Comment 27 Marja Van Waes 2015-04-15 16:59:09 CEST
Thx, Thierry and Thomas :-D

That fixed it.

Closing, knowing that Stormi will reopen it if it didn't get fixed for him ;-)

Status: NEW => RESOLVED
Resolution: (none) => FIXED


Note You need to log in before you can comment on or make changes to this bug.