summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2022-12-08 13:24:02 +0100
committerMathieu Othacehe <othacehe@gnu.org>2022-12-10 11:23:27 +0100
commit1ab48edb1674e0454d4368fdbed16cbbdfd9bf06 (patch)
tree4c946fc8edaef59ea40f21715f7e4acf7c5fbd04
parentb129026e2e242e9068158ae6e6fcd8d7c5ea092e (diff)
installer: Detect mapped installation devices.
Fixes: <https://issues.guix.gnu.org/59823> * gnu/installer/parted.scm (mapped-device?, mapped-device-parent-partition): New procedures. (eligible-devices): Detect mapped installation devices using the new procedures.
-rw-r--r--gnu/installer/parted.scm34
1 files changed, 33 insertions, 1 deletions
diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm
index 82375d29e37..51fa7cf9d9c 100644
--- a/gnu/installer/parted.scm
+++ b/gnu/installer/parted.scm
@@ -379,12 +379,44 @@ fail. See rereadpt function in wipefs.c of util-linux for an explanation."
379(define %min-device-size 379(define %min-device-size
380 (* 2 GIBIBYTE-SIZE)) ;2GiB 380 (* 2 GIBIBYTE-SIZE)) ;2GiB
381 381
382(define (mapped-device? device)
383 "Return #true if DEVICE is a mapped device, false otherwise."
384 (string-prefix? "/dev/dm-" device))
385
386;; TODO: Use DM_TABLE_DEPS ioctl instead of dmsetup.
387(define (mapped-device-parent-partition device)
388 "Return the parent partition path of the mapped DEVICE."
389 (let* ((command `("dmsetup" "deps" ,device "-o" "devname"))
390 (parent #f)
391 (handler
392 (lambda (input)
393 ;; We are parsing an output that should look like:
394 ;; 1 dependencies : (sda2)
395 (let ((result
396 (string-match "\\(([^\\)]+)\\)"
397 (get-string-all input))))
398 (and result
399 (set! parent
400 (format #f "/dev/~a"
401 (match:substring result 1))))))))
402 (run-external-command-with-handler handler command)
403 parent))
404
382(define (eligible-devices) 405(define (eligible-devices)
383 "Return all the available devices except the install device and the devices 406 "Return all the available devices except the install device and the devices
384which are smaller than %MIN-DEVICE-SIZE." 407which are smaller than %MIN-DEVICE-SIZE."
385 408
386 (define the-installer-root-partition-path 409 (define the-installer-root-partition-path
387 (installer-root-partition-path)) 410 (let ((root (installer-root-partition-path)))
411 (cond
412 ((mapped-device? root)
413 ;; If the partition is a mapped device (/dev/dm-X), locate the parent
414 ;; partition. It is the case when Ventoy is used to host the
415 ;; installation image.
416 (let ((parent (mapped-device-parent-partition root)))
417 (installer-log-line "mapped device ~a -> ~a" parent root)
418 parent))
419 (else root))))
388 420
389 (define (small-device? device) 421 (define (small-device? device)
390 (let ((length (device-length device)) 422 (let ((length (device-length device))