From patchwork Wed Jan 24 21:58:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 59366 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 015B127BBE2; Wed, 24 Jan 2024 22:06:19 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 78D9927BBE9 for ; Wed, 24 Jan 2024 22:06:17 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSlNg-0002RT-6Z; Wed, 24 Jan 2024 17:06:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSlNd-0002Qx-9m for guix-patches@gnu.org; Wed, 24 Jan 2024 17:05:57 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rSlNc-0000Lg-B0 for guix-patches@gnu.org; Wed, 24 Jan 2024 17:05:56 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rSlNh-0008Le-PM for guix-patches@gnu.org; Wed, 24 Jan 2024 17:06:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68702] [PATCH] WIP: gnu: bootloader: Add efi-stub-bootloader. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 24 Jan 2024 22:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68702 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68702@debbugs.gnu.org Cc: Herman Rimm X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.170613390331978 (code B ref -1); Wed, 24 Jan 2024 22:06:01 +0000 Received: (at submit) by debbugs.gnu.org; 24 Jan 2024 22:05:03 +0000 Received: from localhost ([127.0.0.1]:46746 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rSlMk-0008JJ-5p for submit@debbugs.gnu.org; Wed, 24 Jan 2024 17:05:03 -0500 Received: from lists.gnu.org ([2001:470:142::17]:38020) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rSlMh-0008Ic-6J for submit@debbugs.gnu.org; Wed, 24 Jan 2024 17:05:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSlMW-0002CZ-Cl for guix-patches@gnu.org; Wed, 24 Jan 2024 17:04:48 -0500 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117] helo=email.rimm.ee) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1rSlMT-0007qX-OC for guix-patches@gnu.org; Wed, 24 Jan 2024 17:04:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1706133879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7cpS+pDLRCoiFqK/nDzlle1GeUNLxZ3wAnUcUmOS/4Q=; b=OTk8KtSd8JJOqRtuPRztmXq5m2rZqJyihjLEoqU/8x4BGTVmVwUctZunH/o+lXBEjiZf+Z JR5Pel/6OxHsGcxOCbhK3cJKjV6u7iaUE5TYUxf5pwzxb4bu2g566Ya4eNzCj7v9RZAh1+ J7yz/EmbGuJIRdziVaDHSi0GGCp0MHqu201GstLChmcKfxBDd3Tkf/nIGSM1IIOu9Xk7HE zoUNOiBu/jOcgcqDnfLl2aYwitOmxXSSETACGpGxmpVOug+M9tvXlBTrg5+VXoQWfs4uhl Qj4LaKZx3qq1NAPiABUH24UPbpWqbXFJYTF6W8b8O5qOpzqhrz5rkjqJHcqjhQ== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 6074fe7e (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Wed, 24 Jan 2024 22:04:39 +0000 (UTC) Date: Wed, 24 Jan 2024 22:58:31 +0100 Message-ID: <941a6206de12ad011f9f2eda48a9a2d57c2c0734.1706133511.git.herman@rimm.ee> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=81.205.150.117; envelope-from=herman@rimm.ee; helo=email.rimm.ee X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_PBL=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * doc/guix.texi (Bootloader Configuration)[bootloader,targets]: Document efi-stub-bootloader. * gnu/bootloader/efi-stub.scm: New file. * gnu/local.mk: Register file. Change-Id: Ia0ee0b8ded636f2647d9f4afaf8fed153e732b52 --- Hi all, This patch adds efi-stub-bootloader which is based on uefi-uki- bootloader from [bug#68524], that should get merged first. Though maybe you can answer some of my questions: 1. How can I load (a newer) bootloader module? The --load-path option is only meant to load package modules. 2. How do I get rid of: (define (menu-entry->args e) #~(string-join (list #$@(menu-entry-linux-arguments e)))) 3. Related, what can I do about: (list #$@(map-in-order menu-entry-label entries)) (list #$@(map-in-order menu-entry-linux entries)) (list #$@(map-in-order menu-entry->args entries)) (list #$@(map-in-order menu-entry-initrd entries)) (list #$@(map-in-order menu-entry-device entries)) 4. If mount-point/boot/efi does not exist, the bootloader is installed to /boot/efi. This is in case the user is installing guix to mount-point but has the ESP mounted to /boot/efi. However the manual instructs the user to mount it to /mnt/boot/efi before running 'guix system init'. Also, if the user forgets to create (and mount) /mnt/boot/efi, the init fails with a 'failed to get canonical path of /boot/efi' error. Is it also okay to immediately fail if /mnt/boot/efi does not exist? Related conditional statement: (invoke install (if (file-exists? target-esp) target-esp efi-dir)) Thank you for your time, Herman Rimm doc/guix.texi | 35 ++++++++---- gnu/bootloader/efi-stub.scm | 110 ++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 gnu/bootloader/efi-stub.scm base-commit: da3e6aea0a750246e8a9120d62441c3df65faff0 prerequisite-patch-id: d5fe3fcbdd7961f687f72d0e4262af7fffe92435 prerequisite-patch-id: 9eddb6700a8d8fe0f5604d084ca90cd23381613b prerequisite-patch-id: 38851b9a3c7437328ceccff94815abd939e6d1e5 diff --git a/doc/guix.texi b/doc/guix.texi index 2cd05634bd..d7d158b7db 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -124,6 +124,8 @@ Copyright @copyright{} 2023 Saku Laesvuori@* Copyright @copyright{} 2023 Graham James Addis@* Copyright @copyright{} 2023 Tomas Volf@* +Copyright @copyright{} 2024 Lilah Tascheter@* +Copyright @copyright{} 2024 Herman Rimm@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -41110,9 +41112,10 @@ Bootloader Configuration The bootloader to use, as a @code{bootloader} object. For now @code{grub-bootloader}, @code{grub-efi-bootloader}, @code{grub-efi-removable-bootloader}, @code{grub-efi-netboot-bootloader}, -@code{grub-efi-netboot-removable-bootloader}, @code{extlinux-bootloader}, -@code{u-boot-bootloader}, @code{uefi-uki-bootloader}, and -@code{uefi-uki-signed-bootloader} are supported. +@code{grub-efi-netboot-removable-bootloader}, @code{efi-stub-bootloader}, +@code{extlinux-bootloader}, @code{u-boot-bootloader}, +@code{uefi-uki-bootloader} and @code{uefi-uki-signed-bootloader} are +supported. @cindex ARM, bootloaders @cindex AArch64, bootloaders @@ -41219,11 +41222,18 @@ Bootloader Configuration unbootable. @end quotation +@vindex efi-stub-bootloader +@code{efi-stub-bootloader} boots a linux kernel directly through UEFI, without +a bootloader like GRUB. A practical advantage of this is allowing root/store +encryption without an extra GRUB password entry and slow decryption step. It +also makes it possible to have filesystems not yet supported by GRUB as root, +like bcachefs. + @vindex uefi-uki-bootloader -@code{uefi-uki-bootloader} boots a linux kernel directly through UEFI, without -an intermediary like GRUB. The main practical advantage of this is allowing -root/store encryption without an extra GRUB password entry and slow decryption -step. +@code{uefi-uki-bootloader} is like @code{efi-stub-bootloader}, but it boots a +unified kernel image (UKI) instead. The main advantage is that the UKI can be +booted from an EFI shell or file browser in the BIOS, when the corresponding +UEFI boot entry is lost or removed. @vindex uefi-uki-signed-bootloader @code{uefi-uki-signed-bootloader} is like @code{uefi-uki-bootloader}, except @@ -41246,11 +41256,12 @@ Bootloader Configuration 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}, -@code{grub-efi-removable-bootloader}, @code{uefi-uki-bootloader}, and -@code{uefi-uki-signed-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 server. +@code{grub-efi-removable-bootloader}, @code{efi-stub-bootloader}, +@code{uefi-uki-bootloader} and @code{uefi-uki-signed-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 server. @item @code{menu-entries} (default: @code{'()}) A possibly empty list of @code{menu-entry} objects (see below), denoting diff --git a/gnu/bootloader/efi-stub.scm b/gnu/bootloader/efi-stub.scm new file mode 100644 index 0000000000..ed36cbef83 --- /dev/null +++ b/gnu/bootloader/efi-stub.scm @@ -0,0 +1,110 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2024 Marius Bakke +;;; Copyright © 2024 Lilah Tascheter +;;; Copyright © 2024 Herman Rimm +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu bootloader efi-stub) + #:use-module (gnu bootloader) + #:use-module (gnu packages bootloaders) + #:use-module (gnu packages linux) + #:use-module (guix gexp) + #:use-module (guix modules) + #:export (efi-stub-bootloader)) + +;; Config generator makes script creating uki images; +;; install runs script; +;; install device is path to uefi dir. + +(define* (efi-stub-configuration-file config entries + #:key + (old-entries '()) + #:allow-other-keys) + (define (menu-entry->args e) + #~(string-join (list #$@(menu-entry-linux-arguments e)))) + + (program-file "install-efi-stub" + (with-imported-modules (source-module-closure '((guix build utils))) + #~(let* ((target-esp (cadr (command-line))) + (vendir (string-append target-esp "/EFI/Guix")) + (schema (string-append vendir "/boot.mgr")) + (findmnt #$(file-append util-linux "/bin/findmnt")) + (efibootmgr #$(file-append efibootmgr "/sbin/efibootmgr"))) + (use-modules (guix build utils) (ice-9 popen) (ice-9 textual-ports)) + + (define disk + (call-with-port + ;; TODO: try findmnt with multi-device Bcachefs and Btrfs. + (open-pipe* OPEN_READ findmnt "-fnro" "SOURCE" "-T" target-esp) + (lambda (port) (get-line port)))) ; only 1 line: the device + + (when (file-exists? schema) + (call-with-input-file schema + (lambda (port) + (for-each (lambda (l) + (unless (string-null? l) + (system* efibootmgr "-q" "-B" "-L" l))) + (string-split (get-string-all port) #\lf))))) + (when (directory-exists? vendir) (delete-file-recursively vendir)) + + (define (out file) + (string-append vendir "/" (basename file))) + + (define (boot file) + (string-append "\\EFI\\Guix\\" (basename file))) + + (mkdir-p vendir) + (call-with-output-file schema + (lambda (port) + (for-each + (lambda (label loader args initrd device) + (copy-file loader (out loader)) + (copy-file initrd (out initrd)) + (invoke efibootmgr + "-q" "-c" "-L" label "-d" disk "-l" (boot loader) + "-u" (string-append args " initrd=" (boot initrd))) + (put-string port label) + (put-char port #\lf)) + (list #$@(map-in-order menu-entry-label entries)) + (list #$@(map-in-order menu-entry-linux entries)) + (list #$@(map-in-order menu-entry->args entries)) + (list #$@(map-in-order menu-entry-initrd entries)) + (list #$@(map-in-order menu-entry-device entries))))))))) + +(define install-efi-stub + ;; mount-point is /mnt in guix system init /etc/config.scm /mnt/point; + ;; efi-dir comes from target list of bootloader configuration. + #~(lambda (bootloader efi-dir mount-point) + ;; There is nothing useful to do when called in the context of a disk + ;; image generation. + (when efi-dir + (let ((install (string-append mount-point "/boot/install-efi-stub.scm")) + ;; When installing Guix, it's common to mount EFI-DIR below + ;; MOUNT-POINT rather than /boot/efi on the live image. + (target-esp (string-append mount-point efi-dir))) + (invoke install (if (file-exists? target-esp) + target-esp + efi-dir)))))) + +(define efi-stub-bootloader + (bootloader + (name 'efi-stub) + (package #f) ; The EFI boot stub is a part of linux. + (installer install-efi-stub) + (disk-image-installer #f) + (configuration-file "/boot/install-efi-stub.scm") + (configuration-file-generator efi-stub-configuration-file))) diff --git a/gnu/local.mk b/gnu/local.mk index 43d02ee793..1b75fa7487 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -87,6 +87,7 @@ GNU_SYSTEM_MODULES = \ %D%/artwork.scm \ %D%/bootloader.scm \ %D%/bootloader/grub.scm \ + %D%/bootloader/efi-stub.scm \ %D%/bootloader/extlinux.scm \ %D%/bootloader/u-boot.scm \ %D%/bootloader/depthcharge.scm \