90fallback 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. # Fallback in case nothing else works. Look for vmlinu[xz] file in root and
  3. # /boot, see if there is a matching initrd, and wing it.
  4. . /usr/share/os-prober/common.sh
  5. set -e
  6. partition="$1"
  7. bootpart="$2"
  8. mpoint="$3"
  9. type="$4"
  10. mappedpartition=$(mapdevfs "$partition" 2>/dev/null) || mappedpartition="$partition"
  11. exitcode=1
  12. for kernpat in /vmlinuz /vmlinux /boot/vmlinuz /boot/vmlinux "/boot/vmlinuz*" \
  13. "/boot/vmlinux*" "/vmlinuz*" "/vmlinux*" "/kernel-*" "/boot/kernel-*"; do
  14. if echo "$kernpat" | grep -q boot/; then
  15. kernbootpart="$bootpart"
  16. else
  17. kernbootpart="$partition"
  18. fi
  19. for kernfile in $(eval ls -t "$mpoint$kernpat" 2>/dev/null); do
  20. kernbasefile=$(echo "$kernfile" | sed "s!^$mpoint!!")
  21. if [ -f "$kernfile" ] && [ ! -L "$kernfile" ]; then
  22. initrdname=$(echo "$kernfile" | sed "s/vmlinu[zx]/initrd\*/")
  23. # Yellow Dog Linux appends .img to it.
  24. initrdname1="${initrdname}.img"
  25. # Arch Linux names its initrds weirdly. We take
  26. # some care here to avoid false positives on other
  27. # systems, since kernel.img could conceivably be a
  28. # kernel itself.
  29. initrdname2=$(echo "$kernfile" | sed -n 's/vmlinu[zx]\([0-9][0-9]*\)/kernel\1/p' | sed 's/$/.img/')
  30. # Dracut initramfses are named differently again.
  31. initrdname3=$(echo "$kernfile" | sed "s/vmlinu[zx]/initramfs\*/" | sed 's/$/.img/')
  32. # And Gentoo's also
  33. initrdname4=$(echo "$kernfile" | sed "s/kernel/initramfs\*/")
  34. foundinitrd=0
  35. for initrd in $(eval ls "$initrdname" "$initrdname1" "$initrdname2" "$initrdname3" "$initrdname4" 2>/dev/null); do
  36. if [ "$initrd" != "$kernfile" ] && [ -f "$initrd" ] && [ ! -L "$initrd" ]; then
  37. initrd=$(echo "$initrd" | sed "s!^$mpoint!!")
  38. result "$partition:$kernbootpart::$kernbasefile:$initrd:root=$mappedpartition"
  39. exitcode=0
  40. foundinitrd=1
  41. fi
  42. done
  43. if [ "$foundinitrd" = 0 ]; then
  44. result "$partition:$kernbootpart::$kernbasefile::root=$mappedpartition"
  45. exitcode=0
  46. fi
  47. fi
  48. done
  49. done
  50. exit "$exitcode"