From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id MGfuMyRGZl8FKAAA0tVLHw (envelope-from ) for ; Sat, 19 Sep 2020 17:55:48 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mI7MLyRGZl8VKAAAbx9fmQ (envelope-from ) for ; Sat, 19 Sep 2020 17:55:48 +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 30B7D9402B0 for ; Sat, 19 Sep 2020 17:55:48 +0000 (UTC) Received: from localhost ([::1]:49500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJh5O-0005im-VB for larch@yhetil.org; Sat, 19 Sep 2020 13:55:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJh4i-0005iM-G7 for guix-patches@gnu.org; Sat, 19 Sep 2020 13:55:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36513) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJh4g-0004B3-Pd for guix-patches@gnu.org; Sat, 19 Sep 2020 13:55:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kJh4g-0002XJ-PC for guix-patches@gnu.org; Sat, 19 Sep 2020 13:55:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41011] [PATCH] gnu: grub: Support for network boot via TFTP. Resent-From: Stefan Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 19 Sep 2020 17:55: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: Danny Milosavljevic Cc: 41011@debbugs.gnu.org, Efraim Flashner Received: via spool by 41011-submit@debbugs.gnu.org id=B41011.16005380759698 (code B ref 41011); Sat, 19 Sep 2020 17:55:02 +0000 Received: (at 41011) by debbugs.gnu.org; 19 Sep 2020 17:54:35 +0000 Received: from localhost ([127.0.0.1]:48057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJh4F-0002WL-55 for submit@debbugs.gnu.org; Sat, 19 Sep 2020 13:54:35 -0400 Received: from mx009.vodafonemail.xion.oxcs.net ([153.92.174.39]:51300) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJh4A-0002Vp-QG for 41011@debbugs.gnu.org; Sat, 19 Sep 2020 13:54:34 -0400 Received: from vsmx002.vodafonemail.xion.oxcs.net (unknown [192.168.75.192]) by mta-6-out.mta.xion.oxcs.net (Postfix) with ESMTP id 46E1C6048DB; Sat, 19 Sep 2020 17:54:24 +0000 (UTC) Received: from macbook-pro.kuh-wiese.my-router.de (unknown [2.206.141.21]) by mta-6-out.mta.xion.oxcs.net (Postfix) with ESMTPA id 85ACE6047C9; Sat, 19 Sep 2020 17:54:17 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) From: Stefan In-Reply-To: <20200916075117.GE19874@E5400> Date: Sat, 19 Sep 2020 19:54:16 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <5C85E809-92D7-48F2-A8E2-2DF57460A6D9@vodafonemail.de> References: <9AAFEFF4-8ACE-4C95-975F-67C3F4FDAF81@vodafonemail.de> <20200906163559.1b56c36f@scratchpost.org> <45F0D825-F888-42E9-BDAE-7BB6FA010A6E@vodafonemail.de> <20200909003732.5c401932@scratchpost.org> <20200914065911.GB1717@E5400> <20200916075117.GE19874@E5400> X-Mailer: Apple Mail (2.3124) X-VADE-STATUS: LEGIT X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) 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.51 X-TUID: d2+EMB+zNpbb * gnu/bootloader/grub.scm (grub-efi-netboot-bootloader): New bootloader = for network booting. (install-grub-efi-netboot): New bootloader installer for network = booting. (grub-root-search): Set the root to "(tftp)" if the searched file is not = stored on a local devices, i.e. an NFS share. --- gnu/bootloader/grub.scm | 106 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index e3febeefd0..211c314f4d 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -23,8 +23,10 @@ ;;; along with GNU Guix. If not, see . =20 (define-module (gnu bootloader grub) + #:use-module (guix build union) #:use-module (guix records) - #:use-module ((guix utils) #:select (%current-system)) + #:use-module (guix store) + #:use-module (guix utils) #:use-module (guix gexp) #:use-module (gnu artwork) #:use-module (gnu bootloader) @@ -46,8 +48,11 @@ grub-theme-color-highlight grub-theme-gfxmode =20 + install-grub-efi-netboot + grub-bootloader grub-efi-bootloader + grub-efi-netboot-bootloader grub-mkrescue-bootloader grub-minimal-bootloader =20 @@ -295,6 +300,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 @@ -501,6 +509,96 @@ fi~%")))) "--bootloader-id=3DGuix" "--efi-directory" target-esp)))) =20 +(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." + (let* ((system (string-split (nix-system->gnu-triplet + (or (%current-target-system) + (%current-system))) + #\-)) + (arch (first system)) + (boot-efi-link (match system + ;; These are the supportend systems and the = names + ;; defined by the UEFI standard for removable = media. + (("i686" _ ...) "/bootia32.efi") + (("x86_64" _ ...) "/bootx64.efi") + (("arm" _ ...) "/bootarm.efi") + (("aarch64" _ ...) "/bootaa64.efi") + (("riscv" _ ...) "/bootriscv32.efi") + (("riscv64" _ ...) "/bootriscv64.efi") + ;; Other systems are not supported, although = defined. + ;; (("riscv128" _ ...) "/bootriscv128.efi") + ;; (("ia64" _ ...) "/bootia64.efi") + ((_ ...) #f))) + (efi-bootloader (string-append + ;; This is the arch dependent file name of = GRUB, e.g. + ;; i368-efi/core.efi or arm64-efi/core.efi. + (match arch + ("i686" "i386") + ("aarch64" "arm64") + ("riscv" "riscv32") + (_ arch)) + "-efi/core.efi"))) + (with-imported-modules + '((guix build union)) + #~(lambda (bootloader target mount-point) + "Install the BOOTLOADER, which must be the package grub, as = e.g. +bootx64.efi or bootaa64.efi into SUBDIR, which is usually efi/Guix or = efi/boot, +below the directory TARGET for the system whose root is mounted at = MOUNT-POINT. + +MOUNT-POINT is the last argument in 'guix system init /etc/config.scm = mnt/point' +or '/' for other 'guix system' commands. + +TARGET is the target argument given to the bootloader-configuration in + +(operating-system + (bootloader (bootloader-configuration + (target \"/boot\") + =E2=80=A6)) + =E2=80=A6) + +TARGET is required to be an absolute directory name, usually mounted = via NFS, +and finally needs to be provided by a TFTP server as the TFTP root = directory. + +GRUB will load tftp://server/SUBDIR/grub.cfg and this file will = instruct it to +load more files from the store like = tftp://server/gnu/store/=E2=80=A6-linux=E2=80=A6/Image. + +To make this possible two symlinks will be created. The first symlink = points +relatively form TARGET/SUBDIR/grub.cfg to /boot/grub/grub.cfg. And the = second +symlink points relatively from TARGET/%store-prefix to %store-prefix. + +It is important to note that these symlinks need to be relativ, as the = absolute +paths on the TFTP server side are unknown. + +It is also important to note that both symlinks will point outside the = TFTP root +directory and that the TARGET/%store-prefix symlink makes the whole = store +accessible via TFTP. Possibly the TFTP server must be configured +to allow accesses outside its TFTP root directory. This may need to be +considered for security aspects." + (use-modules ((guix build union) #:select (symlink-relative))) + (let* ((net-dir (string-append mount-point target "/")) + (sub-dir (string-append net-dir #$subdir "/")) + (store-link (string-append net-dir (%store-prefix))) + (grub-cfg "/boot/grub/grub.cfg") + (grub-cfg-link (string-append sub-dir (basename = grub-cfg))) + (boot-efi-link (string-append sub-dir = #$boot-efi-link))) + ;; Prepare the symlink to the store. + (mkdir-p (dirname store-link)) + (false-if-exception (delete-file store-link)) + (symlink-relative (%store-prefix) store-link) + ;; Prepare the symlink to the grub.cfg, which points into = the store. + (false-if-exception (delete-file grub-cfg-link)) + (symlink-relative grub-cfg grub-cfg-link) + ;; Install GRUB, which refers to the grub.cfg, with support = for + ;; encrypted partitions, + (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)) + ;; Prepare the bootloader symlink, which points to GRUB. + (false-if-exception (delete-file boot-efi-link)) + (symlink #$efi-bootloader boot-efi-link)))))) + ^L =20 ;;; @@ -533,6 +631,12 @@ fi~%")))) (name 'grub-efi) (package grub-efi))) =20 +(define grub-efi-netboot-bootloader + (bootloader + (inherit grub-efi-bootloader) + (name 'grub-efi-netboot-bootloader) + (installer (install-grub-efi-netboot "efi/Guix")))) + (define grub-mkrescue-bootloader (bootloader (inherit grub-efi-bootloader) --=20 2.26.0