[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch version-1.4.0 updated: installer: Detect mapped installation devi

From: guix-commits
Subject: branch version-1.4.0 updated: installer: Detect mapped installation devices.
Date: Sat, 10 Dec 2022 05:23:42 -0500

This is an automated email from the git hooks/post-receive script.

mothacehe pushed a commit to branch version-1.4.0
in repository guix.

The following commit(s) were added to refs/heads/version-1.4.0 by this push:
     new 1ab48edb16 installer: Detect mapped installation devices.
1ab48edb16 is described below

commit 1ab48edb1674e0454d4368fdbed16cbbdfd9bf06
Author: Mathieu Othacehe <>
AuthorDate: Thu Dec 8 13:24:02 2022 +0100

    installer: Detect mapped installation devices.
    Fixes: <>
    * gnu/installer/parted.scm (mapped-device?,
    mapped-device-parent-partition): New procedures.
    (eligible-devices): Detect mapped installation devices using the new
 gnu/installer/parted.scm | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm
index 82375d29e3..51fa7cf9d9 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."
 (define %min-device-size
   (* 2 GIBIBYTE-SIZE)) ;2GiB
+(define (mapped-device? device)
+  "Return #true if DEVICE is a mapped device, false otherwise."
+  (string-prefix? "/dev/dm-" device))
+;; TODO: Use DM_TABLE_DEPS ioctl instead of dmsetup.
+(define (mapped-device-parent-partition device)
+  "Return the parent partition path of the mapped DEVICE."
+  (let* ((command `("dmsetup" "deps" ,device "-o" "devname"))
+         (parent #f)
+         (handler
+          (lambda (input)
+            ;; We are parsing an output that should look like:
+            ;; 1 dependencies  : (sda2)
+            (let ((result
+                   (string-match "\\(([^\\)]+)\\)"
+                                 (get-string-all input))))
+              (and result
+                   (set! parent
+                         (format #f "/dev/~a"
+                                 (match:substring result 1))))))))
+    (run-external-command-with-handler handler command)
+    parent))
 (define (eligible-devices)
   "Return all the available devices except the install device and the devices
 which are smaller than %MIN-DEVICE-SIZE."
   (define the-installer-root-partition-path
-    (installer-root-partition-path))
+    (let ((root (installer-root-partition-path)))
+      (cond
+       ((mapped-device? root)
+        ;; If the partition is a mapped device (/dev/dm-X), locate the parent
+        ;; partition.  It is the case when Ventoy is used to host the
+        ;; installation image.
+        (let ((parent (mapped-device-parent-partition root)))
+          (installer-log-line "mapped device ~a -> ~a" parent root)
+          parent))
+       (else root))))
   (define (small-device? device)
     (let ((length (device-length device))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]