diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2016-01-21 22:45:54 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2016-01-22 00:02:52 +0100 |
| commit | 6b779207ee627c93fc0dad18ef67c149024fa535 (patch) | |
| tree | 9a4fa6759add87f0bcd943e72bddae960e749a82 /gnu/system | |
| parent | 3738d8700ff84e16bfd8609efbd4db6933b414f1 (diff) | |
system: grub: Search root device by label or UUID if possible.
Fixes <http://bugs.gnu.org/22281>.
Reported by Christopher Allan Webber <cwebber@dustycloud.org>.
* gnu/system/grub.scm (eye-candy): Add 'root-fs' parameter. Replace
'search --file' command in the output with whatever 'grub-root-search'
returns.
(grub-root-search): New procedure.
(grub-configuration-file): Add 'store-fs' parameter. Use
'grub-root-search' instead of hard-coded 'search --file' commands.
* gnu/system.scm (store-file-system,
operating-system-store-file-system): New procedures.
(operating-system-grub.cfg): Use it, and adjust call to
'grub-configuration-file'.
* tests/system.scm: New file.
* Makefile.am (SCM_TESTS): Add it.
Diffstat (limited to 'gnu/system')
| -rw-r--r-- | gnu/system/grub.scm | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm index 5b824820b17..45b46cae6fc 100644 --- a/gnu/system/grub.scm +++ b/gnu/system/grub.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; | 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. | 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; | 5 | ;;; |
| @@ -25,6 +25,7 @@ | |||
| 25 | #:use-module (guix gexp) | 25 | #:use-module (guix gexp) |
| 26 | #:use-module (guix download) | 26 | #:use-module (guix download) |
| 27 | #:use-module (gnu artwork) | 27 | #:use-module (gnu artwork) |
| 28 | #:use-module (gnu system file-systems) | ||
| 28 | #:autoload (gnu packages grub) (grub) | 29 | #:autoload (gnu packages grub) (grub) |
| 29 | #:autoload (gnu packages inkscape) (inkscape) | 30 | #:autoload (gnu packages inkscape) (inkscape) |
| 30 | #:autoload (gnu packages imagemagick) (imagemagick) | 31 | #:autoload (gnu packages imagemagick) (imagemagick) |
| @@ -153,10 +154,12 @@ WIDTH/HEIGHT, or #f if none was found." | |||
| 153 | (with-monad %store-monad | 154 | (with-monad %store-monad |
| 154 | (return #f))))) | 155 | (return #f))))) |
| 155 | 156 | ||
| 156 | (define (eye-candy config system port) | 157 | (define (eye-candy config root-fs system port) |
| 157 | "Return in %STORE-MONAD a gexp that writes to PORT (a port-valued gexp) the | 158 | "Return in %STORE-MONAD a gexp that writes to PORT (a port-valued gexp) the |
| 158 | 'grub.cfg' part concerned with graphics mode, background images, colors, and | 159 | 'grub.cfg' part concerned with graphics mode, background images, colors, and |
| 159 | all that." | 160 | all that. ROOT-FS is a file-system object denoting the root file system where |
| 161 | the store is. SYSTEM must be the target system string---e.g., | ||
| 162 | \"x86_64-linux\"." | ||
| 160 | (define setup-gfxterm-body | 163 | (define setup-gfxterm-body |
| 161 | ;; Intel systems need to be switched into graphics mode, whereas most | 164 | ;; Intel systems need to be switched into graphics mode, whereas most |
| 162 | ;; other modern architectures have no other mode and therefore don't need | 165 | ;; other modern architectures have no other mode and therefore don't need |
| @@ -179,15 +182,18 @@ all that." | |||
| 179 | (string-append (symbol->string (assoc-ref colors 'fg)) "/" | 182 | (string-append (symbol->string (assoc-ref colors 'fg)) "/" |
| 180 | (symbol->string (assoc-ref colors 'bg))))) | 183 | (symbol->string (assoc-ref colors 'bg))))) |
| 181 | 184 | ||
| 185 | (define font-file | ||
| 186 | #~(string-append #$grub "/share/grub/unicode.pf2")) | ||
| 187 | |||
| 182 | (mlet* %store-monad ((image (grub-background-image config))) | 188 | (mlet* %store-monad ((image (grub-background-image config))) |
| 183 | (return (and image | 189 | (return (and image |
| 184 | #~(format #$port " | 190 | #~(format #$port " |
| 185 | function setup_gfxterm {~a} | 191 | function setup_gfxterm {~a} |
| 186 | 192 | ||
| 187 | # Set 'root' to the partition that contains /gnu/store. | 193 | # Set 'root' to the partition that contains /gnu/store. |
| 188 | search --file --set ~a/share/grub/unicode.pf2 | 194 | ~a |
| 189 | 195 | ||
| 190 | if loadfont ~a/share/grub/unicode.pf2; then | 196 | if loadfont ~a; then |
| 191 | setup_gfxterm | 197 | setup_gfxterm |
| 192 | fi | 198 | fi |
| 193 | 199 | ||
| @@ -200,7 +206,9 @@ else | |||
| 200 | set menu_color_highlight=white/blue | 206 | set menu_color_highlight=white/blue |
| 201 | fi~%" | 207 | fi~%" |
| 202 | #$setup-gfxterm-body | 208 | #$setup-gfxterm-body |
| 203 | #$grub #$grub | 209 | #$(grub-root-search root-fs font-file) |
| 210 | #$font-file | ||
| 211 | |||
| 204 | #$image | 212 | #$image |
| 205 | #$(theme-colors grub-theme-color-normal) | 213 | #$(theme-colors grub-theme-color-normal) |
| 206 | #$(theme-colors grub-theme-color-highlight)))))) | 214 | #$(theme-colors grub-theme-color-highlight)))))) |
| @@ -210,13 +218,31 @@ fi~%" | |||
| 210 | ;;; Configuration file. | 218 | ;;; Configuration file. |
| 211 | ;;; | 219 | ;;; |
| 212 | 220 | ||
| 213 | (define* (grub-configuration-file config entries | 221 | (define (grub-root-search root-fs file) |
| 222 | "Return the GRUB 'search' command to look for ROOT-FS, which contains FILE, | ||
| 223 | a gexp. The result is a gexp that can be inserted in the grub.cfg-generation | ||
| 224 | code." | ||
| 225 | (case (file-system-title root-fs) | ||
| 226 | ;; Preferably refer to ROOT-FS by its UUID or label. This is more | ||
| 227 | ;; efficient and less ambiguous, see <>. | ||
| 228 | ((uuid) | ||
| 229 | (format #f "search --fs-uuid --set ~a" | ||
| 230 | (uuid->string (file-system-device root-fs)))) | ||
| 231 | ((label) | ||
| 232 | (format #f "search --label --set ~a" | ||
| 233 | (file-system-device root-fs))) | ||
| 234 | (else | ||
| 235 | ;; As a last resort, look for any device containing FILE. | ||
| 236 | #~(format #f "search --file --set ~a" #$file)))) | ||
| 237 | |||
| 238 | (define* (grub-configuration-file config store-fs entries | ||
| 214 | #:key | 239 | #:key |
| 215 | (system (%current-system)) | 240 | (system (%current-system)) |
| 216 | (old-entries '())) | 241 | (old-entries '())) |
| 217 | "Return the GRUB configuration file corresponding to CONFIG, a | 242 | "Return the GRUB configuration file corresponding to CONFIG, a |
| 218 | <grub-configuration> object. OLD-ENTRIES is taken to be a list of menu | 243 | <grub-configuration> object, and where the store is available at STORE-FS, a |
| 219 | entries corresponding to old generations of the system." | 244 | <file-system> object. OLD-ENTRIES is taken to be a list of menu entries |
| 245 | corresponding to old generations of the system." | ||
| 220 | (define linux-image-name | 246 | (define linux-image-name |
| 221 | (if (string-prefix? "mips" system) | 247 | (if (string-prefix? "mips" system) |
| 222 | "vmlinuz" | 248 | "vmlinuz" |
| @@ -229,18 +255,18 @@ entries corresponding to old generations of the system." | |||
| 229 | (match-lambda | 255 | (match-lambda |
| 230 | (($ <menu-entry> label linux arguments initrd) | 256 | (($ <menu-entry> label linux arguments initrd) |
| 231 | #~(format port "menuentry ~s { | 257 | #~(format port "menuentry ~s { |
| 232 | # Set 'root' to the partition that contains the kernel. | 258 | ~a |
| 233 | search --file --set ~a/~a~% | ||
| 234 | |||
| 235 | linux ~a/~a ~a | 259 | linux ~a/~a ~a |
| 236 | initrd ~a | 260 | initrd ~a |
| 237 | }~%" | 261 | }~%" |
| 238 | #$label | 262 | #$label |
| 239 | #$linux #$linux-image-name | 263 | #$(grub-root-search store-fs |
| 264 | #~(string-append #$linux "/" | ||
| 265 | #$linux-image-name)) | ||
| 240 | #$linux #$linux-image-name (string-join (list #$@arguments)) | 266 | #$linux #$linux-image-name (string-join (list #$@arguments)) |
| 241 | #$initrd)))) | 267 | #$initrd)))) |
| 242 | 268 | ||
| 243 | (mlet %store-monad ((sugar (eye-candy config system #~port))) | 269 | (mlet %store-monad ((sugar (eye-candy config store-fs system #~port))) |
| 244 | (define builder | 270 | (define builder |
| 245 | #~(call-with-output-file #$output | 271 | #~(call-with-output-file #$output |
| 246 | (lambda (port) | 272 | (lambda (port) |
