From: Stefan <stefan-guix@vodafonemail.de>
To: Mathieu Othacehe <othacehe@gnu.org>
Cc: 41011@debbugs.gnu.org
Subject: [bug#41011] [PATCH] gnu: grub: Support for network boot via tftp/nfs.
Date: Sat, 6 Jun 2020 15:33:26 +0200 [thread overview]
Message-ID: <CA441935-DB65-4DF8-BB7F-844B541BB554@vodafonemail.de> (raw)
In-Reply-To: <CE315407-AD1A-45A8-A232-FC1512C4569E@vodafonemail.de>
* gnu/bootloader/grub.scm (grub-efi-net-bootloader): New efi bootloader for
network booting via tftp/nfs.
(install-grub-efi-net): New bootloader installer for tftp.
(grub-root-search): Adding support for tftp root.
(eye-candy): Use 'gfxterm' for all systems if selected via 'terminal-outputs'.
* gnu/system.scm (read-boot-parameters): Prevent devices with ":/" from being
treated as a file system label.
* gnu/build/linux-boot.scm (device-string->file-system-device): Prevent devices
with ":/" from being treated as a file system label.
---
gnu/bootloader/grub.scm | 127 +++++++++++++++++++++++++++------------
gnu/build/linux-boot.scm | 1 +
gnu/system.scm | 3 +-
3 files changed, 93 insertions(+), 38 deletions(-)
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 2d9a39afc3..60b3a12037 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -23,7 +23,7 @@
(define-module (gnu bootloader grub)
#:use-module (guix records)
- #:use-module ((guix utils) #:select (%current-system))
+ #:use-module ((guix utils) #:select (%current-system %current-target-system))
#:use-module (guix gexp)
#:use-module (gnu artwork)
#:use-module (gnu bootloader)
@@ -47,6 +47,8 @@
grub-bootloader
grub-efi-bootloader
+ make-grub-efi-net-bootloader
+ grub-efi-net-bootloader
grub-mkrescue-bootloader
grub-minimal-bootloader
@@ -135,41 +137,25 @@ file with the resolution provided in CONFIG."
(_ #f)))))
(define* (eye-candy config store-device store-mount-point
- #:key store-directory-prefix system port)
+ #:key store-directory-prefix port)
"Return a gexp that writes to PORT (a port-valued gexp) the 'grub.cfg' part
concerned with graphics mode, background images, colors, and all that.
STORE-DEVICE designates the device holding the store, and STORE-MOUNT-POINT is
its mount point; these are used to determine where the background image and
-fonts must be searched for. SYSTEM must be the target system string---e.g.,
-\"x86_64-linux\". STORE-DIRECTORY-PREFIX is a directory prefix to prepend to
-any store file name."
- (define setup-gfxterm-body
- (let ((gfxmode
- (or (and-let* ((theme (bootloader-configuration-theme config))
- (gfxmode (grub-theme-gfxmode theme)))
- (string-join gfxmode ";"))
- "auto")))
-
- ;; Intel and EFI systems need to be switched into graphics mode, whereas
- ;; most other modern architectures have no other mode and therefore
- ;; don't need to be switched.
-
- ;; XXX: Do we really need to restrict to x86 systems? We could imitate
- ;; what the GRUB default configuration does and decide based on whether
- ;; a user provided 'gfxterm' in the terminal-outputs field of their
- ;; bootloader-configuration record.
- (if (string-match "^(x86_64|i[3-6]86)-" system)
- (format #f "
- set gfxmode=~a
- insmod all_video
- insmod gfxterm~%" gfxmode)
- "")))
-
+fonts must be searched for. STORE-DIRECTORY-PREFIX is a directory prefix to
+prepend to any store file name."
(define (setup-gfxterm config font-file)
(if (memq 'gfxterm (bootloader-configuration-terminal-outputs config))
- #~(format #f "if loadfont ~a; then
- setup_gfxterm
-fi~%" #+font-file)
+ #~(format #f "
+if loadfont ~a; then
+ set gfxmode=~a
+ insmod all_video
+ insmod gfxterm
+fi~%"
+ #$font-file
+ #$(string-join
+ (grub-theme-gfxmode (bootloader-theme config))
+ ";"))
""))
(define (theme-colors type)
@@ -190,8 +176,6 @@ fi~%" #+font-file)
(and image
#~(format #$port "
-function setup_gfxterm {~a}
-
# Set 'root' to the partition that contains /gnu/store.
~a
@@ -206,7 +190,6 @@ else
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
fi~%"
- #$setup-gfxterm-body
#$(grub-root-search store-device font-file)
#$(setup-gfxterm config font-file)
#$(grub-setup-io config)
@@ -313,6 +296,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=(tftp)")
((or #f (? string?))
#~(format #f "search --file --set ~a" #$file)))))
@@ -358,7 +344,6 @@ when booting a root file system on a Btrfs subvolume."
(menu-entry-device (first all-entries))
(menu-entry-device-mount-point (first all-entries))
#:store-directory-prefix store-directory-prefix
- #:system system
#:port #~port))
(define keyboard-layout-config
@@ -498,11 +483,73 @@ fi~%"))))
"--bootloader-id=Guix"
"--efi-directory" target-esp))))
+(define (install-grub-efi-net subdir)
+ "Define a grub-efi bootloader installer for installation in SUBDIR,
+which is usually \"efi/boot\" or \"efi/Guix\"."
+ (let* ((arch (car (string-split (or (%current-target-system)
+ (%current-system))
+ #\-)))
+ (efi-bootloader-link (string-append "/boot"
+ (match arch
+ ("i686" "ia32")
+ ("x86_64" "x64")
+ ("arm" "arm")
+ ("armhf" "arm")
+ ("aarch64" "aa64")
+ ("riscv" "riscv32")
+ ("riscv64" "riscv64"))
+ ".efi"))
+ (efi-bootloader (string-append (match arch
+ ("i686" "i386")
+ ("x86_64" "x86_64")
+ ("arm" "arm")
+ ("armhf" "arm")
+ ("aarch64" "arm64")
+ ("riscv" "riscv32")
+ ("riscv64" "riscv64"))
+ "-efi/core.efi")))
+ #~(lambda (bootloader target mount-point)
+ "Install GRUB as e.g. \"bootx64.efi\" or \"bootarm64.efi\" \"into
+SUBDIR, which is usually \"efi/boot\" or \"efi/Guix\" below the directory TARGET
+for the system whose root is mounted at MOUNT-POINT."
+ (let* (;; Use target-depth and subdir-depth to construct links to
+ ;; "../gnu" and "../../../boot/grub/grub.cfg" with the correct
+ ;; number of "../". Note: This doesn't consider ".." or ".",
+ ;; which may appear inside target or subdir.
+ (target-depth (length (delete "" (string-split target #\/))))
+ (subdir-depth (length (delete "" (string-split #$subdir #\/))))
+ (up1 (string-join (make-list target-depth "..") "/" 'suffix))
+ (up2 (string-join (make-list subdir-depth "..") "/" 'suffix))
+ (net-dir (string-append mount-point target "/"))
+ (store-name (car (delete "" (string-split bootloader #\/))))
+ (store (string-append up1 store-name))
+ (store-link (string-append net-dir store-name))
+ (grub-cfg (string-append up1 up2 "boot/grub/grub.cfg"))
+ (grub-cfg-link (string-append net-dir #$subdir "/grub.cfg"))
+ (efi-bootloader-link
+ (string-append net-dir #$subdir #$efi-bootloader-link)))
+ ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
+ ;; root partition.
+ (setenv "GRUB_ENABLE_CRYPTODISK" "y")
+ (invoke/quiet (string-append bootloader "/bin/grub-mknetdir")
+ (string-append "--net-directory=" net-dir)
+ (string-append "--subdir=" #$subdir))
+ (false-if-exception (delete-file store-link))
+ (symlink store store-link)
+ (false-if-exception (delete-file grub-cfg-link))
+ (symlink grub-cfg grub-cfg-link)
+ (false-if-exception (delete-file efi-bootloader-link))
+ (symlink #$efi-bootloader efi-bootloader-link)))))
+
^L
;;;
;;; Bootloader definitions.
;;;
+;;; For all these grub-bootloader variables the path to /boot/grub/grub.cfg
+;;; is fixed. Inheriting and overwriting the field 'configuration-file' will
+;;; break 'guix system delete-generations', 'guix system switch-generation',
+;;; and 'guix system roll-back'.
(define grub-bootloader
(bootloader
@@ -513,12 +560,12 @@ fi~%"))))
(configuration-file "/boot/grub/grub.cfg")
(configuration-file-generator grub-configuration-file)))
-(define* grub-minimal-bootloader
+(define grub-minimal-bootloader
(bootloader
(inherit grub-bootloader)
(package grub-minimal)))
-(define* grub-efi-bootloader
+(define grub-efi-bootloader
(bootloader
(inherit grub-bootloader)
(installer install-grub-efi)
@@ -526,7 +573,13 @@ fi~%"))))
(name 'grub-efi)
(package grub-efi)))
-(define* grub-mkrescue-bootloader
+(define grub-efi-net-bootloader
+ (bootloader
+ (inherit grub-efi-bootloader)
+ (name 'grub-efi-net-bootloader)
+ (installer (install-grub-efi-net "efi/boot"))))
+
+(define grub-mkrescue-bootloader
(bootloader
(inherit grub-efi-bootloader)
(package grub-hybrid)))
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index f08bb11514..3a79cfd461 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -503,6 +503,7 @@ upon error."
;; string, but the string can represent a device, a UUID, or a
;; label. So check for all three.
(cond ((string-prefix? "/" device-string) device-string)
+ ((string-contains device-string ":/") device-string)
((uuid device-string) => identity)
(else (file-system-label device-string))))
diff --git a/gnu/system.scm b/gnu/system.scm
index ac8bbd1d16..91caba7012 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -301,7 +301,8 @@ file system labels."
((? string? device)
;; It used to be that we would not distinguish between labels and
;; device names. Try to infer the right thing here.
- (if (string-prefix? "/dev/" device)
+ (if (or (string-prefix? "/dev/" device)
+ (string-contains device ":/")) ; nfs
device
(file-system-label device)))))
--
2.26.0
next prev parent reply other threads:[~2020-06-06 13:34 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-01 20:32 [bug#41011] [PATCH] gnu: grub: Support for network boot via tftp/nfs Stefan
2020-05-10 8:20 ` Mathieu Othacehe
2020-05-10 21:13 ` Stefan
2020-05-18 21:43 ` Stefan
2020-05-21 15:07 ` Stefan
2020-05-21 18:40 ` Stefan
2020-05-23 8:10 ` Mathieu Othacehe
2020-05-24 0:22 ` Stefan
2020-05-23 8:02 ` Mathieu Othacehe
2020-05-24 10:18 ` Stefan
2020-05-24 11:00 ` Danny Milosavljevic
2020-05-24 13:09 ` Stefan
2020-05-24 13:42 ` Danny Milosavljevic
2020-05-24 13:58 ` Danny Milosavljevic
2020-05-24 17:06 ` Stefan
2020-05-24 16:47 ` Stefan
2020-06-06 13:30 ` Stefan
2020-06-06 13:33 ` Stefan [this message]
2020-06-06 17:37 ` Danny Milosavljevic
[not found] ` <46CD97B3-9994-4AB7-AA7D-4DE39AB7A238@vodafonemail.de>
2020-06-09 13:44 ` Danny Milosavljevic
2020-06-09 14:25 ` Stefan
2020-06-11 4:21 ` Maxim Cournoyer
2020-06-11 11:36 ` Stefan
2020-06-11 13:07 ` Maxim Cournoyer
2020-06-11 13:19 ` Danny Milosavljevic
2020-06-12 14:41 ` Stefan
2020-06-14 18:56 ` Maxim Cournoyer
2020-06-11 23:43 ` [bug#41820] [PATCH] file-systems: Add record type <nfs-share> for a file system device Stefan
2020-06-20 13:52 ` Stefan
2020-06-12 0:06 ` [bug#41011] [PATCH] gnu: grub: Support for network boot via tftp/nfs Stefan
2020-06-14 19:09 ` Maxim Cournoyer
2020-06-17 13:12 ` Stefan
2020-09-05 11:25 ` Stefan
2020-09-06 13:07 ` Stefan
2020-09-06 14:35 ` Danny Milosavljevic
2020-09-06 15:14 ` Danny Milosavljevic
2020-09-07 22:59 ` Stefan
2020-09-08 22:37 ` Danny Milosavljevic
2020-09-13 17:46 ` [bug#41011] [PATCH] gnu: grub: Support for network boot via TFTP Stefan
2020-09-14 6:59 ` Efraim Flashner
2020-09-15 20:28 ` Stefan
2020-09-16 7:51 ` Efraim Flashner
2020-09-19 17:54 ` Stefan
2020-09-20 11:47 ` Stefan
2020-09-20 11:56 ` Stefan
2020-09-26 10:52 ` Stefan
2020-09-26 10:54 ` Stefan
2020-09-26 16:13 ` Danny Milosavljevic
2020-09-27 10:50 ` Stefan
2020-09-27 10:51 ` Stefan
2020-09-27 11:47 ` Danny Milosavljevic
2020-09-14 12:34 ` Danny Milosavljevic
2020-09-15 22:10 ` Danny Milosavljevic
2020-09-27 11:57 ` bug#41011: " Stefan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA441935-DB65-4DF8-BB7F-844B541BB554@vodafonemail.de \
--to=stefan-guix@vodafonemail.de \
--cc=41011@debbugs.gnu.org \
--cc=othacehe@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).