summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnu/bootloader/grub.scm19
-rw-r--r--gnu/build/file-systems.scm58
2 files changed, 71 insertions, 6 deletions
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 2723eda5f4d..ef516b1e13d 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -3,7 +3,7 @@
3;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com> 3;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
4;;; Copyright © 2017 Leo Famulari <leo@famulari.name> 4;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
5;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com> 5;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
6;;; Copyright © 2019, 2020, 2023 Janneke Nieuwenhuizen <janneke@gnu.org> 6;;; Copyright © 2019, 2020, 2023, 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
7;;; Copyright © 2019, 2020 Miguel Ángel Arruga Vivas <rosen644835@gmail.com> 7;;; Copyright © 2019, 2020 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
8;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> 8;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
9;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de> 9;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
@@ -34,6 +34,7 @@
34 #:use-module (guix gexp) 34 #:use-module (guix gexp)
35 #:use-module (gnu artwork) 35 #:use-module (gnu artwork)
36 #:use-module (gnu bootloader) 36 #:use-module (gnu bootloader)
37 #:use-module (gnu build file-systems)
37 #:use-module (gnu system uuid) 38 #:use-module (gnu system uuid)
38 #:use-module (gnu system file-systems) 39 #:use-module (gnu system file-systems)
39 #:use-module (gnu system keyboard) 40 #:use-module (gnu system keyboard)
@@ -45,6 +46,7 @@
45 #:use-module (ice-9 regex) 46 #:use-module (ice-9 regex)
46 #:use-module (srfi srfi-1) 47 #:use-module (srfi srfi-1)
47 #:use-module (srfi srfi-2) 48 #:use-module (srfi srfi-2)
49 #:use-module (srfi srfi-26)
48 #:export (grub-theme 50 #:export (grub-theme
49 grub-theme? 51 grub-theme?
50 grub-theme-image 52 grub-theme-image
@@ -355,6 +357,11 @@ code."
355 ((or #f (? string?)) 357 ((or #f (? string?))
356 #~(format #f "search --file --set ~a" #$file))))) 358 #~(format #f "search --file --set ~a" #$file)))))
357 359
360(define* (device->hurd-device-name device-spec #:key (disk "w"))
361 "Return DEVICE as a Hurd name spec: part:PART-NUMBER:device:DISKdDISK-INDEX."
362 (let ((device-name (canonicalize-device-spec device-spec)))
363 (device-name->hurd-device-name device-name #:disk disk)))
364
358(define* (make-grub-configuration grub config entries 365(define* (make-grub-configuration grub config entries
359 #:key 366 #:key
360 (locale #f) 367 (locale #f)
@@ -413,16 +420,16 @@ when booting a root file system on a Btrfs subvolume."
413 ;; IDE driver ("hdX") and those understood by rumpdisk ("wdX" 420 ;; IDE driver ("hdX") and those understood by rumpdisk ("wdX"
414 ;; in the "noide" case). 421 ;; in the "noide" case).
415 (disk (if (member "noide" arguments) "w" "h")) 422 (disk (if (member "noide" arguments) "w" "h"))
416 (modules (menu-entry-multiboot-modules entry)) 423 (device-spec (and=> device file-system-device->string))
417 (root-index 1)) ; XXX EFI will need root-index 2 424 (device-name (and=> device-spec device-spec->device-name))
425 (modules (menu-entry-multiboot-modules entry)))
418 #~(format port " 426 #~(format port "
419menuentry ~s { 427menuentry ~s {
420 multiboot ~a root=part:~a:device:~ad0~a~a 428 multiboot ~a root=~a~a~a
421}~%" 429}~%"
422 #$label 430 #$label
423 #$kernel 431 #$kernel
424 #$root-index 432 #$(device-name->hurd-device-name device-name #:disk disk)
425 #$disk
426 (string-join (list #$@arguments) " " 'prefix) 433 (string-join (list #$@arguments) " " 'prefix)
427 (string-join (map string-join '#$modules) 434 (string-join (map string-join '#$modules)
428 "\n module " 'prefix)))) 435 "\n module " 'prefix))))
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 41e1c9e2828..6fd9f950939 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -9,6 +9,7 @@
9;;; Copyright © 2022 Oleg Pykhalov <go.wigust@gmail.com> 9;;; Copyright © 2022 Oleg Pykhalov <go.wigust@gmail.com>
10;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr> 10;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr>
11;;; Copyright © 2024 Richard Sent <richard@freakingpenguin.com> 11;;; Copyright © 2024 Richard Sent <richard@freakingpenguin.com>
12;;; Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
12;;; 13;;;
13;;; This file is part of GNU Guix. 14;;; This file is part of GNU Guix.
14;;; 15;;;
@@ -53,6 +54,11 @@
53 find-partition-by-luks-uuid 54 find-partition-by-luks-uuid
54 canonicalize-device-spec 55 canonicalize-device-spec
55 56
57 device-name->hurd-device-name
58 device-spec->device
59 device-spec->device-name
60 hurd-device-name->device-name
61
56 read-partition-label 62 read-partition-label
57 read-partition-uuid 63 read-partition-uuid
58 read-luks-partition-uuid 64 read-luks-partition-uuid
@@ -1431,4 +1437,56 @@ corresponds to the symbols listed in FLAGS."
1431 (or (file-system-mount-may-fail? fs) 1437 (or (file-system-mount-may-fail? fs)
1432 (apply throw args)))))) 1438 (apply throw args))))))
1433 1439
1440(define %device-name-regexp "/dev/[hsvw]d([abcd])([0-9]*)")
1441(define %hurd-device-name-regexp "part:([0-9]*):device:[hw]d([0-9]*)")
1442
1443(define (device-spec->device-name device-spec)
1444 "Return DEVICE-SPEC as a Linux /dev/XdYZ device name, also catering for uuid
1445or label."
1446 (cond ((string-match %device-name-regexp device-spec)
1447 device-spec)
1448 ((string-match %hurd-device-name-regexp device-spec)
1449 (hurd-device-name->device-name device-spec))
1450 ((string->uuid device-spec)
1451 =>
1452 (lambda (uuid) (false-if-exception (find-partition-by-uuid uuid))))
1453 (else
1454 (false-if-exception (find-partition-by-label device-spec)))))
1455
1456(define* (device-name->hurd-device-name device-name #:key (disk "w"))
1457 "Return DEVICE-NAME as a Hurd device name:
1458 part:PART-NUMBER:device:DISKdDISK-INDEX
1459Default to part:1:device:DISKd0 if partition cannot be found."
1460 (let* ((m (and=> device-name (cute string-match %device-name-regexp <>)))
1461 (disk-char (and m (and=> (match:substring m 1)
1462 (compose car string->list))))
1463 (disk-index (or (and disk-char
1464 (- (char->integer disk-char) (char->integer #\a)))
1465 0))
1466 (partition-number (or (and m (and=> (match:substring m 2)
1467 string->number))
1468 1)))
1469 (format #f "part:~a:device:~ad~a" partition-number disk disk-index)))
1470
1471(define* (hurd-device-name->device-name device-name #:key (disk "s"))
1472 (let* ((m (and=> device-name (cute string-match %hurd-device-name-regexp <>)))
1473 (disk-index-string (and=> m (cute match:substring <> 2)))
1474 (disk-index (or (and=> disk-index-string string->number)
1475 0))
1476 (disk-index-char (integer->char (+ disk-index (char->integer #\a))))
1477 (partition-string (and=> m (cute match:substring <> 1)))
1478 (partition-number (or (and=> partition-string string->number)
1479 1)))
1480 (format #f "/dev/~ad~a~a" disk disk-index-char partition-number)))
1481
1482(define (device-spec->device device-spec)
1483 "Return DEVICE-SPEC as UUID, FILE-SYSTEM-LABEL, or DEVICE-SPEC."
1484 (cond ((and=> (string->uuid device-spec)
1485 find-partition-by-uuid)
1486 (string->uuid device-spec))
1487 ((find-partition-by-label device-spec)
1488 (file-system-label device-spec))
1489 (else
1490 device-spec)))
1491
1434;;; file-systems.scm ends here 1492;;; file-systems.scm ends here