Hello Ludovic,

l...@gnu.org (Ludovic Courtès) writes:

> Oleg Pykhalov <go.wig...@gmail.com> skribis:

[...]

>> Are linux linux-arguments initrd in menu-entry required?
>
> Currently yes: this is how you tell GRUB what to boot.

I see an issue with it, because not always you want them.

>> Maybe we could have configfile field?
>> https://www.gnu.org/software/grub/manual/grub/html_node/configfile.html
>
> Yes, we could do that.  One question is how to integrated properly since
> ‘menu-entry’ is now bootloader-independent.  Perhaps Mathieu or Danny
> have ideas?

We could start by adding a way to add anything.  Here is a patch.
Probably ugly, but as a draft and idea about additional-options.

From 7d7162a8ec78c84e7eba3ae9f7c4fbf07703617e Mon Sep 17 00:00:00 2001
From: Oleg Pykhalov <go.wig...@gmail.com>
Date: Thu, 1 Feb 2018 08:59:30 +0300
Subject: [PATCH] bootloader: Add additional-options to menu-entry.

* gnu/bootloader.scm (<menu-entry>)[additional-options]: New field.
* gnu/bootloader/grub.scm (grub-configuration-file): Handle this.
---
 gnu/bootloader.scm      | 19 +++++++++++--------
 gnu/bootloader/grub.scm | 27 +++++++++++++++++++--------
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm
index 736f11952..9a3c29a88 100644
--- a/gnu/bootloader.scm
+++ b/gnu/bootloader.scm
@@ -31,6 +31,7 @@
             menu-entry-linux-arguments
             menu-entry-initrd
             menu-entry-device-mount-point
+            menu-entry-additional-options
 
             bootloader
             bootloader?
@@ -65,15 +66,17 @@
 (define-record-type* <menu-entry>
   menu-entry make-menu-entry
   menu-entry?
-  (label           menu-entry-label)
-  (device          menu-entry-device       ; file system uuid, label, or #f
-                   (default #f))
+  (label              menu-entry-label)
+  (device             menu-entry-device      ; file system uuid, label, or #f
+                      (default #f))
   (device-mount-point menu-entry-device-mount-point
-                   (default #f))
-  (linux           menu-entry-linux)
-  (linux-arguments menu-entry-linux-arguments
-                   (default '()))          ; list of string-valued gexps
-  (initrd          menu-entry-initrd))     ; file name of the initrd as a gexp
+                      (default #f))
+  (linux              menu-entry-linux)
+  (linux-arguments    menu-entry-linux-arguments
+                      (default '()))         ; list of string-valued gexps
+  (initrd             menu-entry-initrd)     ; file name of the initrd as a gexp
+  (additional-options menu-entry-additional-options
+                      (default '())))        ; list of string-valued gexps
 

 ;;;
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 96e53c5c2..7613c2a84 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -324,22 +324,33 @@ entries corresponding to old generations of the system."
           (label (menu-entry-label entry))
           (kernel (menu-entry-linux entry))
           (arguments (menu-entry-linux-arguments entry))
-          (initrd (menu-entry-initrd entry)))
+          (initrd (menu-entry-initrd entry))
+          (additional-options (menu-entry-additional-options entry)))
       ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point.
       ;; Use the right file names for KERNEL and INITRD in case
       ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a
       ;; separate partition.
-      (let ((kernel  (strip-mount-point device-mount-point kernel))
-            (initrd  (strip-mount-point device-mount-point initrd)))
-        #~(format port "menuentry ~s {
+      (if (and (file-append? kernel) (file-append? initrd))
+          (let ((kernel  (strip-mount-point device-mount-point kernel))
+                (initrd  (strip-mount-point device-mount-point initrd)))
+            #~(format port "menuentry ~s {
   ~a
   linux ~a ~a
   initrd ~a
+  ~a
+}~%"
+                      #$label
+                      #$(grub-root-search device kernel)
+                      #$kernel (string-join (list #$@arguments))
+                      #$initrd
+                      (string-join (list #$@additional-options) "\n")))
+          #~(format port "menuentry ~s {
+  ~a
+  ~a
 }~%"
-                  #$label
-                  #$(grub-root-search device kernel)
-                  #$kernel (string-join (list #$@arguments))
-                  #$initrd))))
+                    #$label
+                    #$(grub-root-search device kernel)
+                    (string-join (list #$@additional-options) "\n")))))
   (mlet %store-monad ((sugar (eye-candy config
                                         (menu-entry-device
                                          (first all-entries))
-- 
2.15.1

Which allows to use additional-options in menu-entry:
--8<---------------cut here---------------start------------->8---
(operating-system
…
 (bootloader
  (bootloader-configuration
   (bootloader grub-efi-bootloader)
   (target "/boot/efi")
   (menu-entries
    (list (menu-entry
           (label "Another distro")
           (linux "")
           (initrd "")
           (additional-options '("search --label --set another-disk-label"
                                 "configfile /boot/grub/grub.cfg")))))))
…)
--8<---------------cut here---------------end--------------->8---

Will produce the following Grub menuentry:
--8<---------------cut here---------------start------------->8---
menuentry "Another distro" {
  
  search --label --set another-disk-label
configfile /boot/grub/grub.cfg
}
--8<---------------cut here---------------end--------------->8---

I successfully reconfigured and dualbooted with attached patch.

Oleg.

Attachment: signature.asc
Description: PGP signature

Reply via email to