From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id eFlnEk+b214LTAAA0tVLHw (envelope-from ) for ; Sat, 06 Jun 2020 13:34:07 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id ADYgDk+b214lYgAAB5/wlQ (envelope-from ) for ; Sat, 06 Jun 2020 13:34:07 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D30289403EE for ; Sat, 6 Jun 2020 13:34:06 +0000 (UTC) Received: from localhost ([::1]:34218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhYxZ-0007QU-H8 for larch@yhetil.org; Sat, 06 Jun 2020 09:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhYxW-0007QM-PS for guix-patches@gnu.org; Sat, 06 Jun 2020 09:34:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39531) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhYxW-0002Bi-Gb for guix-patches@gnu.org; Sat, 06 Jun 2020 09:34:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jhYxW-0006D0-ED for guix-patches@gnu.org; Sat, 06 Jun 2020 09:34:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41011] [PATCH] gnu: grub: Support for network boot via tftp/nfs. Resent-From: Stefan Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 06 Jun 2020 13:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41011 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Mathieu Othacehe Cc: 41011@debbugs.gnu.org Received: via spool by 41011-submit@debbugs.gnu.org id=B41011.159145041923832 (code B ref 41011); Sat, 06 Jun 2020 13:34:02 +0000 Received: (at 41011) by debbugs.gnu.org; 6 Jun 2020 13:33:39 +0000 Received: from localhost ([127.0.0.1]:51077 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jhYx8-0006CK-Ce for submit@debbugs.gnu.org; Sat, 06 Jun 2020 09:33:38 -0400 Received: from vsmx012.vodafonemail.xion.oxcs.net ([153.92.174.90]:33582) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jhYx7-0006C8-2g for 41011@debbugs.gnu.org; Sat, 06 Jun 2020 09:33:37 -0400 Received: from vsmx004.vodafonemail.xion.oxcs.net (unknown [192.168.75.198]) by mta-8-out.mta.xion.oxcs.net (Postfix) with ESMTP id 89823F34E34; Sat, 6 Jun 2020 13:33:31 +0000 (UTC) Received: from macbook-pro.kuh-wiese.my-router.de (unknown [145.254.41.70]) by mta-8-out.mta.xion.oxcs.net (Postfix) with ESMTPA id F02CD19ADB0; Sat, 6 Jun 2020 13:33:26 +0000 (UTC) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) From: Stefan In-Reply-To: Date: Sat, 6 Jun 2020 15:33:26 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <9AAFEFF4-8ACE-4C95-975F-67C3F4FDAF81@vodafonemail.de> <87a72gi4kz.fsf@gmail.com> <1179D890-7D6C-43D8-A286-DA7A0F61D585@vodafonemail.de> <87h7w7cc55.fsf@gnu.org> <92DB8E2B-1CA2-41AE-9265-53C4F5337686@vodafonemail.de> X-Mailer: Apple Mail (2.3124) X-VADE-STATUS: LEGIT X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.7 (-) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 0.99 X-TUID: /jBjpzNnmDfi * gnu/bootloader/grub.scm (grub-efi-net-bootloader): New efi bootloader = for network booting via tftp/nfs. (install-grub-efi-net): New bootloader installer for tftp. (grub-root-search): Adding support for tftp root. (eye-candy): Use 'gfxterm' for all systems if selected via = 'terminal-outputs'. * gnu/system.scm (read-boot-parameters): Prevent devices with ":/" from = being treated as a file system label. * gnu/build/linux-boot.scm (device-string->file-system-device): Prevent = devices with ":/" from being treated as a file system label. --- gnu/bootloader/grub.scm | 127 +++++++++++++++++++++++++++------------ gnu/build/linux-boot.scm | 1 + gnu/system.scm | 3 +- 3 files changed, 93 insertions(+), 38 deletions(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index 2d9a39afc3..60b3a12037 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -23,7 +23,7 @@ =20 (define-module (gnu bootloader grub) #:use-module (guix records) - #:use-module ((guix utils) #:select (%current-system)) + #:use-module ((guix utils) #:select (%current-system = %current-target-system)) #:use-module (guix gexp) #:use-module (gnu artwork) #:use-module (gnu bootloader) @@ -47,6 +47,8 @@ =20 grub-bootloader grub-efi-bootloader + make-grub-efi-net-bootloader + grub-efi-net-bootloader grub-mkrescue-bootloader grub-minimal-bootloader =20 @@ -135,41 +137,25 @@ file with the resolution provided in CONFIG." (_ #f))))) =20 (define* (eye-candy config store-device store-mount-point - #:key store-directory-prefix system port) + #:key store-directory-prefix port) "Return a gexp that writes to PORT (a port-valued gexp) the = 'grub.cfg' part concerned with graphics mode, background images, colors, and all that. STORE-DEVICE designates the device holding the store, and = STORE-MOUNT-POINT is its mount point; these are used to determine where the background image = and -fonts must be searched for. SYSTEM must be the target system = string---e.g., -\"x86_64-linux\". STORE-DIRECTORY-PREFIX is a directory prefix to = prepend to -any store file name." - (define setup-gfxterm-body - (let ((gfxmode - (or (and-let* ((theme (bootloader-configuration-theme = config)) - (gfxmode (grub-theme-gfxmode theme))) - (string-join gfxmode ";")) - "auto"))) - - ;; Intel and EFI systems need to be switched into graphics mode, = whereas - ;; most other modern architectures have no other mode and = therefore - ;; don't need to be switched. - - ;; XXX: Do we really need to restrict to x86 systems? We could = imitate - ;; what the GRUB default configuration does and decide based on = whether - ;; a user provided 'gfxterm' in the terminal-outputs field of = their - ;; bootloader-configuration record. - (if (string-match "^(x86_64|i[3-6]86)-" system) - (format #f " - set gfxmode=3D~a - insmod all_video - insmod gfxterm~%" gfxmode) - ""))) - +fonts must be searched for. STORE-DIRECTORY-PREFIX is a directory = prefix to +prepend to any store file name." (define (setup-gfxterm config font-file) (if (memq 'gfxterm (bootloader-configuration-terminal-outputs = config)) - #~(format #f "if loadfont ~a; then - setup_gfxterm -fi~%" #+font-file) + #~(format #f " +if loadfont ~a; then + set gfxmode=3D~a + insmod all_video + insmod gfxterm +fi~%" + #$font-file + #$(string-join + (grub-theme-gfxmode (bootloader-theme config)) + ";")) "")) =20 (define (theme-colors type) @@ -190,8 +176,6 @@ fi~%" #+font-file) =20 (and image #~(format #$port " -function setup_gfxterm {~a} - # Set 'root' to the partition that contains /gnu/store. ~a =20 @@ -206,7 +190,6 @@ else set menu_color_normal=3Dcyan/blue set menu_color_highlight=3Dwhite/blue fi~%" - #$setup-gfxterm-body #$(grub-root-search store-device font-file) #$(setup-gfxterm config font-file) #$(grub-setup-io config) @@ -313,6 +296,9 @@ code." ((? file-system-label? label) (format #f "search --label --set ~a" (file-system-label->string label))) + ((? (lambda (device) + (and (string? device) (string-contains device ":/"))) = nfs-uri) + "set root=3D(tftp)") ((or #f (? string?)) #~(format #f "search --file --set ~a" #$file))))) =20 @@ -358,7 +344,6 @@ when booting a root file system on a Btrfs = subvolume." (menu-entry-device (first all-entries)) (menu-entry-device-mount-point (first all-entries)) #:store-directory-prefix store-directory-prefix - #:system system #:port #~port)) =20 (define keyboard-layout-config @@ -498,11 +483,73 @@ fi~%")))) "--bootloader-id=3DGuix" "--efi-directory" target-esp)))) =20 +(define (install-grub-efi-net subdir) + "Define a grub-efi bootloader installer for installation in SUBDIR, +which is usually \"efi/boot\" or \"efi/Guix\"." + (let* ((arch (car (string-split (or (%current-target-system) + (%current-system)) + #\-))) + (efi-bootloader-link (string-append "/boot" + (match arch + ("i686" "ia32") + ("x86_64" "x64") + ("arm" "arm") + ("armhf" "arm") + ("aarch64" "aa64") + ("riscv" "riscv32") + ("riscv64" "riscv64")) + ".efi")) + (efi-bootloader (string-append (match arch + ("i686" "i386") + ("x86_64" "x86_64") + ("arm" "arm") + ("armhf" "arm") + ("aarch64" "arm64") + ("riscv" "riscv32") + ("riscv64" "riscv64")) + "-efi/core.efi"))) + #~(lambda (bootloader target mount-point) + "Install GRUB as e.g. \"bootx64.efi\" or \"bootarm64.efi\" = \"into +SUBDIR, which is usually \"efi/boot\" or \"efi/Guix\" below the = directory TARGET +for the system whose root is mounted at MOUNT-POINT." + (let* (;; Use target-depth and subdir-depth to construct links = to + ;; "../gnu" and "../../../boot/grub/grub.cfg" with the = correct + ;; number of "../". Note: This doesn't consider ".." or = ".", + ;; which may appear inside target or subdir. + (target-depth (length (delete "" (string-split target = #\/)))) + (subdir-depth (length (delete "" (string-split #$subdir = #\/)))) + (up1 (string-join (make-list target-depth "..") "/" = 'suffix)) + (up2 (string-join (make-list subdir-depth "..") "/" = 'suffix)) + (net-dir (string-append mount-point target "/")) + (store-name (car (delete "" (string-split bootloader = #\/)))) + (store (string-append up1 store-name)) + (store-link (string-append net-dir store-name)) + (grub-cfg (string-append up1 up2 "boot/grub/grub.cfg")) + (grub-cfg-link (string-append net-dir #$subdir = "/grub.cfg")) + (efi-bootloader-link + (string-append net-dir #$subdir = #$efi-bootloader-link))) + ;; Tell 'grub-install' that there might be a LUKS-encrypted = /boot or + ;; root partition. + (setenv "GRUB_ENABLE_CRYPTODISK" "y") + (invoke/quiet (string-append bootloader "/bin/grub-mknetdir") + (string-append "--net-directory=3D" net-dir) + (string-append "--subdir=3D" #$subdir)) + (false-if-exception (delete-file store-link)) + (symlink store store-link) + (false-if-exception (delete-file grub-cfg-link)) + (symlink grub-cfg grub-cfg-link) + (false-if-exception (delete-file efi-bootloader-link)) + (symlink #$efi-bootloader efi-bootloader-link))))) + ^L =20 ;;; ;;; Bootloader definitions. ;;; +;;; For all these grub-bootloader variables the path to = /boot/grub/grub.cfg +;;; is fixed. Inheriting and overwriting the field = 'configuration-file' will +;;; break 'guix system delete-generations', 'guix system = switch-generation', +;;; and 'guix system roll-back'. =20 (define grub-bootloader (bootloader @@ -513,12 +560,12 @@ fi~%")))) (configuration-file "/boot/grub/grub.cfg") (configuration-file-generator grub-configuration-file))) =20 -(define* grub-minimal-bootloader +(define grub-minimal-bootloader (bootloader (inherit grub-bootloader) (package grub-minimal))) =20 -(define* grub-efi-bootloader +(define grub-efi-bootloader (bootloader (inherit grub-bootloader) (installer install-grub-efi) @@ -526,7 +573,13 @@ fi~%")))) (name 'grub-efi) (package grub-efi))) =20 -(define* grub-mkrescue-bootloader +(define grub-efi-net-bootloader + (bootloader + (inherit grub-efi-bootloader) + (name 'grub-efi-net-bootloader) + (installer (install-grub-efi-net "efi/boot")))) + +(define grub-mkrescue-bootloader (bootloader (inherit grub-efi-bootloader) (package grub-hybrid))) diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm index f08bb11514..3a79cfd461 100644 --- a/gnu/build/linux-boot.scm +++ b/gnu/build/linux-boot.scm @@ -503,6 +503,7 @@ upon error." ;; string, but the string can represent a device, a UUID, or a ;; label. So check for all three. (cond ((string-prefix? "/" device-string) device-string) + ((string-contains device-string ":/") device-string) ((uuid device-string) =3D> identity) (else (file-system-label device-string)))) =20 diff --git a/gnu/system.scm b/gnu/system.scm index ac8bbd1d16..91caba7012 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -301,7 +301,8 @@ file system labels." ((? string? device) ;; It used to be that we would not distinguish between labels = and ;; device names. Try to infer the right thing here. - (if (string-prefix? "/dev/" device) + (if (or (string-prefix? "/dev/" device) + (string-contains device ":/")) ; nfs device (file-system-label device))))) =20 --=20 2.26.0