|
Packit |
d86cd3 |
#!/bin/sh
|
|
Packit |
d86cd3 |
# Sub-tests that require a mounted partition.
|
|
Packit |
d86cd3 |
set -e
|
|
Packit |
d86cd3 |
partition="$1"
|
|
Packit |
d86cd3 |
|
|
Packit |
d86cd3 |
. /usr/share/os-prober/common.sh
|
|
Packit |
d86cd3 |
|
|
Packit |
d86cd3 |
do_unmount() {
|
|
Packit |
d86cd3 |
if [ "$mounted" ]; then
|
|
Packit |
d86cd3 |
if ! umount "$tmpmnt"; then
|
|
Packit |
d86cd3 |
warn "failed to umount $tmpmnt"
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
if [ -e "$dm_device" ]
|
|
Packit |
d86cd3 |
then
|
|
Packit |
d86cd3 |
debug "remove device mapper device $dm_device"
|
|
Packit |
d86cd3 |
dmsetup remove $dm_device
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
rmdir "$tmpmnt" || true
|
|
Packit |
d86cd3 |
}
|
|
Packit |
d86cd3 |
|
|
rpm-build |
fe73fc |
if [ "x$1" = xbtrfs ]; then
|
|
rpm-build |
fe73fc |
types=btrfs
|
|
rpm-build |
fe73fc |
if [ -z "$2" -o -z "$3" ]; then
|
|
rpm-build |
fe73fc |
debug "missing btrfs parameters, exiting"
|
|
rpm-build |
fe73fc |
exit 1
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
UUID="$2"
|
|
rpm-build |
fe73fc |
BTRFSDEV="$3"
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
partition="$1"
|
|
rpm-build |
fe73fc |
types="$(fs_type "$partition")" || types=NOT-DETECTED
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
|
|
Packit |
d86cd3 |
if [ "$types" = NOT-DETECTED ]; then
|
|
Packit |
d86cd3 |
debug "$1 type not recognised; skipping"
|
|
rpm-build |
fe73fc |
exit 1
|
|
Packit |
d86cd3 |
elif [ "$types" = swap ]; then
|
|
Packit |
d86cd3 |
debug "$1 is a swap partition; skipping"
|
|
rpm-build |
fe73fc |
exit 1
|
|
Packit |
d86cd3 |
elif [ "$types" = crypto_LUKS ]; then
|
|
Packit |
d86cd3 |
debug "$1 is a LUKS partition; skipping"
|
|
rpm-build |
fe73fc |
exit 1
|
|
Packit |
d86cd3 |
elif [ "$types" = LVM2_member ]; then
|
|
Packit |
d86cd3 |
debug "$1 is an LVM member; skipping"
|
|
rpm-build |
fe73fc |
exit 1
|
|
Packit |
d86cd3 |
elif [ "$types" = ntfs ]; then
|
|
Packit |
d86cd3 |
if type ntfs-3g >/dev/null 2>&1; then
|
|
Packit |
d86cd3 |
types='ntfs-3g ntfs'
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
elif [ -z "$types" ]; then
|
|
Packit |
d86cd3 |
if type cryptsetup >/dev/null 2>&1 && \
|
|
Packit |
d86cd3 |
cryptsetup luksDump "$partition" >/dev/null 2>&1; then
|
|
Packit |
d86cd3 |
debug "$1 is a LUKS partition; skipping"
|
|
rpm-build |
fe73fc |
exit 1
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
for type in $(grep -v nodev /proc/filesystems); do
|
|
Packit |
d86cd3 |
# hfsplus filesystems are mountable as hfs. Try hfs last so
|
|
Packit |
d86cd3 |
# that we can tell the difference.
|
|
Packit |
d86cd3 |
if [ "$type" = hfs ]; then
|
|
Packit |
d86cd3 |
delaytypes="${delaytypes:+$delaytypes }$type"
|
|
Packit |
d86cd3 |
elif [ "$type" = fuseblk ]; then
|
|
Packit |
d86cd3 |
if type ntfs-3g >/dev/null 2>&1; then
|
|
Packit |
d86cd3 |
types="${types:+$types }ntfs-3g"
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
else
|
|
Packit |
d86cd3 |
types="${types:+$types }$type"
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
done
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
|
|
Packit |
d86cd3 |
tmpmnt=/var/lib/os-prober/mount
|
|
Packit |
d86cd3 |
if [ ! -d "$tmpmnt" ]; then
|
|
Packit |
d86cd3 |
mkdir "$tmpmnt"
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
|
|
Packit |
d86cd3 |
mounted=
|
|
rpm-build |
fe73fc |
|
|
rpm-build |
fe73fc |
# all btrfs processing here. Handle both unmounted and
|
|
rpm-build |
fe73fc |
# mounted subvolumes.
|
|
rpm-build |
fe73fc |
if [ "$types" = btrfs ]; then
|
|
rpm-build |
fe73fc |
partition="$BTRFSDEV"
|
|
rpm-build |
fe73fc |
debug "begin btrfs processing for $UUID"
|
|
rpm-build |
fe73fc |
# note that the btrfs volume must not be mounted ro
|
|
rpm-build |
fe73fc |
if mount -t btrfs -U "$UUID" "$tmpmnt" 2>/dev/null; then
|
|
rpm-build |
fe73fc |
debug "btrfs volume $UUID mounted"
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
warn "cannot mount btrfs volume $UUID, exiting"
|
|
rpm-build |
fe73fc |
rmdir "$tmpmnt" || true
|
|
rpm-build |
fe73fc |
exit 1
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
# besides regular subvols, get ro and snapshot so thet can be excluded
|
|
rpm-build |
fe73fc |
subvols=$(btrfs subvolume list "$tmpmnt" | cut -d ' ' -f 9)
|
|
rpm-build |
fe73fc |
rosubvols=$(btrfs subvolume list -r "$tmpmnt" | cut -d ' ' -f 9)
|
|
rpm-build |
fe73fc |
sssubvols=$(btrfs subvolume list -s "$tmpmnt" | cut -d ' ' -f 14)
|
|
rpm-build |
fe73fc |
if ! umount "$tmpmnt"; then
|
|
rpm-build |
fe73fc |
warn "failed to umount btrfs volume on $tmpmnt"
|
|
rpm-build |
fe73fc |
rmdir "$tmpmnt" || true
|
|
rpm-build |
fe73fc |
exit 1
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
|
|
rpm-build |
fe73fc |
found=
|
|
rpm-build |
fe73fc |
mounted=
|
|
rpm-build |
fe73fc |
|
|
rpm-build |
fe73fc |
mpoint="$(grep btrfs /proc/self/mountinfo | grep "$partition " | cut -d ' ' -f 5)"
|
|
rpm-build |
fe73fc |
if [ -n "$mpoint" -a "x$mpoint" = "x/" ]; then
|
|
rpm-build |
fe73fc |
debug "This is the root for the running system" #running system must be done elsewhere
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
#partition was not root of running system, so lets look for bootable subvols
|
|
rpm-build |
fe73fc |
if [ -n "$mpoint" ] ; then
|
|
rpm-build |
fe73fc |
mounted=1 #partition was already mounted,so lets not unmount it when done
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
# again, do not mount btrfs ro
|
|
rpm-build |
fe73fc |
mount -t btrfs -U "$UUID" "$tmpmnt"
|
|
rpm-build |
fe73fc |
mpoint="$tmpmnt"
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
|
|
Packit Service |
8d4c46 |
test="/usr/libexec/os-probes/mounted/90linux-distro"
|
|
rpm-build |
fe73fc |
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
rpm-build |
fe73fc |
debug "running subtest $test"
|
|
rpm-build |
fe73fc |
if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID"; then
|
|
rpm-build |
fe73fc |
debug "os found by subtest $test on $partition"
|
|
rpm-build |
fe73fc |
found=1
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
if [ -z "$mounted" ]; then
|
|
rpm-build |
fe73fc |
if ! umount "$tmpmnt"; then
|
|
rpm-build |
fe73fc |
warn "failed to umount $tmpmnt"
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
|
|
rpm-build |
fe73fc |
if [ -z "$subvols" ]; then
|
|
rpm-build |
fe73fc |
debug "no subvols found on btrfs volume $UUID"
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
found=
|
|
rpm-build |
fe73fc |
for subvol in $subvols; do
|
|
rpm-build |
fe73fc |
debug "begin btrfs processing for $UUID subvol=$subvol"
|
|
rpm-build |
fe73fc |
if echo "$rosubvols" | grep -q -x "$subvol"; then
|
|
rpm-build |
fe73fc |
continue
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
if echo "$sssubvols" | grep -q -x "$subvol"; then
|
|
rpm-build |
fe73fc |
continue
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
mounted=
|
|
rpm-build |
fe73fc |
mpoint="$(grep btrfs /proc/self/mountinfo | grep "$partition " | grep "/$subvol " | cut -d ' ' -f 5)"
|
|
rpm-build |
fe73fc |
if [ -n "$mpoint" ]; then
|
|
rpm-build |
fe73fc |
if [ "x$mpoint" = "x/" ]; then
|
|
rpm-build |
fe73fc |
continue # this is the root for the running system
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
mounted=1
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
# again, do not mount btrfs ro
|
|
rpm-build |
fe73fc |
mount -t btrfs -o subvol="$subvol" -U "$UUID" "$tmpmnt"
|
|
rpm-build |
fe73fc |
mpoint="$tmpmnt"
|
|
rpm-build |
fe73fc |
fi
|
|
Packit Service |
8d4c46 |
test="/usr/libexec/os-probes/mounted/90linux-distro"
|
|
rpm-build |
fe73fc |
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
rpm-build |
fe73fc |
debug "running subtest $test"
|
|
rpm-build |
fe73fc |
if "$test" "$partition" "$mpoint" btrfs "UUID=$UUID" "subvol=$subvol"; then
|
|
rpm-build |
fe73fc |
debug "os found by subtest $test on subvol $subvol"
|
|
rpm-build |
fe73fc |
found=1
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
if [ -z "$mounted" ]; then
|
|
rpm-build |
fe73fc |
if ! umount "$tmpmnt"; then
|
|
rpm-build |
fe73fc |
warn "failed to umount $tmpmnt"
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
done
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
rmdir "$tmpmnt" || true
|
|
rpm-build |
fe73fc |
if [ "$found" ]; then
|
|
rpm-build |
fe73fc |
exit 0
|
|
rpm-build |
fe73fc |
else
|
|
rpm-build |
fe73fc |
exit 1
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
fi
|
|
rpm-build |
fe73fc |
|
|
Packit |
d86cd3 |
if type grub-mount >/dev/null 2>&1 && \
|
|
Packit Service |
8d4c46 |
type grub2-probe >/dev/null 2>&1 && \
|
|
Packit |
d86cd3 |
grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
|
|
Packit |
d86cd3 |
mounted=1
|
|
Packit Service |
8d4c46 |
type="$(grub2-probe -d "$partition" -t fs)" || true
|
|
Packit |
d86cd3 |
if [ "$type" ]; then
|
|
Packit |
d86cd3 |
debug "mounted using GRUB $type filesystem driver"
|
|
Packit |
d86cd3 |
else
|
|
Packit |
d86cd3 |
debug "mounted using GRUB, but unknown filesystem?"
|
|
Packit |
d86cd3 |
type=fuseblk
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
elif dm_device="$(do_dmsetup osprober "$partition")" && \
|
|
Packit |
d86cd3 |
[ "$dm_device" ]; then
|
|
Packit |
d86cd3 |
for type in $types $delaytypes; do
|
|
Packit |
d86cd3 |
if mountinfo=`mount -o ro -t "$type" "$dm_device" "$tmpmnt" 2>&1;; then
|
|
Packit |
d86cd3 |
debug "mounted as $type filesystem"
|
|
Packit |
d86cd3 |
mounted=1
|
|
Packit |
d86cd3 |
break
|
|
Packit |
d86cd3 |
else
|
|
Packit |
d86cd3 |
debug "mounting $dm_device ($partition) as $type failed: $mountinfo"
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
done
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
|
|
Packit |
d86cd3 |
if [ "$mounted" ]; then
|
|
Packit Service |
8d4c46 |
for test in /usr/libexec/os-probes/mounted/*; do
|
|
Packit |
d86cd3 |
debug "running subtest $test"
|
|
Packit |
d86cd3 |
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
Packit |
d86cd3 |
if "$test" "$partition" "$tmpmnt" "$type"; then
|
|
Packit |
d86cd3 |
debug "os found by subtest $test"
|
|
Packit |
d86cd3 |
do_unmount
|
|
Packit |
d86cd3 |
exit 0
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
done
|
|
Packit |
d86cd3 |
fi
|
|
Packit |
d86cd3 |
do_unmount
|
|
Packit |
d86cd3 |
|
|
Packit |
d86cd3 |
# No tests found anything.
|
|
Packit |
d86cd3 |
exit 1
|