50lilo 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/sh
  2. . /usr/share/os-prober/common.sh
  3. set -e
  4. partition="$1"
  5. bootpart="$2"
  6. mpoint="$3"
  7. type="$4"
  8. found_item=0
  9. title=""
  10. rootdev=""
  11. kernel=""
  12. parameters=""
  13. initrd=""
  14. read_only=""
  15. added_parameters=0
  16. default_rootdev=""
  17. default_kernel=""
  18. default_parameters=""
  19. default_initrd=""
  20. default_read_only=""
  21. dequote () {
  22. item="${1%\"}"
  23. echo "${item#\"}"
  24. }
  25. addparams () {
  26. # Any parameters we find replace the default parameters, but
  27. # otherwise append.
  28. if [ "$added_parameters" = 0 ]; then
  29. parameters="$1"
  30. added_parameters=1
  31. else
  32. parameters="${parameters:+$parameters }$1"
  33. fi
  34. }
  35. recordstanza () {
  36. if [ -n "$kernel" ] && [ -n "$title" ]; then
  37. if [ -e "$mpoint/$kernel" ] && [ -e "$mpoint/$initrd" ]; then
  38. if [ "$read_only" ]; then
  39. parameters="ro $parameters"
  40. fi
  41. if [ "$rootdev" ]; then
  42. parameters="root=$rootdev $parameters"
  43. fi
  44. parameters="${parameters% }"
  45. result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
  46. found_item=1
  47. else
  48. debug "cannot find $kernel or $initrd, not recording"
  49. fi
  50. title=""
  51. rootdev="$default_rootdev"
  52. kernel="$default_kernel"
  53. parameters="$default_parameters"
  54. initrd="$default_initrd"
  55. read_only="$default_read_only"
  56. added_parameters=0
  57. else
  58. # Everything before set default values.
  59. default_rootdev="$rootdev"
  60. default_kernel="$kernel"
  61. default_parameters="$parameters"
  62. default_initrd="$initrd"
  63. default_read_only="$read_only"
  64. fi
  65. }
  66. parse_lilo_conf () {
  67. mpoint="$1"
  68. rootpart="$2"
  69. bootpart="$3"
  70. IFS=" ="
  71. while read line; do
  72. debug "parsing: $line"
  73. set -f
  74. set -- $line
  75. set +f
  76. case "$1" in
  77. root)
  78. rootdev=$(dequote "$2")
  79. ;;
  80. image)
  81. recordstanza
  82. # Dereference if symbolic link
  83. kernel="$(readlink -f "$(dequote "$2")")"
  84. ;;
  85. append)
  86. addparams "$(dequote "${line#append=}")"
  87. ;;
  88. initrd)
  89. # Dereference if symbolic link
  90. initrd="$(readlink -f "$(dequote "$2")")"
  91. ;;
  92. label)
  93. shift 1
  94. title="$(dequote "$*" | sed -e 's/:/ /g')"
  95. ;;
  96. other)
  97. recordstanza
  98. ;;
  99. read-only)
  100. read_only=1
  101. ;;
  102. vga)
  103. addparams "$line"
  104. ;;
  105. esac
  106. done
  107. recordstanza
  108. }
  109. if [ -e "$mpoint/etc/lilo.conf" ]; then
  110. debug "parsing lilo.conf"
  111. parse_lilo_conf "$mpoint" "$partition" "$bootpart" < "$mpoint/etc/lilo.conf"
  112. fi
  113. if [ "$found_item" = 0 ]; then
  114. exit 1
  115. else
  116. exit 0
  117. fi