diff options
| author | Josselin Poiret <dev@jpoiret.xyz> | 2021-11-23 22:19:09 +0000 |
|---|---|---|
| committer | Mathieu Othacehe <othacehe@gnu.org> | 2021-11-26 10:52:02 +0000 |
| commit | b90504cdb5ce3d1981c8d7bc8a9cc918b0d60af7 (patch) | |
| tree | a492fdb327effdc5abefe71bd045e037108a2dfa /gnu/installer/parted.scm | |
| parent | 5d93e9e36a9927f77e789293e2db7c42be199024 (diff) | |
installer: Rework installation device detection.
* gnu/installer/parted.scm (installation-device): Remove it.
* gnu/installer/parted.scm (installer-root-partition-path): Add it.
* gnu/installer/parted.scm (non-install-devices): Add installation-device?
predicate.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
Diffstat (limited to 'gnu/installer/parted.scm')
| -rw-r--r-- | gnu/installer/parted.scm | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm index cbe676017bd..ad7dd6bf91b 100644 --- a/gnu/installer/parted.scm +++ b/gnu/installer/parted.scm | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #:use-module ((gnu build file-systems) | 26 | #:use-module ((gnu build file-systems) |
| 27 | #:select (canonicalize-device-spec | 27 | #:select (canonicalize-device-spec |
| 28 | find-partition-by-label | 28 | find-partition-by-label |
| 29 | find-partition-by-uuid | ||
| 29 | read-partition-uuid | 30 | read-partition-uuid |
| 30 | read-luks-partition-uuid)) | 31 | read-luks-partition-uuid)) |
| 31 | #:use-module ((gnu build linux-boot) | 32 | #:use-module ((gnu build linux-boot) |
| @@ -345,35 +346,38 @@ fail. See rereadpt function in wipefs.c of util-linux for an explanation." | |||
| 345 | (with-null-output-ports | 346 | (with-null-output-ports |
| 346 | (invoke "dmsetup" "remove_all"))) | 347 | (invoke "dmsetup" "remove_all"))) |
| 347 | 348 | ||
| 348 | (define (installation-device) | 349 | (define (installer-root-partition-path) |
| 349 | "Return the installation device path." | 350 | "Return the root partition path, or #f if it could not be detected." |
| 350 | (let* ((cmdline (linux-command-line)) | 351 | (let* ((cmdline (linux-command-line)) |
| 351 | (root (find-long-option "--root" cmdline))) | 352 | (root (find-long-option "--root" cmdline))) |
| 352 | (and root | 353 | (and root |
| 353 | (canonicalize-device-spec (uuid root))))) | 354 | (or (and (access? root F_OK) root) |
| 355 | (find-partition-by-label root) | ||
| 356 | (and=> (uuid root) | ||
| 357 | find-partition-by-uuid))))) | ||
| 354 | 358 | ||
| 355 | (define (non-install-devices) | 359 | (define (non-install-devices) |
| 356 | "Return all the available devices, except the install device." | 360 | "Return all the available devices, except the install device." |
| 357 | (define (read-only? device) | 361 | |
| 358 | (dynamic-wind | 362 | (define the-installer-root-partition-path |
| 359 | (lambda () | 363 | (installer-root-partition-path)) |
| 360 | (device-open device)) | 364 | |
| 361 | (lambda () | 365 | ;; Read partition table of device and compare each path to the one |
| 362 | (device-read-only? device)) | 366 | ;; we're booting from to determine if it is the installation |
| 363 | (lambda () | 367 | ;; device. |
| 364 | (device-close device)))) | 368 | (define (installation-device? device) |
| 365 | 369 | ;; When using CDROM based installation, the root partition path may be the | |
| 366 | ;; If parted reports that a device is read-only it is probably the | 370 | ;; device path. |
| 367 | ;; installation device. However, as this detection does not always work, | 371 | (or (string=? the-installer-root-partition-path |
| 368 | ;; compare the device path to the installation device path read from the | 372 | (device-path device)) |
| 369 | ;; command line. | 373 | (let ((disk (disk-new device))) |
| 370 | (let ((install-device (installation-device))) | 374 | (and disk |
| 371 | (remove (lambda (device) | 375 | (any (lambda (partition) |
| 372 | (let ((file-name (device-path device))) | 376 | (string=? the-installer-root-partition-path |
| 373 | (or (read-only? device) | 377 | (partition-get-path partition))) |
| 374 | (and install-device | 378 | (disk-partitions disk)))))) |
| 375 | (string=? file-name install-device))))) | 379 | |
| 376 | (devices)))) | 380 | (remove installation-device? (devices))) |
| 377 | 381 | ||
| 378 | 382 | ||
| 379 | ;; | 383 | ;; |
