diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2019-07-14 20:50:23 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-05-20 08:30:35 -0400 |
| commit | b460ba7992a0b4af2ddb5927dcf062784539ef7b (patch) | |
| tree | 4d77d01574da9a7aedf31dc3f16e94d82fa31adb /gnu/bootloader | |
| parent | fa35fb58c84d1c1741e4e63c0b37074e35ed2a61 (diff) | |
bootloader: grub: Allow booting from a Btrfs subvolume.
* gnu/bootloader/grub.scm (strip-mount-point): Remove procedure.
(normalize-file): Add procedure.
(grub-configuration-file): New BTRFS-SUBVOLUME-FILE-NAME parameter. When
defined, prepend its value to the kernel and initrd file names, using the
NORMALIZE-FILE procedure. Adjust the call to EYE-CANDY to pass the
BTRFS-SUBVOLUME-FILE-NAME argument. Normalize the KEYMAP file as well.
(eye-candy): Add a BTRFS-SUBVOLUME-FILE-NAME parameter, and use it, along with
the NORMALIZE-FILE procedure, to normalize the FONT-FILE and IMAGE nested
variables. Adjust doc.
* gnu/bootloader/depthcharge.scm (depthcharge-configuration-file): Adapt.
* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Likewise.
* gnu/system/file-systems.scm (btrfs-subvolume?)
(btrfs-store-subvolume-file-name): New procedures.
* gnu/system.scm (operating-system-bootcfg): Specify the Btrfs
subvolume file name the store resides on to the
`operating-system-bootcfg' procedure, using the new
BTRFS-SUBVOLUME-FILE-NAME argument.
* doc/guix.texi (File Systems): Add a Btrfs subsection to document the use of
subvolumes.
* gnu/tests/install.scm (%btrfs-root-on-subvolume-os)
(%btrfs-root-on-subvolume-os-source)
(%btrfs-root-on-subvolume-installation-script)
(%test-btrfs-root-on-subvolume-os): New variables.
Diffstat (limited to 'gnu/bootloader')
| -rw-r--r-- | gnu/bootloader/depthcharge.scm | 3 | ||||
| -rw-r--r-- | gnu/bootloader/extlinux.scm | 3 | ||||
| -rw-r--r-- | gnu/bootloader/grub.scm | 123 |
3 files changed, 80 insertions, 49 deletions
diff --git a/gnu/bootloader/depthcharge.scm b/gnu/bootloader/depthcharge.scm index 58cc3f39322..0a50374bd9b 100644 --- a/gnu/bootloader/depthcharge.scm +++ b/gnu/bootloader/depthcharge.scm | |||
| @@ -82,7 +82,8 @@ | |||
| 82 | (define* (depthcharge-configuration-file config entries | 82 | (define* (depthcharge-configuration-file config entries |
| 83 | #:key | 83 | #:key |
| 84 | (system (%current-system)) | 84 | (system (%current-system)) |
| 85 | (old-entries '())) | 85 | (old-entries '()) |
| 86 | #:allow-other-keys) | ||
| 86 | (match entries | 87 | (match entries |
| 87 | ((entry) | 88 | ((entry) |
| 88 | (let ((kernel (menu-entry-linux entry)) | 89 | (let ((kernel (menu-entry-linux entry)) |
diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm index 5b4dd849656..6b5ff298e74 100644 --- a/gnu/bootloader/extlinux.scm +++ b/gnu/bootloader/extlinux.scm | |||
| @@ -28,7 +28,8 @@ | |||
| 28 | (define* (extlinux-configuration-file config entries | 28 | (define* (extlinux-configuration-file config entries |
| 29 | #:key | 29 | #:key |
| 30 | (system (%current-system)) | 30 | (system (%current-system)) |
| 31 | (old-entries '())) | 31 | (old-entries '()) |
| 32 | #:allow-other-keys) | ||
| 32 | "Return the U-Boot configuration file corresponding to CONFIG, a | 33 | "Return the U-Boot configuration file corresponding to CONFIG, a |
| 33 | <u-boot-configuration> object, and where the store is available at STORE-FS, a | 34 | <u-boot-configuration> object, and where the store is available at STORE-FS, a |
| 34 | <file-system> object. OLD-ENTRIES is taken to be a list of menu entries | 35 | <file-system> object. OLD-ENTRIES is taken to be a list of menu entries |
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index fb871c6e965..bb40c551a74 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm | |||
| @@ -58,18 +58,29 @@ | |||
| 58 | ;;; | 58 | ;;; |
| 59 | ;;; Code: | 59 | ;;; Code: |
| 60 | 60 | ||
| 61 | (define (strip-mount-point mount-point file) | 61 | (define* (normalize-file file mount-point btrfs-subvolume-file-name) |
| 62 | "Strip MOUNT-POINT from FILE, which is a gexp or other lowerable object | 62 | "Strip MOUNT-POINT and prepend BTRFS-SUBVOLUME-FILE-NAME to FILE, a |
| 63 | denoting a file name." | 63 | G-expression or other lowerable object denoting a file name." |
| 64 | (match mount-point | 64 | |
| 65 | ((? string? mount-point) | 65 | (define (strip-mount-point mount-point file) |
| 66 | (if (string=? mount-point "/") | 66 | (if mount-point |
| 67 | file | 67 | (if (string=? mount-point "/") |
| 68 | #~(let ((file #$file)) | 68 | file |
| 69 | (if (string-prefix? #$mount-point file) | 69 | #~(let ((file #$file)) |
| 70 | (substring #$file #$(string-length mount-point)) | 70 | (if (string-prefix? #$mount-point file) |
| 71 | file)))) | 71 | (substring #$file #$(string-length mount-point)) |
| 72 | (#f file))) | 72 | file))) |
| 73 | file)) | ||
| 74 | |||
| 75 | (define (prepend-btrfs-subvolume-file-name btrfs-subvolume-file-name file) | ||
| 76 | (if btrfs-subvolume-file-name | ||
| 77 | #~(string-append #$btrfs-subvolume-file-name #$file) | ||
| 78 | file)) | ||
| 79 | |||
| 80 | (prepend-btrfs-subvolume-file-name btrfs-subvolume-file-name | ||
| 81 | (strip-mount-point mount-point file))) | ||
| 82 | |||
| 83 | |||
| 73 | 84 | ||
| 74 | (define-record-type* <grub-theme> | 85 | (define-record-type* <grub-theme> |
| 75 | ;; Default theme contributed by Felipe López. | 86 | ;; Default theme contributed by Felipe López. |
| @@ -124,13 +135,14 @@ file with the resolution provided in CONFIG." | |||
| 124 | (_ #f))))) | 135 | (_ #f))))) |
| 125 | 136 | ||
| 126 | (define* (eye-candy config store-device store-mount-point | 137 | (define* (eye-candy config store-device store-mount-point |
| 127 | #:key system port) | 138 | #:key btrfs-store-subvolume-file-name system port) |
| 128 | "Return a gexp that writes to PORT (a port-valued gexp) the | 139 | "Return a gexp that writes to PORT (a port-valued gexp) the 'grub.cfg' part |
| 129 | 'grub.cfg' part concerned with graphics mode, background images, colors, and | 140 | concerned with graphics mode, background images, colors, and all that. |
| 130 | all that. STORE-DEVICE designates the device holding the store, and | 141 | STORE-DEVICE designates the device holding the store, and STORE-MOUNT-POINT is |
| 131 | STORE-MOUNT-POINT is its mount point; these are used to determine where the | 142 | its mount point; these are used to determine where the background image and |
| 132 | background image and fonts must be searched for. SYSTEM must be the target | 143 | fonts must be searched for. SYSTEM must be the target system string---e.g., |
| 133 | system string---e.g., \"x86_64-linux\"." | 144 | \"x86_64-linux\". BTRFS-STORE-SUBVOLUME-FILE-NAME is the file name of the |
| 145 | Btrfs subvolume, to be prepended to any store path, if any." | ||
| 134 | (define setup-gfxterm-body | 146 | (define setup-gfxterm-body |
| 135 | (let ((gfxmode | 147 | (let ((gfxmode |
| 136 | (or (and-let* ((theme (bootloader-configuration-theme config)) | 148 | (or (and-let* ((theme (bootloader-configuration-theme config)) |
| @@ -167,11 +179,14 @@ fi~%" #+font-file) | |||
| 167 | (symbol->string (assoc-ref colors 'bg))))) | 179 | (symbol->string (assoc-ref colors 'bg))))) |
| 168 | 180 | ||
| 169 | (define font-file | 181 | (define font-file |
| 170 | (strip-mount-point store-mount-point | 182 | (normalize-file (file-append grub "/share/grub/unicode.pf2") |
| 171 | (file-append grub "/share/grub/unicode.pf2"))) | 183 | store-mount-point |
| 184 | btrfs-store-subvolume-file-name)) | ||
| 172 | 185 | ||
| 173 | (define image | 186 | (define image |
| 174 | (grub-background-image config)) | 187 | (normalize-file (grub-background-image config) |
| 188 | store-mount-point | ||
| 189 | btrfs-store-subvolume-file-name)) | ||
| 175 | 190 | ||
| 176 | (and image | 191 | (and image |
| 177 | #~(format #$port " | 192 | #~(format #$port " |
| @@ -196,7 +211,7 @@ fi~%" | |||
| 196 | #$(setup-gfxterm config font-file) | 211 | #$(setup-gfxterm config font-file) |
| 197 | #$(grub-setup-io config) | 212 | #$(grub-setup-io config) |
| 198 | 213 | ||
| 199 | #$(strip-mount-point store-mount-point image) | 214 | #$image |
| 200 | #$(theme-colors grub-theme-color-normal) | 215 | #$(theme-colors grub-theme-color-normal) |
| 201 | #$(theme-colors grub-theme-color-highlight)))) | 216 | #$(theme-colors grub-theme-color-highlight)))) |
| 202 | 217 | ||
| @@ -304,52 +319,66 @@ code." | |||
| 304 | (define* (grub-configuration-file config entries | 319 | (define* (grub-configuration-file config entries |
| 305 | #:key | 320 | #:key |
| 306 | (system (%current-system)) | 321 | (system (%current-system)) |
| 307 | (old-entries '())) | 322 | (old-entries '()) |
| 323 | btrfs-subvolume-file-name) | ||
| 308 | "Return the GRUB configuration file corresponding to CONFIG, a | 324 | "Return the GRUB configuration file corresponding to CONFIG, a |
| 309 | <bootloader-configuration> object, and where the store is available at | 325 | <bootloader-configuration> object, and where the store is available at |
| 310 | STORE-FS, a <file-system> object. OLD-ENTRIES is taken to be a list of menu | 326 | STORE-FS, a <file-system> object. OLD-ENTRIES is taken to be a list |
| 311 | entries corresponding to old generations of the system." | 327 | of menu entries corresponding to old generations of the system. |
| 328 | BTRFS-SUBVOLUME-FILE-NAME may be used to specify on which subvolume a | ||
| 329 | Btrfs root file system resides." | ||
| 312 | (define all-entries | 330 | (define all-entries |
| 313 | (append entries (bootloader-configuration-menu-entries config))) | 331 | (append entries (bootloader-configuration-menu-entries config))) |
| 314 | (define (menu-entry->gexp entry) | 332 | (define (menu-entry->gexp entry) |
| 315 | (let ((device (menu-entry-device entry)) | 333 | (let* ((device (menu-entry-device entry)) |
| 316 | (device-mount-point (menu-entry-device-mount-point entry)) | 334 | (device-mount-point (menu-entry-device-mount-point entry)) |
| 317 | (label (menu-entry-label entry)) | 335 | (label (menu-entry-label entry)) |
| 318 | (kernel (menu-entry-linux entry)) | 336 | (arguments (menu-entry-linux-arguments entry)) |
| 319 | (arguments (menu-entry-linux-arguments entry)) | 337 | (kernel (normalize-file (menu-entry-linux entry) |
| 320 | (initrd (menu-entry-initrd entry))) | 338 | device-mount-point |
| 339 | btrfs-subvolume-file-name)) | ||
| 340 | (initrd (normalize-file (menu-entry-initrd entry) | ||
| 341 | device-mount-point | ||
| 342 | btrfs-subvolume-file-name))) | ||
| 321 | ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point. | 343 | ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point. |
| 322 | ;; Use the right file names for KERNEL and INITRD in case | 344 | ;; Use the right file names for KERNEL and INITRD in case |
| 323 | ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a | 345 | ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a |
| 324 | ;; separate partition. | 346 | ;; separate partition. |
| 325 | (let ((kernel (strip-mount-point device-mount-point kernel)) | 347 | |
| 326 | (initrd (strip-mount-point device-mount-point initrd))) | 348 | ;; When BTRFS-SUBVOLUME-FILE-NAME is defined, prepend it the kernel and |
| 327 | #~(format port "menuentry ~s { | 349 | ;; initrd paths, to allow booting from a Btrfs subvolume. |
| 350 | #~(format port "menuentry ~s { | ||
| 328 | ~a | 351 | ~a |
| 329 | linux ~a ~a | 352 | linux ~a ~a |
| 330 | initrd ~a | 353 | initrd ~a |
| 331 | }~%" | 354 | }~%" |
| 332 | #$label | 355 | #$label |
| 333 | #$(grub-root-search device kernel) | 356 | #$(grub-root-search device kernel) |
| 334 | #$kernel (string-join (list #$@arguments)) | 357 | #$kernel (string-join (list #$@arguments)) |
| 335 | #$initrd)))) | 358 | #$initrd))) |
| 336 | (define sugar | 359 | (define sugar |
| 337 | (eye-candy config | 360 | (eye-candy config |
| 338 | (menu-entry-device (first all-entries)) | 361 | (menu-entry-device (first all-entries)) |
| 339 | (menu-entry-device-mount-point (first all-entries)) | 362 | (menu-entry-device-mount-point (first all-entries)) |
| 363 | #:btrfs-store-subvolume-file-name btrfs-subvolume-file-name | ||
| 340 | #:system system | 364 | #:system system |
| 341 | #:port #~port)) | 365 | #:port #~port)) |
| 342 | 366 | ||
| 343 | (define keyboard-layout-config | 367 | (define keyboard-layout-config |
| 344 | (let ((layout (bootloader-configuration-keyboard-layout config)) | 368 | (let* ((layout (bootloader-configuration-keyboard-layout config)) |
| 345 | (grub (bootloader-package | 369 | (grub (bootloader-package |
| 346 | (bootloader-configuration-bootloader config)))) | 370 | (bootloader-configuration-bootloader config))) |
| 347 | #~(let ((keymap #$(and layout | 371 | (keymap* (and layout |
| 348 | (keyboard-layout-file layout #:grub grub)))) | 372 | (keyboard-layout-file layout #:grub grub))) |
| 349 | (when keymap | 373 | (keymap (and keymap* |
| 350 | (format port "\ | 374 | (if btrfs-subvolume-file-name |
| 375 | #~(string-append #$btrfs-subvolume-file-name | ||
| 376 | #$keymap*) | ||
| 377 | keymap*)))) | ||
| 378 | #~(when #$keymap | ||
| 379 | (format port "\ | ||
| 351 | insmod keylayouts | 380 | insmod keylayouts |
| 352 | keymap ~a~%" keymap))))) | 381 | keymap ~a~%" #$keymap)))) |
| 353 | 382 | ||
| 354 | (define builder | 383 | (define builder |
| 355 | #~(call-with-output-file #$output | 384 | #~(call-with-output-file #$output |
