05efi 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. # Detects all Microsoft OSes on a collection of partitions.
  3. . /usr/share/os-prober/common.sh
  4. partition="$1"
  5. mpoint="$2"
  6. type="$3"
  7. # This file is for UEFI platform only
  8. if [ ! -d /sys/firmware/efi ] || [ -f /var/lib/partman/ignore_uefi ]; then
  9. debug "Not on UEFI platform"
  10. exit 1
  11. fi
  12. # Weed out stuff that doesn't apply to us
  13. case "$type" in
  14. vfat) debug "$1 is a FAT32 partition" ;;
  15. msdos) debug "$1 is a FAT16 partition" ;;
  16. fat) debug "$1 is a FAT partition (mounted by GRUB)" ;;
  17. *) debug "$1 is $type partition: exiting"; exit 1 ;;
  18. esac
  19. if type udevadm > /dev/null 2>&1; then
  20. udevinfo () {
  21. udevadm info "$@"
  22. }
  23. fi
  24. if type udevinfo > /dev/null 2>&1; then
  25. # Skip virtual devices
  26. if udevinfo -q path -n $partition | grep -q /virtual/; then
  27. debug "$1 is virtual device: exiting"
  28. exit 1
  29. fi
  30. eval "$(udevinfo -q property -n "$partition" | grep -E '^ID_PART_ENTRY_(TYPE|SCHEME)=')"
  31. debug "$partition partition scheme is $ID_PART_ENTRY_SCHEME"
  32. debug "$partition partition type is $ID_PART_ENTRY_TYPE"
  33. if [ -z "$ID_PART_ENTRY_TYPE" -o -z "$ID_PART_ENTRY_SCHEME" -o \
  34. \( "$ID_PART_ENTRY_SCHEME" != gpt -a "$ID_PART_ENTRY_SCHEME" != msdos \) -o \
  35. \( "$ID_PART_ENTRY_SCHEME" = gpt -a "$ID_PART_ENTRY_TYPE" != c12a7328-f81f-11d2-ba4b-00a0c93ec93b \) -o \
  36. \( "$ID_PART_ENTRY_SCHEME" = msdos -a "$ID_PART_ENTRY_TYPE" != 0xef \) ]; then
  37. debug "$partition is not a ESP partition: exiting"
  38. exit 1
  39. fi
  40. else
  41. debug "udevinfo and udevadm missing - cannot check partition type"
  42. fi
  43. efi=$(item_in_dir efi "$mpoint")
  44. if [ -z "$efi" ]; then
  45. debug "$mpoint does not have /EFI directory: exiting"
  46. exit 1
  47. fi
  48. ret=1
  49. for test in /usr/lib/os-probes/mounted/efi/*; do
  50. debug "running subtest $test"
  51. if [ -f "$test" ] && [ -x "$test" ]; then
  52. entry=$("$test" "$mpoint/$efi")
  53. if [ -n "$entry" ]; then
  54. debug "bootloader $entry found by subtest $test"
  55. ret=0
  56. result "${partition}@/$efi/${entry}:efi"
  57. fi
  58. fi
  59. done
  60. exit $ret