using read-only device mapper entry
authorIvo De Decker <ivo.dedecker@ugent.be>
Sat, 13 Jul 2013 19:15:41 +0000 (21:15 +0200)
committerColin Watson <cjwatson@debian.org>
Thu, 19 Jan 2017 21:01:49 +0000 (21:01 +0000)
debian/control
linux-boot-probes/common/50mounted-tests
os-probes/common/50mounted-tests

index 10459bd..d0f778a 100644 (file)
@@ -11,7 +11,7 @@ Vcs-Git: https://anonscm.debian.org/git/d-i/os-prober.git
 Package: os-prober-udeb
 Package-Type: udeb
 Architecture: any
-Depends: ${misc:Depends}, ${shlibs:Depends}, di-utils-mapdevfs, anna (>= 1.16), grub-mount-udeb [i386 amd64 powerpc ppc64 ppc64el sparc mipsel kfreebsd-i386 kfreebsd-amd64]
+Depends: ${misc:Depends}, ${shlibs:Depends}, di-utils-mapdevfs, anna (>= 1.16), grub-mount-udeb [i386 amd64 powerpc ppc64 ppc64el sparc mipsel kfreebsd-i386 kfreebsd-amd64], dmsetup-udeb [linux-any]
 Provides: os-prober
 Description: utility to detect other OSes on a set of drives
  This package is to be used by boot loader installers to detect other OSes
@@ -22,7 +22,7 @@ Package: os-prober
 Architecture: any
 Section: utils
 Priority: extra
-Depends: ${shlibs:Depends}, ${misc:Depends}
+Depends: ${shlibs:Depends}, ${misc:Depends}, dmsetup [linux-any]
 Description: utility to detect other OSes on a set of drives
  This package detects other OSes available on a system and outputs the
  results in a generic machine-readable format.
index fc25dbf..3a58456 100755 (executable)
@@ -10,6 +10,11 @@ do_unmount() {
                        warn "failed to umount $tmpmnt"
                fi
        fi
+       if [ -e "$dm_device" ]
+       then
+               debug "remove device mapper device $dm_device"
+               dmsetup remove $dm_device
+       fi
        rmdir "$tmpmnt" || true
 }
 
@@ -55,16 +60,39 @@ if type grub-mount >/dev/null 2>&1 && \
        type="$(grub-probe -d "$partition" -t fs)"
        [ "$type" ] || type=fuseblk
 else
-       ro_partition "$partition"
-       for type in $types; do
-               if mountinfo=`mount -o ro -t "$type" "$partition" "$tmpmnt" 2>&1`; then
-                       debug "mounted as $type filesystem"
-                       mounted=1
-                       break
+       if type dmsetup >/dev/null 2>&1 && \
+          type blockdev >/dev/null 2>&1; then
+               partition_name="osprober-linux-${partition##*/}"
+               dm_device="/dev/mapper/$partition_name"
+               size_p=$(blockdev --getsize $partition )
+               if [ -e "$dm_device" ]; then
+                       error "$dm_device already exists"
+                       dm_device=
                else
-                       debug "mounting $partition as $type failed: $mountinfo"
+                       debug "creating device mapper device $dm_device"
+                       echo "0 $size_p linear $partition 0" | dmsetup create -r $partition_name
+                       for type in $types; do
+                               if mountinfo=`mount -o ro -t "$type" "$dm_device" "$tmpmnt" 2>&1`; then
+                                       debug "mounted as $type filesystem"
+                                       mounted=1
+                                       break
+                               else
+                                       debug "mounting $dm_device ($partition) as $type failed: $mountinfo"
+                               fi
+                       done
                fi
-       done
+       else
+               ro_partition "$partition"
+               for type in $types; do
+                       if mountinfo=`mount -o ro -t "$type" "$partition" "$tmpmnt" 2>&1`; then
+                               debug "mounted as $type filesystem"
+                               mounted=1
+                               break
+                       else
+                               debug "mounting $partition as $type failed: $mountinfo"
+                       fi
+               done
+       fi
 fi
 
 if [ "$mounted" ]; then
index c02397e..c65feef 100755 (executable)
@@ -11,6 +11,11 @@ do_unmount() {
                        warn "failed to umount $tmpmnt"
                fi
        fi
+       if [ -e "$dm_device" ]
+       then
+               debug "remove device mapper device $dm_device"
+               dmsetup remove $dm_device
+       fi
        rmdir "$tmpmnt" || true
 }
 
@@ -67,16 +72,39 @@ if type grub-mount >/dev/null 2>&1 && \
                type=fuseblk
        fi
 else
-       ro_partition "$partition"
-       for type in $types $delaytypes; do
-               if mountinfo=`mount -o ro -t "$type" "$partition" "$tmpmnt" 2>&1`; then
-                       debug "mounted as $type filesystem"
-                       mounted=1
-                       break
+       if type dmsetup >/dev/null 2>&1 && \
+          type blockdev >/dev/null 2>&1; then
+               partition_name="osprober-${partition##*/}"
+               dm_device="/dev/mapper/$partition_name"
+               size_p=$(blockdev --getsize $partition )
+               if [ -e "$dm_device" ]; then
+                       error "$dm_device already exists"
+                       dm_device=
                else
-                       debug "mounting $partition as $type failed: $mountinfo"
+                       debug "creating device mapper device $dm_device"
+                       echo "0 $size_p linear $partition 0" | dmsetup create -r $partition_name
+                       for type in $types $delaytypes; do
+                               if mountinfo=`mount -o ro -t "$type" "$dm_device" "$tmpmnt" 2>&1`; then
+                                       debug "mounted as $type filesystem"
+                                       mounted=1
+                                       break
+                               else
+                                       debug "mounting $dm_device ($partition) as $type failed: $mountinfo"
+                               fi
+                       done
                fi
-       done
+       else
+               ro_partition "$partition"
+               for type in $types $delaytypes; do
+                       if mountinfo=`mount -o ro -t "$type" "$partition" "$tmpmnt" 2>&1`; then
+                               debug "mounted as $type filesystem"
+                               mounted=1
+                               break
+                       else
+                               debug "mounting $partition as $type failed: $mountinfo"
+                       fi
+               done
+       fi
 fi
 
 if [ "$mounted" ]; then