system: grub: Allow arbitrary kernel file names in 'menu-entry'.

Fixes <http://bugs.gnu.org/20067>.
Reported by Tomáš Čech <sleep_walker@suse.cz>.

* gnu/system.scm (system-linux-image-file-name)
(operating-system-kernel-file): New procedures.
(operating-system-grub.cfg): Use 'operating-system-kernel-file' for the
'kernel' field of 'menu-entry'.
(operating-system-parameters-file): Likewise for the 'kernel' entry.
(read-boot-parameters): Adjust 'kernel' field so that it contains the
absolute file name of the image.
* gnu/system/grub.scm (grub-configuration-file)[linux-image-name]:
Remove.
[entry->gexp]: Assume LINUX is the absolute file name of the kernel
image.
* doc/guix.texi (GRUB Configuration): Add an example, and adjust
'kernel' field documentation accordingly.
This commit is contained in:
Ludovic Courtès 2016-09-09 23:27:00 +02:00
parent a9e5e92f94
commit 44d5f54e31
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 49 additions and 16 deletions

View file

@ -10622,9 +10622,23 @@ The @code{grub-theme} object describing the theme to use.
@end deftp @end deftp
@cindex dual boot
@cindex boot menu
Should you want to list additional boot menu entries @i{via} the Should you want to list additional boot menu entries @i{via} the
@code{menu-entries} field above, you will need to create them with the @code{menu-entries} field above, you will need to create them with the
@code{menu-entry} form: @code{menu-entry} form. For example, imagine you want to be able to
boot another distro (hard to imagine!), you can define a menu entry
along these lines:
@example
(menu-entry
(label "The Other Distro")
(linux "/boot/old/vmlinux-2.6.32")
(linux-arguments '("root=/dev/sda2"))
(initrd "/boot/old/initrd"))
@end example
Details below.
@deftp {Data Type} menu-entry @deftp {Data Type} menu-entry
The type of an entry in the GRUB boot menu. The type of an entry in the GRUB boot menu.
@ -10635,7 +10649,11 @@ The type of an entry in the GRUB boot menu.
The label to show in the menu---e.g., @code{"GNU"}. The label to show in the menu---e.g., @code{"GNU"}.
@item @code{linux} @item @code{linux}
The Linux kernel to boot. The Linux kernel image to boot, for example:
@example
(file-append linux-libre "/bzImage")
@end example
@item @code{linux-arguments} (default: @code{()}) @item @code{linux-arguments} (default: @code{()})
The list of extra Linux kernel command-line arguments---e.g., The list of extra Linux kernel command-line arguments---e.g.,

View file

@ -69,6 +69,7 @@ (define-module (gnu system)
operating-system-host-name operating-system-host-name
operating-system-hosts-file operating-system-hosts-file
operating-system-kernel operating-system-kernel
operating-system-kernel-file
operating-system-kernel-arguments operating-system-kernel-arguments
operating-system-initrd operating-system-initrd
operating-system-users operating-system-users
@ -246,6 +247,19 @@ (define (swap-services os)
"Return the list of swap services for OS." "Return the list of swap services for OS."
(map swap-service (operating-system-swap-devices os))) (map swap-service (operating-system-swap-devices os)))
(define* (system-linux-image-file-name #:optional (system (%current-system)))
"Return the basename of the kernel image file for SYSTEM."
;; FIXME: Evaluate the conditional based on the actual current system.
(if (string-prefix? "mips" (%current-system))
"vmlinuz"
"bzImage"))
(define (operating-system-kernel-file os)
"Return an object representing the absolute file name of the kernel image of
OS."
(file-append (operating-system-kernel os)
"/" (system-linux-image-file-name os)))
(define* (operating-system-directory-base-entries os #:key container?) (define* (operating-system-directory-base-entries os #:key container?)
"Return the basic entries of the 'system' directory of OS for use as the "Return the basic entries of the 'system' directory of OS for use as the
value of the SYSTEM-SERVICE-TYPE service." value of the SYSTEM-SERVICE-TYPE service."
@ -710,12 +724,13 @@ (define* (operating-system-grub.cfg os #:optional (old-entries '()))
((system (operating-system-derivation os)) ((system (operating-system-derivation os))
(root-fs -> (operating-system-root-file-system os)) (root-fs -> (operating-system-root-file-system os))
(store-fs -> (operating-system-store-file-system os)) (store-fs -> (operating-system-store-file-system os))
(kernel -> (operating-system-kernel os)) (label -> (kernel->grub-label (operating-system-kernel os)))
(kernel -> (operating-system-kernel-file os))
(root-device -> (if (eq? 'uuid (file-system-title root-fs)) (root-device -> (if (eq? 'uuid (file-system-title root-fs))
(uuid->string (file-system-device root-fs)) (uuid->string (file-system-device root-fs))
(file-system-device root-fs))) (file-system-device root-fs)))
(entries -> (list (menu-entry (entries -> (list (menu-entry
(label (kernel->grub-label kernel)) (label label)
(linux kernel) (linux kernel)
(linux-arguments (linux-arguments
(cons* (string-append "--root=" root-device) (cons* (string-append "--root=" root-device)
@ -739,7 +754,7 @@ (define (operating-system-parameters-file os)
#~(boot-parameters (version 0) #~(boot-parameters (version 0)
(label #$label) (label #$label)
(root-device #$(file-system-device root)) (root-device #$(file-system-device root))
(kernel #$(operating-system-kernel os)) (kernel #$(operating-system-kernel-file os))
(kernel-arguments (kernel-arguments
#$(operating-system-kernel-arguments os)) #$(operating-system-kernel-arguments os))
(initrd #$initrd)) (initrd #$initrd))
@ -768,7 +783,14 @@ (define (read-boot-parameters port)
(boot-parameters (boot-parameters
(label label) (label label)
(root-device root) (root-device root)
(kernel linux)
;; In the past, we would store the directory name of the kernel instead
;; of the absolute file name of its image. Detect that and correct it.
(kernel (if (string=? linux (direct-store-path linux))
(string-append linux "/"
(system-linux-image-file-name))
linux))
(kernel-arguments (kernel-arguments
(match (assq 'kernel-arguments rest) (match (assq 'kernel-arguments rest)
((_ args) args) ((_ args) args)

View file

@ -243,11 +243,6 @@ (define* (grub-configuration-file config store-fs entries
<grub-configuration> object, and where the store is available at STORE-FS, a <grub-configuration> object, and where the store is available at STORE-FS, a
<file-system> object. OLD-ENTRIES is taken to be a list of menu entries <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
corresponding to old generations of the system." corresponding to old generations of the system."
(define linux-image-name
(if (string-prefix? "mips" system)
"vmlinuz"
"bzImage"))
(define all-entries (define all-entries
(append entries (grub-configuration-menu-entries config))) (append entries (grub-configuration-menu-entries config)))
@ -256,14 +251,12 @@ (define entry->gexp
(($ <menu-entry> label linux arguments initrd) (($ <menu-entry> label linux arguments initrd)
#~(format port "menuentry ~s { #~(format port "menuentry ~s {
~a ~a
linux ~a/~a ~a linux ~a ~a
initrd ~a initrd ~a
}~%" }~%"
#$label #$label
#$(grub-root-search store-fs #$(grub-root-search store-fs linux)
#~(string-append #$linux "/" #$linux (string-join (list #$@arguments))
#$linux-image-name))
#$linux #$linux-image-name (string-join (list #$@arguments))
#$initrd)))) #$initrd))))
(mlet %store-monad ((sugar (eye-candy config store-fs system #~port))) (mlet %store-monad ((sugar (eye-candy config store-fs system #~port)))