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 eKxLA/oUX1+pTwAA0tVLHw (envelope-from ) for ; Mon, 14 Sep 2020 07:00:10 +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 MEsoOfkUX19+XwAAbx9fmQ (envelope-from ) for ; Mon, 14 Sep 2020 07:00:09 +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 205E8940776 for ; Mon, 14 Sep 2020 07:00:09 +0000 (UTC) Received: from localhost ([::1]:52950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHiT8-0008NW-9l for larch@yhetil.org; Mon, 14 Sep 2020 03:00:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHiT4-0008NI-DE for guix-patches@gnu.org; Mon, 14 Sep 2020 03:00:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHiT3-0008Eg-Un for guix-patches@gnu.org; Mon, 14 Sep 2020 03:00:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kHiT3-0001Aw-QG for guix-patches@gnu.org; Mon, 14 Sep 2020 03:00:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41011] [PATCH] gnu: grub: Support for network boot via TFTP. Resent-From: Efraim Flashner Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 14 Sep 2020 07:00: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: Stefan Cc: Danny Milosavljevic , 41011@debbugs.gnu.org Received: via spool by 41011-submit@debbugs.gnu.org id=B41011.16000667934479 (code B ref 41011); Mon, 14 Sep 2020 07:00:01 +0000 Received: (at 41011) by debbugs.gnu.org; 14 Sep 2020 06:59:53 +0000 Received: from localhost ([127.0.0.1]:52342 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kHiSu-0001A9-Tl for submit@debbugs.gnu.org; Mon, 14 Sep 2020 02:59:53 -0400 Received: from flashner.co.il ([178.62.234.194]:45072) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kHiSs-00019v-Ne for 41011@debbugs.gnu.org; Mon, 14 Sep 2020 02:59:51 -0400 Received: from localhost (unknown [31.210.181.177]) by flashner.co.il (Postfix) with ESMTPSA id F045B4026E; Mon, 14 Sep 2020 06:59:43 +0000 (UTC) Date: Mon, 14 Sep 2020 09:59:11 +0300 From: Efraim Flashner Message-ID: <20200914065911.GB1717@E5400> References: <9AAFEFF4-8ACE-4C95-975F-67C3F4FDAF81@vodafonemail.de> <20200906163559.1b56c36f@scratchpost.org> <45F0D825-F888-42E9-BDAE-7BB6FA010A6E@vodafonemail.de> <20200909003732.5c401932@scratchpost.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="WhfpMioaduB5tiZL" Content-Disposition: inline In-Reply-To: X-PGP-Key-ID: 0x41AAE7DCCA3D8351 X-PGP-Key: https://flashner.co.il/~efraim/efraim_flashner.asc X-PGP-Fingerprint: A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.0 (-) 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: -2.61 X-TUID: z/ieEXXOhe1q --WhfpMioaduB5tiZL Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Sep 13, 2020 at 07:46:01PM +0200, Stefan wrote: > * gnu/bootloader/grub.scm (grub-efi-netboot-bootloader): New bootloader f= or > 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(-) >=20 > 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-s= ystem)) > #: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 SU= BDIR, > +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"))) Don't forget the fall-through case, even if it's just ((_ ...) "/bootTODO.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-ef= i")) > + "/core.efi"))) With the fall-through case here, can this be changed to (("i686" _ ...) "i386-efi") (("aarch64" _ ...) "arm64-efi") (("riscv" _ ...) "riscv32-efi") ((_ ...) (string-append (first (string-split (nix-system->gnu-triplet (or (%current-system) (%current-target-system))) #\_)) "-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 e= fi/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 mn= t/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-li= nux=E2=80=A6/Image. > + > +To make this possible two symlinks will be created. The first symlink po= ints > +relatively form TARGET/SUBDIR/grub.cfg to /boot/grub/grub.cfg. And the s= econd > +symlink points relatively from TARGET/%store-prefix to %store-prefix. > + > +It is important to note that these symlinks need to be relativ, as the a= bsolute > +paths on the TFTP server side are unknown. > + > +It is also important to note that both symlinks will point outside the T= FTP 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 f= or > + ;; 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 >=20 >=20 >=20 >=20 --=20 Efraim Flashner =D7=90=D7=A4=D7=A8=D7=99=D7=9D = =D7=A4=D7=9C=D7=A9=D7=A0=D7=A8 GPG key =3D A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted --WhfpMioaduB5tiZL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAl9fFLwACgkQQarn3Mo9 g1EzNRAAko3gKkTrjuf5KM09R8v9c9AsYdYwcItQJlT661CLbKwb4okLv3Hf9qNT BuKdEwnYfz0AVaELTLrWZlJ5GA8u+k7d4b2WOFCiWwI3jEzKjSboQ3f5ZaA6lRiA pjTzVP3Mjbhy4YgClp/2ZxJ/rAfE0thaDaNzQt7RMKpxqqLcyLHD3KC7q7MCST8b N7Tf1CXz25qV3QvKSc2hJRmj7ts1IOI8J06OoHfzir5VGm4JWpEjGrmkGaKcT84j QIYArNKdZ+m1TeBPUDRJIBwgAmuS2fm5ZzWIhmfpVROPnLmge1Gq0qdfTonm7p9f 0Swn1+NwJrwxImkcFJsK5KWQz9WYHilvS/KcOyPbwGFXsIFBUA3GqDwMBIGBTRuH GFModEsnit6eNrTmxSeShkPAIifc2zPcYAMEiPfwanYXg1S9IyDLVpgNrC9w0glT gY99OPsxV5dcTEHYvmbZ4QoUM1M19NIDbcWNkBkNdO/cF5nAoyqA+/ac06aNfkjM q8t2m04W4VhH2NXGVZLozfkDD8WUQD9mAQH7LxCn9lZSUs5kq7kfKI0G2OtxNkb2 6KYTXljurDSg6J853Rro1etTFdW95GVS71ElTrxglZgnoQ4zhnwMPeK9otmpZImI RyCCUeA/FiAvV5/PPsyuqeLBpr+tauQpPlHnjehN6afXcqma1Dg= =fG1h -----END PGP SIGNATURE----- --WhfpMioaduB5tiZL--