summaryrefslogtreecommitdiff
path: root/gnu/installer
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2021-06-17 11:00:26 +0200
committerMathieu Othacehe <othacehe@gnu.org>2021-06-17 11:00:26 +0200
commite12be802e02b3345a753e7ec1287852a7337a0a5 (patch)
tree8245a432fbb08dd098dc11a759c18510b0d5c084 /gnu/installer
parentf1a71be028ac13b567a7e8d11b4f15cbfa3f50d4 (diff)
installer: Improve the installation device detection method.
Fixes: <https://issues.guix.gnu.org/47780>. * gnu/installer/parted.scm (installation-device): New method. (non-install-devices): Remove devices which are reported as read-only by parted or which path is identical to the installation device path returned by the above method.
Diffstat (limited to 'gnu/installer')
-rw-r--r--gnu/installer/parted.scm44
1 files changed, 32 insertions, 12 deletions
diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm
index 277581ef4b5..1f9cec1d116 100644
--- a/gnu/installer/parted.scm
+++ b/gnu/installer/parted.scm
@@ -24,9 +24,13 @@
24 #:use-module (gnu installer newt page) 24 #:use-module (gnu installer newt page)
25 #:use-module (gnu system uuid) 25 #:use-module (gnu system uuid)
26 #:use-module ((gnu build file-systems) 26 #:use-module ((gnu build file-systems)
27 #:select (find-partition-by-label 27 #:select (canonicalize-device-spec
28 find-partition-by-label
28 read-partition-uuid 29 read-partition-uuid
29 read-luks-partition-uuid)) 30 read-luks-partition-uuid))
31 #:use-module ((gnu build linux-boot)
32 #:select (linux-command-line
33 find-long-option))
30 #:use-module ((gnu build linux-modules) 34 #:use-module ((gnu build linux-modules)
31 #:select (missing-modules)) 35 #:select (missing-modules))
32 #:use-module ((gnu system linux-initrd) 36 #:use-module ((gnu system linux-initrd)
@@ -338,19 +342,35 @@ fail. See rereadpt function in wipefs.c of util-linux for an explanation."
338 (with-null-output-ports 342 (with-null-output-ports
339 (invoke "dmsetup" "remove_all"))) 343 (invoke "dmsetup" "remove_all")))
340 344
345(define (installation-device)
346 "Return the installation device path."
347 (let* ((cmdline (linux-command-line))
348 (root (find-long-option "--root" cmdline)))
349 (and root
350 (canonicalize-device-spec (uuid root)))))
351
341(define (non-install-devices) 352(define (non-install-devices)
342 "Return all the available devices, except the install device." 353 "Return all the available devices, except the install device."
343 ;; XXX: The install image uses an overlayfs so detecting the install device 354 (define (read-only? device)
344 ;; is not easy. Assume that a given device is the installation device if it 355 (dynamic-wind
345 ;; is reported as busy by parted or if its label is the ISO9660 image label. 356 (lambda ()
346 (remove (lambda (device) 357 (device-open device))
347 (let ((file-name (device-path device)) 358 (lambda ()
348 (install-file-name 359 (device-read-only? device))
349 (find-partition-by-label "GUIX_IMAGE"))) 360 (lambda ()
350 (or (device-is-busy? device) 361 (device-close device))))
351 (and install-file-name 362
352 (string=? file-name install-file-name))))) 363 ;; If parted reports that a device is read-only it is probably the
353 (devices))) 364 ;; installation device. However, as this detection does not always work,
365 ;; compare the device path to the installation device path read from the
366 ;; command line.
367 (let ((install-device (installation-device)))
368 (remove (lambda (device)
369 (let ((file-name (device-path device)))
370 (or (read-only? device)
371 (and install-device
372 (string=? file-name install-device)))))
373 (devices))))
354 374
355 375
356;; 376;;