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 6BuaOR9bXl/aSQAA0tVLHw (envelope-from ) for ; Sun, 13 Sep 2020 17:47:11 +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 ONHqMx9bXl+vIwAAbx9fmQ (envelope-from ) for ; Sun, 13 Sep 2020 17:47:11 +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 3892694060B for ; Sun, 13 Sep 2020 17:47:11 +0000 (UTC) Received: from localhost ([::1]:55888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHW5l-0002l8-Im for larch@yhetil.org; Sun, 13 Sep 2020 13:47:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHW5e-0002kr-JA for guix-patches@gnu.org; Sun, 13 Sep 2020 13:47:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40095) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHW5e-00050v-A0 for guix-patches@gnu.org; Sun, 13 Sep 2020 13:47:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kHW5e-0007B2-79 for guix-patches@gnu.org; Sun, 13 Sep 2020 13:47: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, 13 Sep 2020 17:47: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 Received: via spool by 41011-submit@debbugs.gnu.org id=B41011.160001917827536 (code B ref 41011); Sun, 13 Sep 2020 17:47:02 +0000 Received: (at 41011) by debbugs.gnu.org; 13 Sep 2020 17:46:18 +0000 Received: from localhost ([127.0.0.1]:51641 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kHW4v-0007A3-T6 for submit@debbugs.gnu.org; Sun, 13 Sep 2020 13:46:18 -0400 Received: from vsmx011.vodafonemail.xion.oxcs.net ([153.92.174.89]:36669) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kHW4r-00079m-Ho for 41011@debbugs.gnu.org; Sun, 13 Sep 2020 13:46:16 -0400 Received: from vsmx003.vodafonemail.xion.oxcs.net (unknown [192.168.75.197]) by mta-5-out.mta.xion.oxcs.net (Postfix) with ESMTP id 0A5C559D509; Sun, 13 Sep 2020 17:46:07 +0000 (UTC) Received: from macbook-pro.kuh-wiese.my-router.de (unknown [188.100.45.56]) by mta-7-out.mta.xion.oxcs.net (Postfix) with ESMTPA id A6BA1539D16; Sun, 13 Sep 2020 17:46:02 +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: <20200909003732.5c401932@scratchpost.org> Date: Sun, 13 Sep 2020 19:46:01 +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> 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: 6cXFiHRqYmy1 * 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 | 97 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index e3febeefd0..552bc34f5a 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) #:select (%current-system = %current-target-system)) #: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,87 @@ 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 (or (%current-target-system) + (%current-system)) + #\-)) + (boot-efi-link (match system + (("i686" _ ...) "/bootia32.efi") + (("x86_64" _ ...) "/bootx64.efi") + (("arm" _ ...) "/bootarm.efi") + (("armhf" _ ...) "/bootarm.efi") + (("aarch64" _ ...) "/bootaa64.efi") + (("riscv" _ ...) "/bootriscv32.efi") + (("riscv64" _ ...) "/bootriscv64.efi"))) + (efi-bootloader (string-append (match system + (("i686" _ ...) "i386-efi") + (("x86_64" _ ...) = "x86_64-efi") + (("arm" _ ...) "arm-efi") + (("armhf" _ ...) "arm-efi") + (("aarch64" _ ...) = "arm64-efi") + (("riscv" _ ...) = "riscv32-efi") + (("riscv64" _ ...) = "riscv64-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 bootarm64.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 path and must 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 +622,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