00_header 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2006,2007,2008,2009,2010 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="/usr"
  19. exec_prefix="/usr"
  20. datarootdir="/usr/share"
  21. grub_lang=`echo $LANG | cut -d . -f 1`
  22. grubdir="`echo "/boot/grub" | sed 's,//*,/,g'`"
  23. quick_boot="1"
  24. export TEXTDOMAIN=grub
  25. export TEXTDOMAINDIR="${datarootdir}/locale"
  26. . "$pkgdatadir/grub-mkconfig_lib"
  27. # Do this as early as possible, since other commands might depend on it.
  28. # (e.g. the `loadfont' command might need lvm or raid modules)
  29. for i in ${GRUB_PRELOAD_MODULES} ; do
  30. echo "insmod $i"
  31. done
  32. if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
  33. if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
  34. if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
  35. if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
  36. if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
  37. if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
  38. if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
  39. cat << EOF
  40. if [ -s \$prefix/grubenv ]; then
  41. set have_grubenv=true
  42. load_env
  43. fi
  44. EOF
  45. cat <<EOF
  46. if [ "\${initrdfail}" = 2 ]; then
  47. set initrdfail=
  48. elif [ "\${initrdfail}" = 1 ]; then
  49. set next_entry="\${prev_entry}"
  50. set prev_entry=
  51. save_env prev_entry
  52. if [ "\${next_entry}" ]; then
  53. set initrdfail=2
  54. fi
  55. fi
  56. EOF
  57. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  58. cat <<EOF
  59. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  60. set default="${GRUB_DEFAULT_BUTTON}"
  61. elif [ "\${next_entry}" ] ; then
  62. set default="\${next_entry}"
  63. set next_entry=
  64. save_env next_entry
  65. set boot_once=true
  66. else
  67. set default="${GRUB_DEFAULT}"
  68. fi
  69. EOF
  70. else
  71. cat <<EOF
  72. if [ "\${next_entry}" ] ; then
  73. set default="\${next_entry}"
  74. set next_entry=
  75. save_env next_entry
  76. set boot_once=true
  77. else
  78. set default="${GRUB_DEFAULT}"
  79. fi
  80. EOF
  81. fi
  82. cat <<EOF
  83. if [ x"\${feature_menuentry_id}" = xy ]; then
  84. menuentry_id_option="--id"
  85. else
  86. menuentry_id_option=""
  87. fi
  88. export menuentry_id_option
  89. if [ "\${prev_saved_entry}" ]; then
  90. set saved_entry="\${prev_saved_entry}"
  91. save_env saved_entry
  92. set prev_saved_entry=
  93. save_env prev_saved_entry
  94. set boot_once=true
  95. fi
  96. function savedefault {
  97. if [ -z "\${boot_once}" ]; then
  98. saved_entry="\${chosen}"
  99. save_env saved_entry
  100. fi
  101. }
  102. EOF
  103. cat <<"EOF"
  104. function initrdfail {
  105. if [ -n "${have_grubenv}" ]; then if [ -n "${partuuid}" ]; then
  106. if [ -z "${initrdfail}" ]; then
  107. set initrdfail=1
  108. if [ -n "${boot_once}" ]; then
  109. set prev_entry="${default}"
  110. save_env prev_entry
  111. fi
  112. fi
  113. save_env initrdfail
  114. fi; fi
  115. }
  116. EOF
  117. if [ "$quick_boot" = 1 ]; then
  118. cat <<EOF
  119. function recordfail {
  120. set recordfail=1
  121. EOF
  122. check_writable () {
  123. abstractions="$(grub-probe --target=abstraction "${grubdir}")"
  124. for abstraction in $abstractions; do
  125. case "$abstraction" in
  126. diskfilter | lvm)
  127. cat <<EOF
  128. # GRUB lacks write support for $abstraction, so recordfail support is disabled.
  129. EOF
  130. return 1
  131. ;;
  132. esac
  133. done
  134. FS="$(grub-probe --target=fs "${grubdir}")"
  135. case "$FS" in
  136. btrfs | cpiofs | newc | odc | romfs | squash4 | tarfs | zfs)
  137. cat <<EOF
  138. # GRUB lacks write support for $FS, so recordfail support is disabled.
  139. EOF
  140. return 1
  141. ;;
  142. esac
  143. cat <<EOF
  144. if [ -n "\${have_grubenv}" ]; then if [ -z "\${boot_once}" ]; then save_env recordfail; fi; fi
  145. EOF
  146. }
  147. if ! check_writable; then
  148. recordfail_broken=1
  149. fi
  150. cat <<EOF
  151. }
  152. EOF
  153. fi
  154. cat <<EOF
  155. function load_video {
  156. EOF
  157. if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
  158. cat <<EOF
  159. insmod ${GRUB_VIDEO_BACKEND}
  160. EOF
  161. else
  162. # If all_video.mod isn't available load all modules available
  163. # with versions prior to introduction of all_video.mod
  164. cat <<EOF
  165. if [ x\$feature_all_video_module = xy ]; then
  166. insmod all_video
  167. else
  168. insmod efi_gop
  169. insmod efi_uga
  170. insmod ieee1275_fb
  171. insmod vbe
  172. insmod vga
  173. insmod video_bochs
  174. insmod video_cirrus
  175. fi
  176. EOF
  177. fi
  178. cat <<EOF
  179. }
  180. EOF
  181. serial=0;
  182. gfxterm=0;
  183. for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
  184. if [ xserial = "x$x" ]; then
  185. serial=1;
  186. fi
  187. if [ xgfxterm = "x$x" ]; then
  188. gfxterm=1;
  189. fi
  190. done
  191. if [ "x$serial" = x1 ]; then
  192. if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
  193. grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
  194. GRUB_SERIAL_COMMAND=serial
  195. fi
  196. echo "${GRUB_SERIAL_COMMAND}"
  197. fi
  198. if [ "x$gfxterm" = x1 ]; then
  199. if [ -n "$GRUB_FONT" ] ; then
  200. # Make the font accessible
  201. prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
  202. cat << EOF
  203. if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
  204. EOF
  205. else
  206. for dir in "${pkgdatadir}" "`echo '/boot/grub' | sed "s,//*,/,g"`" /usr/share/grub ; do
  207. for basename in unicode unifont ascii; do
  208. path="${dir}/${basename}.pf2"
  209. if is_path_readable_by_grub "${path}" > /dev/null ; then
  210. font_path="${path}"
  211. else
  212. continue
  213. fi
  214. break 2
  215. done
  216. done
  217. if [ -n "${font_path}" ] ; then
  218. cat << EOF
  219. if [ x\$feature_default_font_path = xy ] ; then
  220. font=unicode
  221. else
  222. EOF
  223. # Make the font accessible
  224. prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
  225. cat << EOF
  226. font="`make_system_path_relative_to_its_root "${font_path}"`"
  227. fi
  228. if loadfont \$font ; then
  229. EOF
  230. else
  231. cat << EOF
  232. if loadfont unicode ; then
  233. EOF
  234. fi
  235. fi
  236. cat << EOF
  237. set gfxmode=${GRUB_GFXMODE}
  238. load_video
  239. insmod gfxterm
  240. EOF
  241. # Gettext variables and module
  242. if [ "x${LANG}" != "xC" ] && [ "x${LANG}" != "x" ]; then
  243. cat << EOF
  244. set locale_dir=\$prefix/locale
  245. set lang=${grub_lang}
  246. insmod gettext
  247. EOF
  248. fi
  249. cat <<EOF
  250. fi
  251. EOF
  252. fi
  253. case x${GRUB_TERMINAL_INPUT} in
  254. x)
  255. # Just use the native terminal
  256. ;;
  257. x*)
  258. cat << EOF
  259. terminal_input ${GRUB_TERMINAL_INPUT}
  260. EOF
  261. ;;
  262. esac
  263. case x${GRUB_TERMINAL_OUTPUT} in
  264. x)
  265. # Just use the native terminal
  266. ;;
  267. x*)
  268. cat << EOF
  269. terminal_output ${GRUB_TERMINAL_OUTPUT}
  270. EOF
  271. ;;
  272. esac
  273. if [ "x$gfxterm" = x1 ]; then
  274. if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
  275. && is_path_readable_by_grub "$GRUB_THEME"; then
  276. gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2
  277. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
  278. cat << EOF
  279. insmod gfxmenu
  280. EOF
  281. themedir="`dirname "$GRUB_THEME"`"
  282. for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
  283. if [ -f "$x" ]; then
  284. cat << EOF
  285. loadfont (\$root)`make_system_path_relative_to_its_root $x`
  286. EOF
  287. fi
  288. done
  289. if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
  290. cat << EOF
  291. insmod jpeg
  292. EOF
  293. fi
  294. if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
  295. cat << EOF
  296. insmod png
  297. EOF
  298. fi
  299. if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
  300. cat << EOF
  301. insmod tga
  302. EOF
  303. fi
  304. cat << EOF
  305. set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
  306. export theme
  307. EOF
  308. elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
  309. && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
  310. gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
  311. case "$GRUB_BACKGROUND" in
  312. *.png) reader=png ;;
  313. *.tga) reader=tga ;;
  314. *.jpg|*.jpeg) reader=jpeg ;;
  315. *) gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
  316. esac
  317. prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
  318. cat << EOF
  319. insmod $reader
  320. background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
  321. EOF
  322. fi
  323. fi
  324. make_timeout ()
  325. {
  326. cat << EOF
  327. if [ "\${recordfail}" = 1 ] ; then
  328. set timeout=${GRUB_RECORDFAIL_TIMEOUT:-3}
  329. else
  330. EOF
  331. if [ "x${3}" != "x" ] ; then
  332. timeout="${2}"
  333. style="${3}"
  334. elif [ "x${1}" != "x" ] && \
  335. ([ "$quick_boot" = 1 ] || [ "x${1}" != "x0" ]) ; then
  336. # Handle the deprecated GRUB_HIDDEN_TIMEOUT scheme.
  337. timeout="${1}"
  338. if [ "x${2}" != "x0" ] ; then
  339. grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
  340. fi
  341. if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
  342. style="hidden"
  343. verbose=
  344. else
  345. style="countdown"
  346. verbose=" --verbose"
  347. fi
  348. else
  349. # No hidden timeout, so treat as GRUB_TIMEOUT_STYLE=menu
  350. timeout="${2}"
  351. style="menu"
  352. fi
  353. cat << EOF
  354. if [ x\$feature_timeout_style = xy ] ; then
  355. set timeout_style=${style}
  356. set timeout=${timeout}
  357. EOF
  358. if [ "x${style}" = "xmenu" ] ; then
  359. cat << EOF
  360. # Fallback normal timeout code in case the timeout_style feature is
  361. # unavailable.
  362. else
  363. set timeout=${timeout}
  364. EOF
  365. else
  366. cat << EOF
  367. # Fallback hidden-timeout code in case the timeout_style feature is
  368. # unavailable.
  369. elif sleep${verbose} --interruptible ${timeout} ; then
  370. set timeout=0
  371. EOF
  372. fi
  373. cat << EOF
  374. fi
  375. fi
  376. EOF
  377. if [ "$recordfail_broken" = 1 ]; then
  378. cat << EOF
  379. if [ \$grub_platform = efi ]; then
  380. set timeout=${GRUB_RECORDFAIL_TIMEOUT:-3}
  381. if [ x\$feature_timeout_style = xy ] ; then
  382. set timeout_style=menu
  383. fi
  384. fi
  385. EOF
  386. fi
  387. }
  388. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
  389. cat <<EOF
  390. if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
  391. EOF
  392. make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_STYLE_BUTTON}"
  393. echo else
  394. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  395. echo fi
  396. else
  397. make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
  398. fi
  399. if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
  400. cat <<EOF
  401. cmosclean $GRUB_BUTTON_CMOS_ADDRESS
  402. EOF
  403. fi
  404. # Play an initial tune
  405. if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
  406. echo "play ${GRUB_INIT_TUNE}"
  407. fi
  408. if [ "x${GRUB_BADRAM}" != "x" ] ; then
  409. echo "badram ${GRUB_BADRAM}"
  410. fi