Bug 15153 - Patches to add support for the rEFInd boot manager in drakboot
Summary: Patches to add support for the rEFInd boot manager in drakboot
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: RPM Packages (show other bugs)
Version: Cauldron
Hardware: x86_64 Linux
Priority: Low enhancement
Target Milestone: ---
Assignee: Thierry Vignaud
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-29 00:38 CET by Martin Whitaker
Modified: 2018-10-14 10:14 CEST (History)
3 users (show)

See Also:
Source RPM: drakxtools-backend
CVE:
Status comment:


Attachments
Patch for /lib/libDrakX/bootloader.pm (2.92 KB, patch)
2015-01-29 00:38 CET, Martin Whitaker
Details | Diff
Patch for /lib/libDrakX/any.pm (2.23 KB, patch)
2015-01-29 00:39 CET, Martin Whitaker
Details | Diff
Patch for /lib/libDrakX/any.pm (2.22 KB, patch)
2015-02-21 17:33 CET, Martin Whitaker
Details | Diff
Patch for /lib/libDrakX/bootloader.pm (3.10 KB, patch)
2015-02-21 17:34 CET, Martin Whitaker
Details | Diff
add refind support (5.75 KB, patch)
2015-02-21 18:13 CET, Thierry Vignaud
Details | Diff
Updated patch (5.87 KB, text/plain)
2015-03-03 01:32 CET, Martin Whitaker
Details
Updated patch (6.27 KB, text/plain)
2015-04-05 13:41 CEST, Martin Whitaker
Details
Patch to prevent installer forcing the use of grub2 when the rEFInd boot manager is being used (761 bytes, text/plain)
2015-04-05 13:47 CEST, Martin Whitaker
Details
Patch to add support for rEFInd boot manager in drakboot (updated) (8.28 KB, text/plain)
2015-04-18 00:42 CEST, Martin Whitaker
Details
add support for rEFInd boot manager (mga#15153) (7.02 KB, patch)
2016-07-05 10:08 CEST, Thierry Vignaud
Details | Diff
do not preselect grub2 if refind is configured (1.15 KB, patch)
2016-07-05 10:08 CEST, Thierry Vignaud
Details | Diff
add support for rEFInd boot manager (mga#15153) ( (7.05 KB, patch)
2016-07-05 10:40 CEST, Thierry Vignaud
Details | Diff
refind-install: don't choke on /dev/vda (371 bytes, patch)
2016-07-05 10:41 CEST, Thierry Vignaud
Details | Diff
refidn-install: adapt to Mageia's /boot/EFI (2.52 KB, patch)
2016-07-05 10:41 CEST, Thierry Vignaud
Details | Diff
patch to add support for rEFInd boot manager (11.76 KB, text/plain)
2018-09-14 15:37 CEST, Martin Whitaker
Details

Description Martin Whitaker 2015-01-29 00:38:32 CET
Created attachment 5844 [details]
Patch for /lib/libDrakX/bootloader.pm

As there now seems to be a number of Mageia users who are using the rEFInd boot manager, I think it would be useful to support this in drakboot. Attached is the first of two patches to do this (second patch to follow).

With these patches applied to the stage 2 installer in the M5 beta 1 classic installer ISO (copied to a USB stick), I was able to install and boot M5 on a UEFI system with legacy boot disabled (I can't test with M5 beta 2, because the installer is broken).

After applying the patches to the installed system, I was able to edit the boot options via the MCC.

Currently this relies on rEFInd being installed manually. I can look at adapting the rEFInd RPM for Mageia, but will wait to see if these patches are accepted before doing any more work on this.
Comment 1 Martin Whitaker 2015-01-29 00:39:14 CET
Created attachment 5845 [details]
Patch for /lib/libDrakX/any.pm
Manuel Hiebel 2015-02-01 16:23:28 CET

Assignee: bugsquad => thierry.vignaud

Comment 2 Martin Whitaker 2015-02-21 17:33:41 CET
Created attachment 5932 [details]
Patch for /lib/libDrakX/any.pm

Updated patches to accommodate changes since beta 1.

Attachment 5845 is obsolete: 0 => 1

Comment 3 Martin Whitaker 2015-02-21 17:34:24 CET
Created attachment 5933 [details]
Patch for /lib/libDrakX/bootloader.pm

Attachment 5844 is obsolete: 0 => 1

Comment 4 Thierry Vignaud 2015-02-21 18:13:06 CET
Created attachment 5936 [details]
add refind support

Does this patch works as well (especially the reorder in any.pm for smaller changes)
Else it fixes a couple perl_checker warnings
Thierry Vignaud 2015-02-21 18:14:44 CET

Keywords: (none) => NEEDINFO

Comment 5 Martin Whitaker 2015-02-21 20:18:30 CET
No, the reorder in any.pm means that the 'if ($e->{type} eq "image")' branch gets taken instead of the 'elsif ($b->{method} eq 'refind')' branch. All this means is that the user gets presented with some options that aren't used in the rEFInd configuration, so if you really don't like it, you could take out that branch.

Apart from that, it seems to work as before.
Comment 6 Martin Whitaker 2015-03-01 22:11:57 CET
I've just noticed I've used

  -e "/boot/EFI/EFI/refind"

in two places in bootloader.pm, which should probably be

  -e "$::prefix/boot/EFI/EFI/refind"

Any chance of this making it into Mageia-5?

Keywords: NEEDINFO => (none)

Comment 7 Martin Whitaker 2015-03-03 01:32:52 CET
Created attachment 5975 [details]
Updated patch

As well as fixing the errors mentioned in the previous comment, this also ensures that a newly installed kernel update will be the default on the next boot.

Attachment 5932 is obsolete: 0 => 1
Attachment 5933 is obsolete: 0 => 1
Attachment 5936 is obsolete: 0 => 1

Comment 8 Thierry Vignaud 2015-03-03 09:07:44 CET
We don't want that.
That's the user choice which choose the default entry
Comment 9 Martin Whitaker 2015-03-03 09:45:44 CET
(In reply to Thierry Vignaud from comment #8)
> We don't want that.
> That's the user choice which choose the default entry

No, that's not true. When you install a kernel update, the symlinks in /boot are modified to make the new kernel the default. rEFInd ignores the symlinks, so I had to find a different way to get this behaviour.

Also, rEFInd defaults to selecting the previously booted menu entry. If the user overrides this in the rEFInd configuration file, that will take precedence over the suggestion made by drakboot.
Comment 10 Martin Whitaker 2015-04-05 13:41:20 CEST
Created attachment 6187 [details]
Updated patch

Updated patch to prevent an empty configuration file being written if the /boot/vmlinuz symbolic link has gone missing (an empty configuration file exposes a nasty bug in the current version of rEFInd).

Attachment 5975 is obsolete: 0 => 1

Comment 11 Martin Whitaker 2015-04-05 13:47:37 CEST
Created attachment 6188 [details]
Patch to prevent installer forcing the use of grub2 when the rEFInd boot manager is being used

This additional patch is needed to stop the installer automatically installing grub2 and making it the default boot manager when the user has already chosen to install and use rEFInd. It does not prevent the user subsequently choosing grub2 when configuring the bootloader at the end of stage 2.
Comment 12 Thierry Vignaud 2015-04-07 09:47:44 CEST
I feel uneasy about adding support for another bootloader now (I fear breaking existing stuff).
Could more people test those patches?
Comment 13 Martin Whitaker 2015-04-07 21:35:17 CEST
It wouldn't be hard for others to test if they are already using UEFI boot. rEFInd is available as a RPM package, which is easy to install from an existing Mageia system. I know one of the QA team (Lewys Smith) is already using rEFInd, because he's written about it on the Wiki, so he might be a good person to ask.

Generally though, my patches should be fairly safe - unless rEFInd is already installed, then it won't appear as an option. I'm ready to do the extra work to make it fully available, but I thought that might be best left for Mageia-6.
Comment 14 Thierry Vignaud 2015-04-08 10:00:23 CEST
@Thomas: what do you think?
Comment 15 Thierry Vignaud 2015-04-13 16:19:10 CEST
BTW You need to update your patch.
See http://gitweb.mageia.org/software/drakx/commit/perl-install/bootloader.pm?id=6a38c077285c88dcf4d042ec43b6803ba5c56cb1
("fix detecting grub2 on ESP")
Comment 16 Martin Whitaker 2015-04-13 19:10:28 CEST
(In reply to Thierry Vignaud from comment #15)
> BTW You need to update your patch.
> See
> http://gitweb.mageia.org/software/drakx/commit/perl-install/bootloader.
> pm?id=6a38c077285c88dcf4d042ec43b6803ba5c56cb1
> ("fix detecting grub2 on ESP")

Not sure what you mean - my patch still applies cleanly, and still works as I expect it to. The Mageia-specific configuration for rEFInd is only ever stored in /boot, never on the ESP.
Comment 17 Thierry Vignaud 2015-04-13 19:24:07 CEST
The goal is to detect it :-)
That is, detectloader must return "refind".
Drakboot should default to refind once rerunning on a system booted with refind. It should not advertize grub2.
Comment 18 Martin Whitaker 2015-04-13 21:27:30 CEST
I think I've already implemented what you want:

  - at install time, if refind is installed in the ESP, it becomes
    the default choice of bootloader. The user can change to grub2
    at the end of stage 2 if they wish

  - in a running system, drakboot will show refind as the default
    choice if either

    - both refind is installed in the ESP and the file
      /boot/refind_linux.conf exists

    - refind is installed in the ESP and grub2 is not
      installed

In the latter case, drakboot will report that no bootloader is found and generate the default boot config - I need this to generate a new refind_linux.conf file.

What have I missed?

N.B. It is possible that a user may wish to use both refind and grub2, using refind as the primary boot manager and grub2 as a second level. I've tried to allow for this by making sure grub2 is the first choice once it is installed.
Comment 19 Thierry Vignaud 2015-04-13 22:31:38 CEST
That's b/c detectloader (which reuses bootloader.pm) cannot find what bootloader is installed.
For ESP case, the only choice we have is a file test.
See above commit for grub2.
Comment 20 Martin Whitaker 2015-04-18 00:42:53 CEST
Created attachment 6308 [details]
Patch to add support for rEFInd boot manager in drakboot (updated)

This update adds support for switching between grub2 and rEFInd. drakboot correctly identifies which is the currently selected boot manager.

I noticed whilst testing this that when grub2 is selected, changes made by the user to the list of entries are ignored - and when you first select grub2, the list bears no relation to what is actually generated. Maybe this step needs to be skipped when grub2 is selected.

Attachment 6187 is obsolete: 0 => 1

Comment 21 Thierry Vignaud 2015-05-12 14:27:15 CEST
Another issue is that it prevents switching back to grub2 once installed (in method_choices_raw())
Comment 22 Martin Whitaker 2015-05-12 19:53:12 CEST
(In reply to Thierry Vignaud from comment #21)
> Another issue is that it prevents switching back to grub2 once installed (in
> method_choices_raw())

No it doesn't. I tested it multiple times.
Comment 23 Thierry Vignaud 2015-05-12 20:40:29 CEST
Comment on attachment 6308 [details]
Patch to add support for rEFInd boot manager in drakboot (updated)

If refind needs efibootmgr, it should requires it instead of patching bootloader.pm in order to install it (last bit of your patch)
Comment 24 Martin Whitaker 2015-05-12 22:33:39 CEST
(In reply to Thierry Vignaud from comment #23) 
> If refind needs efibootmgr, it should requires it instead of patching
> bootloader.pm in order to install it (last bit of your patch)

No, because:

1) rEFInd doesn't need efibootmgr - drakboot does (if you select rEFInd).

2) rEFInd may have been installed from another distribution, or even from Windows or MacOS. It does not need to be installed again from inside Mageia. It requires nothing to be created inside the Mageia distribution except the configuration file that my patched drakboot creates (and even that is optional). It's a boot manager, not a boot loader.

3) We don't currently have a Mageia package for installing rEFInd (I installed it using the vanilla upstream package, which works well enough). I'll take the time to create one if these patches ever get accepted. At that point we can change the package that drakboot installs and add the requires.
Comment 25 Thierry Vignaud 2016-07-05 10:08:01 CEST
Created attachment 8124 [details]
add support for rEFInd boot manager (mga#15153)

rebased over current git + pass perl_checker

Attachment 6308 is obsolete: 0 => 1

Comment 26 Thierry Vignaud 2016-07-05 10:08:24 CEST
Created attachment 8125 [details]
do not preselect grub2 if refind is configured

rebased over current git

Attachment 6188 is obsolete: 0 => 1

Comment 27 Thierry Vignaud 2016-07-05 10:40:45 CEST
Created attachment 8126 [details]
add support for rEFInd boot manager (mga#15153) (

v3: log error

I fixed it not to use $::prefix for accessing /sys
The new log error shows that this was never tested as writing to the /sys/firmware/efi/efivars/... fails with "no such file"

We obviously should use refind-install.
But we would need to actually package refind...
Also there's bug with upstream refind-install regarding Mageia (see the patches I'll attach)

Last but not least, detectloader hasn't been updated to detect we configured refind....

Attachment 8124 is obsolete: 0 => 1

Comment 28 Thierry Vignaud 2016-07-05 10:41:35 CEST
Created attachment 8127 [details]
refind-install: don't choke on /dev/vda
Comment 29 Thierry Vignaud 2016-07-05 10:41:53 CEST
Created attachment 8128 [details]
refidn-install: adapt to Mageia's /boot/EFI
Thierry Vignaud 2016-07-05 10:42:05 CEST

Priority: Normal => Low

Comment 30 Maurice Batey 2016-08-22 19:01:46 CEST
As a previous user of the GAG boot manager I was - on my HP 450 UEFI Probook  - very happy to install and use the excellent rEFInd as boot manager, doubly so when I was made aware recently of the additional benefit it can provide of avoiding altogether the use of Grub - which can be uninstalled...

This is now working smoothly, and the Installer proposal in this 'bug' report will greatly facilitate this big improvement.

CC: (none) => maurice

Comment 31 Martin Whitaker 2016-08-22 23:30:29 CEST
(In reply to Thierry Vignaud from comment #27)
> We obviously should use refind-install.
> But we would need to actually package refind...

I'm not entirely convinced this is the right thing to do. The only part of rEFInd that "belongs" to the Mageia installation is the /boot/refind_linux.conf file that drakboot creates. The files in the ESP provide a boot manager which is common to all OS installations on the machine. If you allow the installer to reinstall rEFInd, there's a danger you will break something. The refind-install script takes some care to preserve any changes the user has made to a previous installation, but I don't know how robust it is if the version of rEFInd being installed is older than the one already installed (which could happen in the future if, e.g., someone had the latest version of Mageia installed and decided to (re)install an older version).

If you really do want to go down this route, I think we should at least prompt the user to ask if they want to reinstall rEFInd.

The alternative is to stick with my original scheme of simply detecting that a user has manually installed rEFInd, and not meddling with it.

> Also there's bug with upstream refind-install regarding Mageia (see the
> patches I'll attach)

I've submitted your first patch upstream. The second patch wasn't suitable for submission because other distros mount the ESP at /boot/efi, so I created and submitted an alternative patch that checked both mount points.

> Last but not least, detectloader hasn't been updated to detect we configured
> refind....

You removed the parts of my patch that handled this :-(
Comment 32 Barry Jackson 2017-03-14 18:23:58 CET
I think that just because rEFInd boot manager is installed on a machine it's detection should not affect the installation of grub2-efi as default bootloader.

I see nothing wrong with creating a configuration file for it though.

CC: (none) => zen25000

Comment 33 Maurice Batey 2017-03-14 19:05:58 CET
IMHO no, not at all - rEFInd will find the grub.efi file and include an icon for it on its boot menu, with the option to boot via that.

But the grub.efi isn't *needed*, as rEFInd can boot straight into an install's /boot directory; it just needs the ad hoc /boot/refind_linux.conf there to allow rEFInd to make a neater job of it.
Comment 34 Barry Jackson 2017-03-14 20:43:03 CET
(In reply to Maurice Batey from comment #33)
> IMHO no, not at all - rEFInd will find the grub.efi file and include an icon
> for it on its boot menu, with the option to boot via that.

But it can't do that if the presence of rEFInd on a system inhibits the installation of grub2.

> 
> But the grub.efi isn't *needed*, as rEFInd can boot straight into an
> install's /boot directory; it just needs the ad hoc /boot/refind_linux.conf
> there to allow rEFInd to make a neater job of it.

OK I understand grub2 is not needed if you want to use rEFInd exclusively, however I don't yet see how you can select which kernel to boot, or enter rescue mode using rEFInd alone.
Comment 35 Martin Whitaker 2017-03-14 21:53:28 CET
(In reply to Barry Jackson from comment #34)
> (In reply to Maurice Batey from comment #33)
> > IMHO no, not at all - rEFInd will find the grub.efi file and include an icon
> > for it on its boot menu, with the option to boot via that.
> 
> But it can't do that if the presence of rEFInd on a system inhibits the
> installation of grub2.

The patches don't (or at least didn't) inhibit the installation of grub2 - they just prevent it being installed regardless of whether it's wanted. And they make the not unreasonable assumption that if rEFInd is installed, the user wants to use it. If grub2 is installed, it becomes the default for future changes.

> OK I understand grub2 is not needed if you want to use rEFInd exclusively,
> however I don't yet see how you can select which kernel to boot, or enter
> rescue mode using rEFInd alone.

F2 lets you select different boot options.

The patches need updating. I'll do this once mga6 is out.
Comment 36 Barry Jackson 2017-03-15 15:10:56 CET
(In reply to Martin Whitaker from comment #35)
> (In reply to Barry Jackson from comment #34)
> > (In reply to Maurice Batey from comment #33)
> > > IMHO no, not at all - rEFInd will find the grub.efi file and include an icon
> > > for it on its boot menu, with the option to boot via that.
> > 
> > But it can't do that if the presence of rEFInd on a system inhibits the
> > installation of grub2.
> 
> The patches don't (or at least didn't) inhibit the installation of grub2 -
> they just prevent it being installed regardless of whether it's wanted. 

So if there is rEFInd on a machine and I install Mageia (assuming patches are present) then I can install with grub2 and also get the rEFInd config?
That would be the only option I would consider using.

> And
> they make the not unreasonable assumption that if rEFInd is installed, the
> user wants to use it. 

Not necessarily, a user may install rEFInd just to have it there as an alternative when set as the first in the boot order.

> If grub2 is installed, it becomes the default for
> future changes.
> 
> > OK I understand grub2 is not needed if you want to use rEFInd exclusively,
> > however I don't yet see how you can select which kernel to boot, or enter
> > rescue mode using rEFInd alone.
> 
> F2 lets you select different boot options.

Thanks I will check that out in VM
> 
> The patches need updating. I'll do this once mga6 is out.
Comment 37 Martin Whitaker 2018-09-14 15:37:19 CEST
Created attachment 10371 [details]
patch to add support for rEFInd boot manager

  - rebased to current git master
  - restored the code that supported switching between rEFInd and GRUB2
  - fixed the real issues that prevented the PreviousBoot EFI variable being written
  - modified to use the newly-created Mageia refind package
  - added support for installing in /EFI/BOOT (a workaround for buggy BIOSs that ignore the settings in NVRAM)
  - dropped the patch that prevented automatic installation of the grub2-efi package
    - users can manually remove it later

Attachment 8125 is obsolete: 0 => 1
Attachment 8126 is obsolete: 0 => 1

Comment 38 Thierry Vignaud 2018-09-17 15:58:58 CEST
What's the Unicode change?
What was your issue?
It's probably unrelated to refind & should probably a split commit.
Comment 39 Martin Whitaker 2018-09-18 00:30:30 CEST
(In reply to Thierry Vignaud from comment #38)
> What's the Unicode change?
> What was your issue?
> It's probably unrelated to refind & should probably a split commit.

In the patch:

+	    print $efivar Encode::encode('UTF16-LE', $default_kernel);

That doesn't work if the Unicode module isn't available.
Comment 40 Martin Whitaker 2018-10-14 10:14:04 CEST
Released in cauldron.

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


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