diff options
| author | Janneke Nieuwenhuizen <janneke@gnu.org> | 2024-10-24 21:22:39 +0200 |
|---|---|---|
| committer | Jan (janneke) Nieuwenhuizen <janneke@gnu.org> | 2024-11-11 07:28:33 +0100 |
| commit | fdb23d9db8ca5431e280366c5c834e01eda62a5f (patch) | |
| tree | c4dec4c967c8ba47f957304ff35d68ee66d438b7 /gnu/build | |
| parent | 046d6d9f8e5456d651cdc69b04dfae3af5230a98 (diff) | |
bootloader: grub: Remove hardcoded partition number for the Hurd.
This supports using another than the default DISK0 PART1 and using LABEL or
UUID as root file-system specifier. It still defaults to DISK0 PART1 if
the file-system cannot be found, i.e., lives only at the build side: A
virtual machine/childhurd build.
* gnu/build/file-systems.scm (%hurd-device-spec-regexp, %device-spec-regexp):
New variables.
(device-name->hurd-device-name, hurd-device-name->device-name,
device-spec->device, device-spec->device-name): Use them in new procedures.
* gnu/bootloader/grub.scm (make-grub-configuration): Use them to remove
hardcoded partition number (root-index 1).
Change-Id: I49fa93dacc09883dfb4d695402c5eac2e0e17286
Diffstat (limited to 'gnu/build')
| -rw-r--r-- | gnu/build/file-systems.scm | 58 |
1 files changed, 58 insertions, 0 deletions
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 | ||
| 1445 | or 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 | ||
| 1459 | Default 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 |
