unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#41011] [PATCH] gnu: grub: Support for network boot via tftp/nfs.
@ 2020-05-01 20:32 Stefan
  2020-05-10  8:20 ` Mathieu Othacehe
                   ` (2 more replies)
  0 siblings, 3 replies; 54+ messages in thread
From: Stefan @ 2020-05-01 20:32 UTC (permalink / raw)
  To: 41011

* gnu/bootloader/grub.scm (grub-efi-net-bootloader): New efi bootloader for
network booting via tftp/nfs and possibly images, prepared for chain loading.
(install-grub-efi-net): New bootloader installer for tftp and possibly images,
does not need root rights.
(grub-root-search): Adding support for tftp root.
(eye-candy): Enable gfxterm support for all systems.
* gnu/system.scm (read-boot-parameters): Prevent devices with ":/" from being
treated as a file system label.
---
 gnu/bootloader/grub.scm | 107 +++++++++++++++++++++++++++++++---------
 gnu/system.scm          |   3 +-
 2 files changed, 86 insertions(+), 24 deletions(-)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 190b717163..9ca4f016f6 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)
@@ -53,6 +53,7 @@
 
             grub-bootloader
             grub-efi-bootloader
+            grub-efi-net-bootloader
             grub-mkrescue-bootloader
 
             grub-configuration))
@@ -142,34 +143,20 @@ WIDTH/HEIGHT, or #f if none was found."
                    #:width width #:height height))))
 
 (define* (eye-candy config store-device store-mount-point
-                    #:key system port)
+                    #:key 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\"."
+background image and fonts must be searched for."
   (define setup-gfxterm-body
-    (let ((gfxmode
-           (or (and-let* ((theme (bootloader-configuration-theme config))
-                          (gfxmode (grub-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 "
+    (format #f "
   set gfxmode=~a
   insmod all_video
-  insmod gfxterm~%" gfxmode)
-          "")))
+  insmod gfxterm~%"
+            (string-join
+             (grub-gfxmode (bootloader-theme config))
+             ";")))
 
   (define (setup-gfxterm config font-file)
     (if (memq 'gfxterm (bootloader-configuration-terminal-outputs config))
@@ -316,6 +303,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)))))
 
@@ -355,7 +345,6 @@ entries corresponding to old generations of the system."
     (eye-candy config
                (menu-entry-device (first all-entries))
                (menu-entry-device-mount-point (first all-entries))
-               #:system system
                #:port #~port))
 
   (define keyboard-layout-config
@@ -443,6 +432,68 @@ fi~%"))))
                       "--bootloader-id=Guix"
                       "--efi-directory" target-esp))))
 
+(define (install-grub-efi-net efi-subdir)
+  "Define a grub-efi bootloader installer for installation in EFI-SUBDIR,
+which is usually \"efi/guix\" or \"efi/boot\"."
+  (let* ((arch (car (string-split (or (%current-target-system)
+                                      (%current-system))
+                                  #\-)))
+         (efi-bootloader-link (string-append "boot"
+                                       (match arch
+                                         ("i686" "ia32")
+                                         ("x86_64" "x64")
+                                         ("armhf" "arm")
+                                         ("aarch64" "aa64")
+                                         ("riscv" "riscv32")
+                                         ("riscv64" "riscv64"))
+                                       ".efi"))
+         (efi-bootloader (string-append (match arch
+                                         ("i686" "i386")
+                                         ("x86_64" "x86_64")
+                                         ("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
+EFI-SUBDIR, which is usually \"efi/guix\" or \"efi/boot\" below the directory
+TARGET for the system whose root is mounted at MOUNT-POINT."
+        (let* ((mount-point-list (delete "" (string-split mount-point #\/)))
+               (target-list (delete "" (string-split target #\/)))
+               (net-dir
+                (string-append "/" (string-join (append
+                                                 mount-point-list
+                                                 target-list)
+                                                "/")))
+               (subdir #$efi-subdir)
+               (efi-bootloader-link
+                (string-append net-dir "/" subdir "/" #$efi-bootloader-link))
+               (store-name (car (delete "" (string-split bootloader #\/))))
+               (store
+                ;; Use target-list to construct a "../gnu" link with a correct
+                ;; number of "../" to the store.
+                (string-join (append (make-list (length target-list) "..")
+                                     (list store-name))
+                             "/"))
+               (store-link (string-append net-dir "/" store-name)))
+          ;; 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))
+          (catch 'system-error
+            (lambda () (delete-file efi-bootloader-link))
+            (lambda _ #f))
+          (symlink #$efi-bootloader
+                   efi-bootloader-link)
+          (catch 'system-error
+            (lambda () (delete-file store-link))
+            (lambda _ #f))
+          (symlink store
+                   store-link)))))
+
 ^L
 
 ;;;
@@ -464,6 +515,16 @@ fi~%"))))
    (name 'grub-efi)
    (package grub-efi)))
 
+(define* (grub-efi-net-bootloader #:key (target #f) (efi-subdir #f))
+  (let ((target (or target "boot"))
+        (efi-subdir (or efi-subdir "efi/boot")))
+    (bootloader
+     (inherit grub-bootloader)
+     (name 'grub-efi-net-bootloader)
+     (package grub-efi)
+     (installer (install-grub-efi-net efi-subdir))
+     (configuration-file (string-append target "/" efi-subdir "/grub.cfg")))))
+
 (define* grub-mkrescue-bootloader
   (bootloader
    (inherit grub-efi-bootloader)
diff --git a/gnu/system.scm b/gnu/system.scm
index 29e622872d..540f0e4a9e 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -297,7 +297,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






^ permalink raw reply related	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2020-09-27 11:59 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).