10_kfreebsd.in 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
  5. #
  6. # GRUB is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GRUB is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. prefix="@prefix@"
  19. exec_prefix="@exec_prefix@"
  20. datarootdir="@datarootdir@"
  21. . "$pkgdatadir/grub-mkconfig_lib"
  22. export TEXTDOMAIN=@PACKAGE@
  23. export TEXTDOMAINDIR="@localedir@"
  24. CLASS="--class os"
  25. case "${GRUB_DISTRIBUTOR}" in
  26. Debian)
  27. OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
  28. CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') --class gnu-kfreebsd --class gnu ${CLASS}"
  29. ;;
  30. *)
  31. OS="FreeBSD"
  32. CLASS="--class freebsd --class bsd ${CLASS}"
  33. ;;
  34. esac
  35. load_kfreebsd_module ()
  36. {
  37. mod="$1"
  38. allow_fail="$2"
  39. if ! test -e "${module_dir}/${mod}.ko" ; then
  40. if [ "${allow_fail}" = "true" ] ; then
  41. # Return silently
  42. return
  43. else
  44. # Print an error and fail.
  45. ls "${module_dir}/${mod}.ko" > /dev/null
  46. fi
  47. fi
  48. if [ -z "${prepare_module_dir_cache}" ]; then
  49. prepare_module_dir_cache="$(prepare_grub_to_access_device $(${grub_probe} -t device "${module_dir}") | grub_add_tab)"
  50. fi
  51. printf '%s\n' "${prepare_module_dir_cache}"
  52. cat << EOF
  53. kfreebsd_module_elf ${module_dir_rel}/${mod}.ko
  54. EOF
  55. }
  56. title_correction_code=
  57. kfreebsd_entry ()
  58. {
  59. os="$1"
  60. version="$2"
  61. type="$3"
  62. args="$4"
  63. if [ -z "$boot_device_id" ]; then
  64. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  65. fi
  66. if [ x$type != xsimple ] ; then
  67. if [ x$type = xrecovery ] ; then
  68. title="$(gettext_printf "%s, with kFreeBSD %s (recovery mode)" "${os}" "${version}")"
  69. else
  70. title="$(gettext_printf "%s, with kFreeBSD %s" "${os}" "${version}")"
  71. fi
  72. replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
  73. if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
  74. quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
  75. title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
  76. grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "kfreebsd-advanced-$boot_device_id>kfreebsd-$version-$type-$boot_device_id")"
  77. fi
  78. echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  79. else
  80. echo "menuentry '$(echo "$OS" | grub_quote)' ${CLASS} \$menuentry_id_option 'kfreebsd-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
  81. fi
  82. if [ x$type != xrecovery ] ; then
  83. save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
  84. fi
  85. if [ -z "${prepare_boot_cache}" ]; then
  86. prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
  87. fi
  88. printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
  89. message="$(gettext_printf "Loading kernel of FreeBSD %s ..." ${version})"
  90. sed "s/^/$submenu_indentation/" << EOF
  91. echo '$(echo "$message" | grub_quote)'
  92. kfreebsd ${rel_dirname}/${basename} ${args}
  93. EOF
  94. if test -n "${devices}" ; then
  95. sed "s/^/$submenu_indentation/" << EOF
  96. kfreebsd_loadenv ${devices_rel_dirname}/${devices_basename}
  97. EOF
  98. fi
  99. load_kfreebsd_module acpi true
  100. for abstraction in dummy $(${grub_probe} -t abstraction --device ${GRUB_DEVICE}) ; do
  101. case $abstraction in
  102. lvm) load_kfreebsd_module geom_linux_lvm false ;;
  103. esac
  104. done
  105. case "${kfreebsd_fs}" in
  106. zfs)
  107. load_kfreebsd_module opensolaris false
  108. ls "/boot/zfs/zpool.cache" > /dev/null
  109. printf '%s\n' "${prepare_boot_cache}"
  110. sed "s/^/$submenu_indentation/" << EOF
  111. kfreebsd_module $(make_system_path_relative_to_its_root /boot)/zfs/zpool.cache type=/boot/zfs/zpool.cache
  112. EOF
  113. ;;
  114. esac
  115. if [ x${kfreebsd_fs} = xufs ]; then
  116. load_kfreebsd_module ${kfreebsd_fs} true | sed "s/^/$submenu_indentation/"
  117. else
  118. load_kfreebsd_module ${kfreebsd_fs} false | sed "s/^/$submenu_indentation/"
  119. fi
  120. sed "s/^/$submenu_indentation/" << EOF
  121. set kFreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_device}
  122. set kFreeBSD.vfs.root.mountfrom.options=rw
  123. }
  124. EOF
  125. }
  126. list=
  127. for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
  128. if grub_file_is_not_garbage "$i" ; then
  129. list="$list $i"
  130. fi
  131. done
  132. prepare_boot_cache=
  133. boot_device_id=
  134. title_correction_code=
  135. # Extra indentation to add to menu entries in a submenu. We're not in a submenu
  136. # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
  137. submenu_indentation=""
  138. is_top_level=true
  139. while [ "x$list" != "x" ] ; do
  140. kfreebsd=`version_find_latest $list`
  141. gettext_printf "Found kernel of FreeBSD: %s\n" "$kfreebsd" >&2
  142. basename=`basename $kfreebsd`
  143. dirname=`dirname $kfreebsd`
  144. rel_dirname=`make_system_path_relative_to_its_root $dirname`
  145. if [ -f /boot/device.hints ] ; then
  146. devices=/boot/device.hints
  147. devices_basename=`basename $devices`
  148. devices_dirname=`dirname $devices`
  149. devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
  150. fi
  151. case ${GRUB_FS} in
  152. ufs1 | ufs2) kfreebsd_fs=ufs ;;
  153. ext2) kfreebsd_fs=ext2fs ;;
  154. *) kfreebsd_fs=${GRUB_FS} ;;
  155. esac
  156. case ${GRUB_FS} in
  157. zfs)
  158. # zpool name
  159. kfreebsd_device=$(${grub_probe} -t fs_label --device ${GRUB_DEVICE})
  160. # filesystem name (empty string for the main filesystem)
  161. kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s,/*@$,,")"
  162. ;;
  163. *)
  164. kfreebsd_device=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
  165. # Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
  166. # as an UUID
  167. if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
  168. && ! (cat /etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
  169. | grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then
  170. kfreebsd_device=${GRUB_DEVICE}
  171. fi
  172. ;;
  173. esac
  174. version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
  175. alt_version=`echo $version | sed -e "s,\.old$,,g"`
  176. module_dir=
  177. for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
  178. "/boot/kernel"; do
  179. if test -e "$i" ; then
  180. module_dir="$i"
  181. break
  182. fi
  183. done
  184. if test -n "${module_dir}" ; then
  185. gettext_printf "Found kernel module directory: %s\n" "${module_dir}" >&2
  186. module_dir_rel=$(make_system_path_relative_to_its_root $module_dir)
  187. fi
  188. if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
  189. kfreebsd_entry "${OS}" "${version}" simple
  190. submenu_indentation="$grub_tab"
  191. if [ -z "$boot_device_id" ]; then
  192. boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
  193. fi
  194. # TRANSLATORS: %s is replaced with an OS name
  195. echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'kfreebsd-advanced-$boot_device_id' {"
  196. is_top_level=false
  197. fi
  198. kfreebsd_entry "${OS}" "${version}" advanced
  199. if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  200. kfreebsd_entry "${OS}" "${version}" recovery "-s"
  201. fi
  202. list=`echo $list | tr ' ' '\n' | fgrep -vx "$kfreebsd" | tr '\n' ' '`
  203. done
  204. # If at least one kernel was found, then we need to
  205. # add a closing '}' for the submenu command.
  206. if [ x"$is_top_level" != xtrue ]; then
  207. echo '}'
  208. fi
  209. echo "$title_correction_code"