fi
}
-# Sets $mountboot as output variable. (We do this rather than requiring a
-# subshell so that we can run ro_partition without the cleanup trap firing
-# when the subshell exits.)
+do_dmsetup () {
+ local prefix partition dm_device partition_name size_p
+ prefix="$1"
+ partition="$2"
+ dm_device=
+
+ 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 "creating device mapper device $dm_device"
+ echo "0 $size_p linear $partition 0" | dmsetup create -r $partition_name
+ fi
+ fi
+ echo "$dm_device"
+}
+
+# Sets $mountboot and $dm_device as output variables. This is very messy,
+# but POSIX shell isn't really up to the task of doing it more cleanly.
linux_mount_boot () {
partition="$1"
tmpmnt="$2"
bootpart=""
mounted=""
+ dm_device=""
if [ -e "$tmpmnt/etc/fstab" ]; then
# Try to mount any /boot partition.
bootmnt=$(parsefstab < "$tmpmnt/etc/fstab" | grep " /boot ") || true
if type grub-mount >/dev/null 2>&1 && \
grub-mount "$boottomnt" "$tmpmnt/boot" 2>/dev/null; then
mounted=1
+ elif dm_device="$(do_dmsetup osprober-linux "$boottomnt")" && [ "$dm_device" ]; then
+ if mountinfo=`mount -o ro "$dm_device" "$tmpmnt/boot" -t "$3"`; then
+ debug "mounted as $3 filesystem"
+ mounted=1
+ else
+ error "failed to mount $dm_device on $tmpmnt/boot: $mountinfo"
+ fi
else
ro_partition "$boottomnt"
if mount -o ro "$boottomnt" "$tmpmnt/boot" -t "$3"; then
- mounted=1
- else
+ mounted=1
+ else
error "failed to mount $boottomnt on $tmpmnt/boot"
fi
fi
warn "failed to umount $tmpmnt"
fi
fi
- if [ -e "$dm_device" ]
- then
- debug "remove device mapper device $dm_device"
- dmsetup remove $dm_device
- fi
+ for dm_device in $dm_devices; do
+ if [ -e "$dm_device" ]; then
+ debug "remove device mapper device $dm_device"
+ dmsetup remove $dm_device
+ fi
+ done
rmdir "$tmpmnt" || true
}
fi
mounted=
+dm_devices=
if type grub-mount >/dev/null 2>&1 && \
type grub-probe >/dev/null 2>&1 && \
grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
mounted=1
type="$(grub-probe -d "$partition" -t fs)"
[ "$type" ] || type=fuseblk
+elif dm_device="$(do_dmsetup osprober-linux "$partition")" && \
+ [ "$dm_device" ]; then
+ dm_devices="$dm_device"
+ 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
else
- 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=
+ 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 "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
+ debug "mounting $partition as $type failed: $mountinfo"
fi
- 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
+ done
fi
if [ "$mounted" ]; then
linux_mount_boot "$partition" "$tmpmnt"
bootpart="${mountboot%% *}"
mounted="${mountboot#* }"
+ if [ "$dm_device" ]; then
+ dm_devices="$dm_device $dm_devices"
+ fi
for test in /usr/lib/linux-boot-probes/mounted/*; do
if [ -f "$test" ] && [ -x "$test" ]; then
debug "mounted using GRUB, but unknown filesystem?"
type=fuseblk
fi
+elif dm_device="$(do_dmsetup osprober "$partition")" && \
+ [ "$dm_device" ]; then
+ 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
else
- 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=
+ 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 "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
+ debug "mounting $partition as $type failed: $mountinfo"
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
- else
- debug "mounting $partition as $type failed: $mountinfo"
- fi
- done
- fi
+ done
fi
if [ "$mounted" ]; then