[PATCH 0/2] Introduce grub hybrid bootloader and use it.

  • Done
  • quality assurance status badge
Details
2 participants
  • Danny Milosavljevic
  • Ludovic Courtès
Owner
unassigned
Submitted by
Danny Milosavljevic
Severity
normal

Debbugs page

Danny Milosavljevic wrote 8 years ago
(address . guix-patches@gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20170714185954.4381-1-dannym@scratchpost.org
Ok, it turns out that grub-mkrescue can create a hybrid bootloader that works
with both EFI and non-EFI systems.

For that, the contents of lib/grub/i386-pc has to be available to
grub-mkrescue. Then it will build a hybrid bootloader.

I've successfully tested it using:

$ qemu-system-x86_64 -bios $(guix build ovmf)/share/firmware/ovmf_x64.bin -m 1G -enable-kvm -cdrom ZZ -serial stdio
$ qemu-system-x86_64 -bios $(guix build ovmf)/share/firmware/ovmf_x64.bin -m 1G -enable-kvm -hda ZZ -serial stdio
$ qemu-system-x86_64 -m 1G -enable-kvm -cdrom ZZ -serial stdio
$ qemu-system-x86_64 -m 1G -enable-kvm -hda ZZ -serial stdio

and the patch from bug# 27690.

Danny Milosavljevic (2):
bootloader: Add grub-hybrid-bootloader.
install: Use grub-hybrid-bootloader.

gnu/bootloader/grub.scm | 7 +++++++
gnu/packages/bootloaders.scm | 20 ++++++++++++++++++++
gnu/system/install.scm | 3 ++-
3 files changed, 29 insertions(+), 1 deletion(-)
Danny Milosavljevic wrote 8 years ago
[PATCH 1/2] bootloader: Add grub-hybrid-bootloader.
(address . 27695@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20170714190157.4529-1-dannym@scratchpost.org
* gnu/packages/bootloaders.scm (grub-hybrid): New variable.
* gnu/bootloader/grub.scm (grub-hybrid-bootloader): New variable.
---
gnu/bootloader/grub.scm | 7 +++++++
gnu/packages/bootloaders.scm | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+)

Toggle diff (56 lines)
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 880491c98..a67d914ef 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -55,6 +55,7 @@
grub-bootloader
grub-efi-bootloader
+ grub-hybrid-bootloader
grub-configuration))
@@ -413,6 +414,12 @@ submenu \"GNU system, old configurations...\" {~%")
(name 'grub-efi)
(package grub-efi)))
+(define* grub-hybrid-bootloader
+ (bootloader
+ (inherit grub-bootloader)
+ (name 'grub-hybrid)
+ (package grub-hybrid)))
+
;;;
;;; Compatibility macros.
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 9c6927f2a..946bdfd9b 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -182,6 +182,26 @@ menu to select one of the installed operating systems.")
"/bin/mcopy\"")))
#t))))))))))
+(define-public grub-hybrid
+ (package
+ (inherit grub-efi)
+ (name "grub-hybrid")
+ (synopsis "GRand Unified Boot loader (Hybrid version)")
+ (native-inputs
+ `(("grub" ,grub)
+ ,@(package-native-inputs grub-efi)))
+ (arguments
+ (substitute-keyword-arguments (package-arguments grub-efi)
+ ((#:phases phases)
+ `(modify-phases ,phases
+ (add-after 'install 'install-non-efi
+ (lambda* (#:key inputs outputs #:allow-other-keys)
+ (copy-recursively (string-append (assoc-ref inputs "grub")
+ "/lib/grub/i386-pc")
+ (string-append (assoc-ref outputs "out")
+ "/lib/grub/i386-pc"))
+ #t))))))))
+
(define-public syslinux
(let ((commit "bb41e935cc83c6242de24d2271e067d76af3585c"))
(package
Danny Milosavljevic wrote 8 years ago
[PATCH 2/2] install: Use grub-hybrid-bootloader.
(address . 27695@debbugs.gnu.org)(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20170714190157.4529-2-dannym@scratchpost.org
* gnu/system/install.scm (installation-os): Use grub-hybrid-bootloader.
---
gnu/system/install.scm | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

Toggle diff (14 lines)
diff --git a/gnu/system/install.scm b/gnu/system/install.scm
index f9aa7f673..ea4c40511 100644
--- a/gnu/system/install.scm
+++ b/gnu/system/install.scm
@@ -299,7 +299,8 @@ Use Alt-F2 for documentation.
(host-name "gnu")
(timezone "Europe/Paris")
(locale "en_US.utf8")
- (bootloader (grub-configuration
+ (bootloader (bootloader-configuration
+ (bootloader grub-hybrid-bootloader)
(device "/dev/sda")))
(file-systems
;; Note: the disk image build code overrides this root file system with
Danny Milosavljevic wrote 8 years ago
Re: [PATCH 0/2] Introduce grub hybrid bootloader and use it.
(address . 27695@debbugs.gnu.org)
20170714213457.0fb2b613@scratchpost.org
On Fri, 14 Jul 2017 20:59:54 +0200
Danny Milosavljevic <dannym@scratchpost.org> wrote:

Toggle quote (15 lines)
> Ok, it turns out that grub-mkrescue can create a hybrid bootloader that works
> with both EFI and non-EFI systems.
>
> For that, the contents of lib/grub/i386-pc has to be available to
> grub-mkrescue. Then it will build a hybrid bootloader.
>
> I've successfully tested it using:
>
> $ qemu-system-x86_64 -bios $(guix build ovmf)/share/firmware/ovmf_x64.bin -m 1G -enable-kvm -cdrom ZZ -serial stdio
> $ qemu-system-x86_64 -bios $(guix build ovmf)/share/firmware/ovmf_x64.bin -m 1G -enable-kvm -hda ZZ -serial stdio
> $ qemu-system-x86_64 -m 1G -enable-kvm -cdrom ZZ -serial stdio
> $ qemu-system-x86_64 -m 1G -enable-kvm -hda ZZ -serial stdio
>
> and the patch from bug# 27690.

and the patch from bug# 27689.

To clarify: I've tested both

$ guix system disk-image gnu/system/install.scm

and

$ guix system disk-image -t iso9660 gnu/system/install.scm

- both successfully.
Ludovic Courtès wrote 8 years ago
Re: [bug#27695] [PATCH 1/2] bootloader: Add grub-hybrid-bootloader.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 27695@debbugs.gnu.org)
87379rzeml.fsf@gnu.org
Hi,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (3 lines)
> * gnu/packages/bootloaders.scm (grub-hybrid): New variable.
> * gnu/bootloader/grub.scm (grub-hybrid-bootloader): New variable.

[...]

Toggle quote (5 lines)
> +(define-public grub-hybrid
> + (package
> + (inherit grub-efi)
> + (name "grub-hybrid")
> + (synopsis "GRand Unified Boot loader (Hybrid version)")
^
Lower-case please.

Toggle quote (15 lines)
> + (native-inputs
> + `(("grub" ,grub)
> + ,@(package-native-inputs grub-efi)))
> + (arguments
> + (substitute-keyword-arguments (package-arguments grub-efi)
> + ((#:phases phases)
> + `(modify-phases ,phases
> + (add-after 'install 'install-non-efi
> + (lambda* (#:key inputs outputs #:allow-other-keys)
> + (copy-recursively (string-append (assoc-ref inputs "grub")
> + "/lib/grub/i386-pc")
> + (string-append (assoc-ref outputs "out")
> + "/lib/grub/i386-pc"))
> + #t))))))))

Is it really all it takes to make a GRUB that can do both BIOS and UEFI?
I wonder why GRUB upstream doesn’t do it by default. Do you think we
should discuss it with them?

If that works, we might just as well make it the new “grub” package and
remove “grub-efi”. Or is there any downside?

Thanks,
Ludo’.
Danny Milosavljevic wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 27695@debbugs.gnu.org)
20170720134732.7972d5bb@scratchpost.org
Hi Ludo,

On Thu, 20 Jul 2017 10:39:14 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

Toggle quote (3 lines)
> Is it really all it takes to make a GRUB that can do both BIOS and UEFI?
> I wonder why GRUB upstream doesn’t do it by default.

I think they do, in a sense. In many other distributions the directory is common - so if you install both grub-pc and grub-efi on your disk then grub will indeed use both (for grub-mkrescue).

Toggle quote (5 lines)
> Do you think we should discuss it with them?
>
> If that works, we might just as well make it the new “grub” package and
> remove “grub-efi”. Or is there any downside?

I only use this feature for grub-mkrescue right now. I know that it is supported *there* in the sense that there's explicit "if" blocks checking for both platforms (by literals) in the same function, but not exclusively (i.e. "if (efi) A; if (non efi) B;" without "else"). See main() in util/grub-mkrescue.c in grub 2.02 (lines 667ff for EFI, lines 571ff for "PC"). The EFI stuff has "_EFI" in the preprocessor definitions, so search for that.

Note that main() supports a command line option for getting the source files for ONE SINGLE platform, but when you don't specify that option then it uses multiple platforms (the ones it can find).

For using multiple platforms as a regular bootloader I do NOT know whether that works or makes sense at all. Maybe it does, I just didn't test it (and can't usefully).

That's why there's the alternative implementation that wouldn't add a Guix bootloader for it.

I hope someone else knows. I don't have EFI hardware so I'm really the wrong person to find out that stuff. Well I could try reading the documentation / asking and hoping that it's all correct, but ... you know... paper is patient :)

util/grub-install.c seems to use a case anaylsis with exclusive cases for finding out EFI or not *shrugs*.
Danny Milosavljevic wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 27695@debbugs.gnu.org)
20170720204207.52475d50@scratchpost.org
Toggle quote (2 lines)
> I hope someone else knows. I don't have EFI hardware so I'm really the wrong person to find out that stuff. Well I could try reading the documentation / asking and hoping that it's all correct, but ... you know... paper is patient :)

I read up on EFI some more. Apparently EFI can load files from FAT partitions and execute them.

There's the tool "grub-mkstandalone" which will put the GRUB bootloader into an executable file that you can then put on the FAT partition - which the EFI system will later boot from.

So I guess we already do all that's required for installed-hybrid support because Marius already added the grub-mkstandalone invocation to gnu/build/vm.scm - and we install the traditional grub-pc otherwise. So isn't it already hybrid? Can't be far off.

Maybe I contributed to the confusion, but my meddling with grub-efi and grub-hybrid is really just to have grub-mkrescue build a hybrid ISO, nothing else. I don't use grub-install at all there (and I don't use grub-mkstandalone either).

I think the best way forward for the ISO image to do it like that:
* Add grub-hybrid to (gnu packages bootloaders) - but don't add a (gnu bootloaders) entry. Don't use grub-hybrid for anything except when creating the ISO image.
* Either make gnu/system/install.scm directly depend on grub-hybrid as "bootloader" package - or just have make-iso9660-image always override it by grub-hybrid.

That's it. I don't think we have to fiddle with the regular Guix bootloaders or even with the existing bootloader packages at all.
Danny Milosavljevic wrote 7 years ago
(no subject)
(address . control@debbugs.gnu.org)
20171223231647.1bbaf7f1@scratchpost.org
close 27695
?
Your comment

This issue is archived.

To comment on this conversation send an email to 27695@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 27695
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help