GNU bug report logs - #55631
[PATCH] gnu: grub: add removable grub-efi bootloader option

Previous Next

Package: guix-patches;

Reported by: Karl Hallsby <karl <at> hallsby.com>

Date: Wed, 25 May 2022 14:04:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 55631 in the body.
You can then email your comments to 55631 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#55631; Package guix-patches. (Wed, 25 May 2022 14:04:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Karl Hallsby <karl <at> hallsby.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 25 May 2022 14:04:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Karl Hallsby <karl <at> hallsby.com>
To: guix-patches <at> gnu.org
Cc: Karl Hallsby <karl <at> hallsby.com>
Subject: [PATCH] gnu: grub: add removable grub-efi bootloader option
Date: Tue, 24 May 2022 23:32:54 -0500
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(+)

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 <at> gmail.com>
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
 ;;; Copyright © 2020 Stefan <stefan-guix <at> vodafonemail.de>
+;;; Copyright © 2022 Karl Hallsby <karl <at> 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)

base-commit: d129d962e437fd215c5e9428fc1b26e2d72ffbda
-- 
2.36.1





Information forwarded to guix-patches <at> gnu.org:
bug#55631; Package guix-patches. (Thu, 26 May 2022 20:15:02 GMT) Full text and rfc822 format available.

Message #8 received at 55631 <at> debbugs.gnu.org (full text, mbox):

From: Karl Hallsby <karl <at> hallsby.com>
To: 55631 <at> debbugs.gnu.org
Date: Thu, 26 May 2022 15:14:22 -0500
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.




Information forwarded to guix-patches <at> gnu.org:
bug#55631; Package guix-patches. (Fri, 03 Jun 2022 21:28:02 GMT) Full text and rfc822 format available.

Message #11 received at 55631 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Karl Hallsby <karl <at> hallsby.com>
Cc: 55631 <at> debbugs.gnu.org
Subject: Re: bug#55631: [PATCH] gnu: grub: add removable grub-efi bootloader
 option
Date: Fri, 03 Jun 2022 23:27:17 +0200
Hi,

Karl Hallsby <karl <at> 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’.




Information forwarded to guix-patches <at> gnu.org:
bug#55631; Package guix-patches. (Sat, 04 Jun 2022 04:31:01 GMT) Full text and rfc822 format available.

Message #14 received at 55631 <at> debbugs.gnu.org (full text, mbox):

From: Karl Hallsby <karl <at> hallsby.com>
To: 55631 <at> debbugs.gnu.org
Cc: Karl Hallsby <karl <at> hallsby.com>
Subject: [PATCH] gnu: grub: add documentation for new
 grub-efi-removable-bootloader
Date: Fri,  3 Jun 2022 23:29:31 -0500
---
 doc/guix.texi | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 184206bec8..fdfd024a7a 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -103,6 +103,7 @@ Copyright @copyright{} 2021 Josselin Poiret@*
 Copyright @copyright{} 2022 Remco van 't Veer@*
 Copyright @copyright{} 2022 Aleksandr Vityazev@*
 Copyright @copyright{} 2022 Philip M <at> sup{c}Grath@*
+Copyright @copyright{} 2022 Karl Hallsby@*

 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -36282,8 +36283,8 @@ The type of a bootloader configuration declaration.
 @cindex BIOS, bootloader
 The bootloader to use, as a @code{bootloader} object.  For now
 @code{grub-bootloader}, @code{grub-efi-bootloader},
-@code{grub-efi-netboot-bootloader}, @code{extlinux-bootloader} and
-@code{u-boot-bootloader} are supported.
+@code{grub-efi-netboot-bootloader}, @code{grub-efi-removable-bootloader},
+@code{extlinux-bootloader} and @code{u-boot-bootloader} are supported.

 @cindex ARM, bootloaders
 @cindex AArch64, bootloaders
@@ -36352,6 +36353,20 @@ NFS servers, you also need a properly configured DHCP server to make the booting
 over netboot possible.  For all this we can currently only recommend you to look
 for instructions about @acronym{PXE, Preboot eXecution Environment}.

+@vindex grub-efi-removable-bootloader
+@code{grub-efi-removable-bootloader} allows you to boot your system from
+removable media by writing the GRUB file to the UEFI-specification location of
+@file{/EFI/BOOT/BOOTX64.efi} of the boot directory, usually @file{/boot/efi}.
+This is also useful for some UEFI firmwares that ``forget'' their configuration
+from their non-volatile storage. Like @code{grub-efi-bootloader}, this can only
+be used if the @file{/sys/firmware/efi} directory is available.
+
+@quotation Note
+This @emph{will} overwrite the GRUB file from any other operating systems that
+also place their GRUB file in the UEFI-specification location; making them
+unbootable.
+@end quotation
+
 @item @code{targets}
 This is a list of strings denoting the targets onto which to install the
 bootloader.
@@ -36360,7 +36375,8 @@ The interpretation of targets depends on the bootloader in question.
 For @code{grub-bootloader}, for example, they should be device names
 understood by the bootloader @command{installer} command, such as
 @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
-GNU GRUB Manual}).  For @code{grub-efi-bootloader}, they should be mount
+GNU GRUB Manual}).  For @code{grub-efi-bootloader} and
+@code{grub-efi-removable-bootloader} they should be mount
 points of the EFI file system, usually @file{/boot/efi}.  For
 @code{grub-efi-netboot-bootloader}, @code{targets} should be the mount
 points corresponding to TFTP root directories served by your TFTP

base-commit: f47dce686a57e5eb793003e37101df63b5eb37ae
--
2.36.1




Information forwarded to guix-patches <at> gnu.org:
bug#55631; Package guix-patches. (Sun, 05 Jun 2022 14:23:01 GMT) Full text and rfc822 format available.

Message #17 received at 55631 <at> debbugs.gnu.org (full text, mbox):

From: Tom Fitzhenry <tom <at> tom-fitzhenry.me.uk>
To: Karl Hallsby <karl <at> hallsby.com>
Cc: 55631 <at> debbugs.gnu.org
Subject: Re: [bug#55631] [PATCH] gnu: grub: add removable grub-efi
 bootloader option
Date: Sun, 05 Jun 2022 16:22:15 +0200
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!




Information forwarded to guix-patches <at> gnu.org:
bug#55631; Package guix-patches. (Mon, 06 Jun 2022 20:14:02 GMT) Full text and rfc822 format available.

Message #20 received at 55631 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Tom Fitzhenry <tom <at> tom-fitzhenry.me.uk>
Cc: Karl Hallsby <karl <at> hallsby.com>, 55631 <at> debbugs.gnu.org
Subject: Re: bug#55631: [PATCH] gnu: grub: add removable grub-efi bootloader
 option
Date: Mon, 06 Jun 2022 22:13:10 +0200
Tom Fitzhenry <tom <at> 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’.




Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Mon, 06 Jun 2022 20:14:02 GMT) Full text and rfc822 format available.

Notification sent to Karl Hallsby <karl <at> hallsby.com>:
bug acknowledged by developer. (Mon, 06 Jun 2022 20:14:02 GMT) Full text and rfc822 format available.

Message #25 received at 55631-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Karl Hallsby <karl <at> hallsby.com>
Cc: 55631-done <at> debbugs.gnu.org
Subject: Re: bug#55631: [PATCH] gnu: grub: add removable grub-efi bootloader
 option
Date: Mon, 06 Jun 2022 22:12:50 +0200
Hi Karl,

Karl Hallsby <karl <at> hallsby.com> skribis:

> +@vindex grub-efi-removable-bootloader
> +@code{grub-efi-removable-bootloader} allows you to boot your system from
> +removable media by writing the GRUB file to the UEFI-specification location of
> +@file{/EFI/BOOT/BOOTX64.efi} of the boot directory, usually @file{/boot/efi}.
> +This is also useful for some UEFI firmwares that ``forget'' their configuration
> +from their non-volatile storage. Like @code{grub-efi-bootloader}, this can only
> +be used if the @file{/sys/firmware/efi} directory is available.

I merged the two patches, added a ChangeLog-style commit log¹, and
committed.

Thank you!

Ludo’.

¹ https://guix.gnu.org/manual/devel/en/html_node/Submitting-Patches.html




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 05 Jul 2022 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 289 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.