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 0LlkG0xvcF9FZQAA0tVLHw (envelope-from ) for ; Sun, 27 Sep 2020 10:54: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 iGdiF0xvcF+JAgAA1q6Kng (envelope-from ) for ; Sun, 27 Sep 2020 10:54: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 E6E569402A6 for ; Sun, 27 Sep 2020 10:54:03 +0000 (UTC) Received: from localhost ([::1]:60566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMUJe-0002AE-GY for larch@yhetil.org; Sun, 27 Sep 2020 06:54:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMUIg-000299-Me for guix-patches@gnu.org; Sun, 27 Sep 2020 06:53:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kMUIg-0005rU-Dm for guix-patches@gnu.org; Sun, 27 Sep 2020 06:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kMUIf-00086U-ST for guix-patches@gnu.org; Sun, 27 Sep 2020 06:53: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: Sun, 27 Sep 2020 10:53:01 +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.160120392731062 (code B ref 41011); Sun, 27 Sep 2020 10:53:01 +0000 Received: (at 41011) by debbugs.gnu.org; 27 Sep 2020 10:52:07 +0000 Received: from localhost ([127.0.0.1]:48452 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kMUHm-00084v-Hw for submit@debbugs.gnu.org; Sun, 27 Sep 2020 06:52:06 -0400 Received: from vsmx012.vodafonemail.xion.oxcs.net ([153.92.174.90]:55178) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kMUHk-00084K-PJ for 41011@debbugs.gnu.org; Sun, 27 Sep 2020 06:52:05 -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 A9304F35030; Sun, 27 Sep 2020 10:51:58 +0000 (UTC) Received: from macbook-pro.kuh-wiese.my-router.de (unknown [2.206.141.21]) by mta-8-out.mta.xion.oxcs.net (Postfix) with ESMTPA id 1E2C919AEAD; Sun, 27 Sep 2020 10:51:52 +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: Date: Sun, 27 Sep 2020 12:51:51 +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> <2A23E912-6919-4A4A-A4CC-0C5FB1A5D5C1@vodafonemail.de> <066A5D57-B0B1-4FF4-B07B-1A5030AA789F@vodafonemail.de> <20200926181357.1aa2faa4@scratchpost.org> 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: SeO75T+Ge5q6 * 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 | 114 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index f69bf8ed4d..516a7d48c8 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,99 @@ 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))) + (core-efi (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 MOUNT-POINT/TARGET/SUBDIR/grub.cfg to +MOUNT-POINT/boot/grub/grub.cfg, and the second symlink points = relatively from +MOUNT-POINT/TARGET/%store-prefix to MOUNT-POINT/%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 (string-append mount-point (%store-prefix))) + (store-link (string-append net-dir (%store-prefix))) + (grub-cfg (string-append mount-point = "/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 store-link) + ;; Prepare the symlink to the grub.cfg, which points into = the store. + (mkdir-p (dirname grub-cfg-link)) + (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 core.efi = of GRUB. + (false-if-exception (delete-file boot-efi-link)) + (symlink #$core-efi boot-efi-link)))))) + ^L =20 ;;; @@ -560,6 +660,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