50mounted-tests 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. # Sub-tests that require a mounted partition.
  3. . /usr/share/os-prober/common.sh
  4. set -e
  5. do_unmount() {
  6. if [ "$mounted" ]; then
  7. umount "$tmpmnt/boot" 2>/dev/null || true
  8. if ! umount "$tmpmnt"; then
  9. warn "failed to umount $tmpmnt"
  10. fi
  11. fi
  12. for dm_device in $dm_devices; do
  13. if [ -e "$dm_device" ]; then
  14. debug "remove device mapper device $dm_device"
  15. dmsetup remove $dm_device
  16. fi
  17. done
  18. rmdir "$tmpmnt" || true
  19. }
  20. partition="$1"
  21. types="$(fs_type "$partition")"
  22. if [ "$types" = NOT-DETECTED ]; then
  23. debug "$1 type not recognised; skipping"
  24. exit 0
  25. elif [ "$types" = swap ]; then
  26. debug "$1 is a swap partition; skipping"
  27. exit 0
  28. elif [ "$types" = crypto_LUKS ]; then
  29. debug "$1 is a LUKS partition; skipping"
  30. exit 0
  31. elif [ "$types" = ntfs ]; then
  32. if type ntfs-3g >/dev/null 2>&1; then
  33. types='ntfs-3g ntfs'
  34. fi
  35. elif [ -z "$types" ]; then
  36. if is_dos_extended_partition "$partition"; then
  37. debug "$1 looks like an extended dos partition; skipping"
  38. exit 0
  39. fi
  40. if type cryptsetup >/dev/null 2>&1 && \
  41. cryptsetup luksDump "$partition" >/dev/null 2>&1; then
  42. debug "$1 is a LUKS partition; skipping"
  43. exit 0
  44. fi
  45. types="$(grep -v nodev /proc/filesystems)"
  46. fi
  47. tmpmnt=/var/lib/os-prober/mount
  48. if [ ! -d "$tmpmnt" ]; then
  49. mkdir "$tmpmnt"
  50. fi
  51. mounted=
  52. dm_devices=
  53. if type grub-mount >/dev/null 2>&1 && \
  54. type grub-probe >/dev/null 2>&1 && \
  55. grub-mount "$partition" "$tmpmnt" 2>/dev/null; then
  56. mounted=1
  57. type="$(grub-probe -d "$partition" -t fs)"
  58. [ "$type" ] || type=fuseblk
  59. elif dm_device="$(do_dmsetup osprober-linux "$partition")" && \
  60. [ "$dm_device" ]; then
  61. dm_devices="$dm_device"
  62. for type in $types; do
  63. if mountinfo=`mount -o ro -t "$type" "$dm_device" "$tmpmnt" 2>&1`; then
  64. debug "mounted as $type filesystem"
  65. mounted=1
  66. case "$type" in
  67. btrfs)
  68. if [ -x "$tmpmnt/@/lib" ] && \
  69. ! mount --bind "$tmpmnt/@" "$tmpmnt"; then
  70. warn "failed to mount btrfs subvolume @ on $partition"
  71. if ! umount $tmpmnt; then
  72. warn "failed to umount $tmpmnt"
  73. fi
  74. mounted=
  75. fi
  76. ;;
  77. esac
  78. break
  79. else
  80. debug "mounting $dm_device ($partition) as $type failed: $mountinfo"
  81. fi
  82. done
  83. fi
  84. if [ "$mounted" ]; then
  85. linux_mount_boot "$partition" "$tmpmnt"
  86. bootpart="${mountboot%% *}"
  87. mounted="${mountboot#* }"
  88. if [ "$dm_device" ]; then
  89. dm_devices="$dm_device $dm_devices"
  90. fi
  91. for test in /usr/lib/linux-boot-probes/mounted/*; do
  92. if [ -f "$test" ] && [ -x "$test" ]; then
  93. debug "running $test $partition $bootpart $tmpmnt $type"
  94. if $test "$partition" "$bootpart" "$tmpmnt" "$type"; then
  95. debug "$test succeeded"
  96. do_unmount
  97. exit 0
  98. fi
  99. fi
  100. done
  101. fi
  102. do_unmount
  103. # No tests found anything.
  104. exit 1