[2cd8344] | 1 | #!/bin/sh |
---|
| 2 | # Sub-tests that require a mounted partition. |
---|
| 3 | set -e |
---|
| 4 | partition="$1" |
---|
| 5 | |
---|
| 6 | . /usr/share/os-prober/common.sh |
---|
| 7 | |
---|
| 8 | types="$(fs_type "$partition")" || types=NOT-DETECTED |
---|
| 9 | if [ "$types" = NOT-DETECTED ] || [ -z "$types" ]; then |
---|
| 10 | debug "$1 type not recognised; skipping" |
---|
| 11 | exit 0 |
---|
| 12 | elif [ "$types" = swap ]; then |
---|
| 13 | debug "$1 is a swap partition; skipping" |
---|
| 14 | exit 0 |
---|
| 15 | elif [ "$types" = LVM2_member ]; then |
---|
| 16 | debug "$1 is a LVM member partition; skipping" |
---|
| 17 | exit 0 |
---|
| 18 | elif [ "$types" = crypto_LUKS ]; then |
---|
| 19 | debug "$1 is a LUKS partition; skipping" |
---|
| 20 | exit 0 |
---|
| 21 | elif [ "$types" = ntfs ]; then |
---|
| 22 | if type ntfs-3g >/dev/null 2>&1; then |
---|
| 23 | types='ntfs-3g ntfs' |
---|
| 24 | fi |
---|
| 25 | elif [ -z "$types" ]; then |
---|
| 26 | if type cryptsetup >/dev/null 2>&1 && \ |
---|
| 27 | cryptsetup luksDump "$partition" >/dev/null 2>&1; then |
---|
| 28 | debug "$1 is a LUKS partition; skipping" |
---|
| 29 | exit 0 |
---|
| 30 | fi |
---|
| 31 | for type in $(grep -v nodev /proc/filesystems); do |
---|
| 32 | # hfsplus filesystems are mountable as hfs. Try hfs last so |
---|
| 33 | # that we can tell the difference. |
---|
| 34 | if [ "$type" = hfs ]; then |
---|
| 35 | delaytypes="${delaytypes:+$delaytypes }$type" |
---|
| 36 | elif [ "$type" = fuseblk ]; then |
---|
| 37 | if type ntfs-3g >/dev/null 2>&1; then |
---|
| 38 | types="${types:+$types }ntfs-3g" |
---|
| 39 | fi |
---|
| 40 | else |
---|
| 41 | types="${types:+$types }$type" |
---|
| 42 | fi |
---|
| 43 | done |
---|
| 44 | fi |
---|
| 45 | |
---|
| 46 | tmpmnt=/var/lib/os-prober/mount |
---|
| 47 | if [ ! -d "$tmpmnt" ]; then |
---|
| 48 | mkdir "$tmpmnt" |
---|
| 49 | fi |
---|
| 50 | |
---|
| 51 | mounted= |
---|
| 52 | if type grub-mount >/dev/null 2>&1 && \ |
---|
| 53 | type grub-probe >/dev/null 2>&1 && \ |
---|
| 54 | grub-mount "$partition" "$tmpmnt" 2>/dev/null; then |
---|
| 55 | mounted=1 |
---|
| 56 | type="$(grub-probe -d "$partition" -t fs)" || true |
---|
| 57 | if [ "$type" ]; then |
---|
| 58 | debug "mounted using GRUB $type filesystem driver" |
---|
| 59 | else |
---|
| 60 | debug "mounted using GRUB, but unknown filesystem?" |
---|
| 61 | type=fuseblk |
---|
| 62 | fi |
---|
| 63 | else |
---|
| 64 | echo "Failed to probe $partition for filesystem type" >&2 |
---|
| 65 | exit 1 |
---|
| 66 | fi |
---|
| 67 | |
---|
| 68 | if [ "$mounted" ]; then |
---|
| 69 | for test in /usr/lib/os-probes/mounted/*; do |
---|
| 70 | debug "running subtest $test" |
---|
| 71 | if [ -f "$test" ] && [ -x "$test" ]; then |
---|
| 72 | if "$test" "$partition" "$tmpmnt" "$type"; then |
---|
| 73 | debug "os found by subtest $test" |
---|
| 74 | if ! umount "$tmpmnt"; then |
---|
| 75 | warn "failed to umount $tmpmnt" |
---|
| 76 | fi |
---|
| 77 | case "$type" in |
---|
| 78 | btrfs) |
---|
| 79 | # umount to account for the bind-mount |
---|
| 80 | if [ -x "$tmpmnt/@/lib" ] && \ |
---|
| 81 | ! umount $tmpmnt; then |
---|
| 82 | warn "failed to umount $tmpmnt" |
---|
| 83 | fi |
---|
| 84 | ;; |
---|
| 85 | esac |
---|
| 86 | rmdir "$tmpmnt" || true |
---|
| 87 | exit 0 |
---|
| 88 | fi |
---|
| 89 | fi |
---|
| 90 | done |
---|
| 91 | if ! umount "$tmpmnt"; then |
---|
| 92 | warn "failed to umount $tmpmnt" |
---|
| 93 | fi |
---|
| 94 | fi |
---|
| 95 | |
---|
| 96 | rmdir "$tmpmnt" || true |
---|
| 97 | |
---|
| 98 | # No tests found anything. |
---|
| 99 | exit 1 |
---|