From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KNDMMLBBZ1/nJQAA0tVLHw (envelope-from ) for ; Sun, 20 Sep 2020 11:49:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id cEjPLLBBZ18aWAAA1q6Kng (envelope-from ) for ; Sun, 20 Sep 2020 11:49:04 +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 3501B940148 for ; Sun, 20 Sep 2020 11:49:04 +0000 (UTC) Received: from localhost ([::1]:54220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJxq2-00045s-W1 for larch@yhetil.org; Sun, 20 Sep 2020 07:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJxp6-0003fz-Fn for guix-patches@gnu.org; Sun, 20 Sep 2020 07:48:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJxp5-0000cG-2e for guix-patches@gnu.org; Sun, 20 Sep 2020 07:48:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kJxp5-0002Bm-1m for guix-patches@gnu.org; Sun, 20 Sep 2020 07:48:03 -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: Sun, 20 Sep 2020 11:48:03 +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.16006024728112 (code B ref 41011); Sun, 20 Sep 2020 11:48:03 +0000 Received: (at 41011) by debbugs.gnu.org; 20 Sep 2020 11:47:52 +0000 Received: from localhost ([127.0.0.1]:49041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJxot-00026V-7d for submit@debbugs.gnu.org; Sun, 20 Sep 2020 07:47:51 -0400 Received: from vsmx009.vodafonemail.xion.oxcs.net ([153.92.174.87]:20533) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kJxon-0001yp-EE for 41011@debbugs.gnu.org; Sun, 20 Sep 2020 07:47:46 -0400 Received: from vsmx001.vodafonemail.xion.oxcs.net (unknown [192.168.75.191]) by mta-5-out.mta.xion.oxcs.net (Postfix) with ESMTP id F1766159DAA9; Sun, 20 Sep 2020 11:47:38 +0000 (UTC) Received: from macbook-pro.kuh-wiese.my-router.de (unknown [2.206.141.21]) by mta-5-out.mta.xion.oxcs.net (Postfix) with ESMTPA id 348F3159DB76; Sun, 20 Sep 2020 11:47:32 +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: <5C85E809-92D7-48F2-A8E2-2DF57460A6D9@vodafonemail.de> Date: Sun, 20 Sep 2020 13:47:31 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: 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> <5C85E809-92D7-48F2-A8E2-2DF57460A6D9@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.51 X-TUID: szQP9bWf/oVX * 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 | 111 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index f69bf8ed4d..fe771b2631 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 @@ -297,9 +302,11 @@ code." (file-system-label->string label))) ((? (lambda (device) (and (string? device) (string-contains device ":/"))) = nfs-uri) - ;; This assumes that if your root file system is on NFS, then - ;; you also want to load your grub extra files, kernel and = initrd - ;; from there. + ;; If the device is an NFS share, then we assume that the = expected + ;; file on that device (e.g. the GRUB background image or the = kernel) + ;; has to be loaded over the network. Otherwise we would need = an + ;; additional device information for some local disk to look = for that + ;; file, which we do not have. ;; ;; We explicitly set "root=3D(tftp)" here even though if = grub.cfg ;; had been loaded via TFTP, Grub would have set "root=3D(tftp)"= @@ -528,6 +535,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 ;;; @@ -560,6 +657,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