diff mbox series

[bug#55631] gnu: grub: add removable grub-efi bootloader option

Message ID 20220525043254.62715-1-karl@hallsby.com
State Accepted
Headers show
Series [bug#55631] gnu: grub: add removable grub-efi bootloader option | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Karl Hallsby May 25, 2022, 4:32 a.m. UTC
For single-disk installs (external USBs) and for amnesiac UEFIs, Guix is not
found using its default Grub EFI bootloader location of
/boot/efi/EFI/Guix/grubx64.efi means the Guix install will not be found.

To handle this, we can place the bootloader file in the UEFI specification
location, overwriting any other OS that may have placed a file there. This
location is namely /boot/efi/EFI/BOOT/BOOTX64.efi. Grub has explicit support
for this location/situation with the `--removable` flag.
---
 gnu/bootloader/grub.scm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)


base-commit: d129d962e437fd215c5e9428fc1b26e2d72ffbda

Comments

Karl Hallsby May 26, 2022, 8:14 p.m. UTC | #1
This was only tested in virtual machines or on disk images. But this
has been running on my actual hardware for the past few days, and has
been working fine, including when unplugging and replugging the
device. The BIOS/UEFI properly picks up the drive/boot file and load
Guix.
Ludovic Courtès June 3, 2022, 9:27 p.m. UTC | #2
Hi,

Karl Hallsby <karl@hallsby.com> skribis:

> For single-disk installs (external USBs) and for amnesiac UEFIs, Guix is not
> found using its default Grub EFI bootloader location of
> /boot/efi/EFI/Guix/grubx64.efi means the Guix install will not be found.
>
> To handle this, we can place the bootloader file in the UEFI specification
> location, overwriting any other OS that may have placed a file there. This
> location is namely /boot/efi/EFI/BOOT/BOOTX64.efi. Grub has explicit support
> for this location/situation with the `--removable` flag.

Interesting.  The patch LGTM; one last thing: could you add a couple of
lines in doc/guix.texi, under “Bootloader Configuration” (next to where
‘grub-efi-netboot-bootloader’ is described) describing
‘grub-efi-removable-bootloader’?

With that in place, we should be all set.

Thanks in advance,
Ludo’.
Tom Fitzhenry June 5, 2022, 2:22 p.m. UTC | #3
I have tested this on my Pine64 RockPro64 running Tow Boot, which is an
amnesiac UEFI.

This works for me, and allows me to avoid needing Guix to provide a
 custom u-boot for this board, as discussed in
 https://lists.gnu.org/archive/html/guix-devel/2022-05/msg00073.html .

Thanks!
Ludovic Courtès June 6, 2022, 8:13 p.m. UTC | #4
Tom Fitzhenry <tom@tom-fitzhenry.me.uk> skribis:

> I have tested this on my Pine64 RockPro64 running Tow Boot, which is an
> amnesiac UEFI.
>
> This works for me, and allows me to avoid needing Guix to provide a
>  custom u-boot for this board, as discussed in
>  https://lists.gnu.org/archive/html/guix-devel/2022-05/msg00073.html .

Awesome, thanks for testing!

Ludo’.
diff mbox series

Patch

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 120cd55012..65d7171432 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -7,6 +7,7 @@ 
 ;;; Copyright © 2019, 2020 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
+;;; Copyright © 2022 Karl Hallsby <karl@hallsby.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -50,10 +51,12 @@  (define-module (gnu bootloader grub)
             grub-theme-color-highlight
             grub-theme-gfxmode
 
+            install-grub-efi-removable
             install-grub-efi-netboot
 
             grub-bootloader
             grub-efi-bootloader
+            grub-efi-removable-bootloader
             grub-efi-netboot-bootloader
             grub-mkrescue-bootloader
             grub-minimal-bootloader
@@ -608,6 +611,31 @@  (define install-grub-efi
                         "--bootloader-id=Guix"
                         "--efi-directory" target-esp)))))
 
+(define install-grub-efi-removable
+  #~(lambda (bootloader efi-dir mount-point)
+      ;; NOTE: mount-point is /mnt in guix system init /etc/config.scm /mnt/point
+      ;; NOTE: efi-dir comes from target list of booloader configuration
+      ;; There is nothing useful to do when called in the context of a disk
+      ;; image generation.
+      (when efi-dir
+        ;; Install GRUB onto the EFI partition mounted at EFI-DIR, for the
+        ;; system whose root is mounted at MOUNT-POINT.
+        (let ((grub-install (string-append bootloader "/sbin/grub-install"))
+              (install-dir (string-append mount-point "/boot"))
+              ;; When installing Guix, it's common to mount EFI-DIR below
+              ;; MOUNT-POINT rather than /boot/efi on the live image.
+              (target-esp (if (file-exists? (string-append mount-point efi-dir))
+                              (string-append mount-point efi-dir)
+                              efi-dir)))
+          ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
+          ;; root partition.
+          (setenv "GRUB_ENABLE_CRYPTODISK" "y")
+          (invoke/quiet grub-install "--boot-directory" install-dir
+                        "--removable"
+                        ;; "--no-nvram"
+                        "--bootloader-id=Guix"
+                        "--efi-directory" target-esp)))))
+
 (define (install-grub-efi-netboot subdir)
   "Define a grub-efi-netboot bootloader installer for installation in SUBDIR,
 which is usually efi/Guix or efi/boot."
@@ -734,6 +762,12 @@  (define grub-efi-bootloader
    (name 'grub-efi)
    (package grub-efi)))
 
+(define grub-efi-removable-bootloader
+  (bootloader
+   (inherit grub-efi-bootloader)
+   (name 'grub-efi-removable-bootloader)
+   (installer install-grub-efi-removable)))
+
 (define grub-efi-netboot-bootloader
   (bootloader
    (inherit grub-efi-bootloader)