4 # grub-mkconfig helper script.
5 # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
7 # GRUB is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GRUB is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 exec_prefix="@exec_prefix@"
22 datarootdir="@datarootdir@"
23 grub_lang=`echo $LANG | cut -d . -f 1`
25 export TEXTDOMAIN=@PACKAGE@
26 export TEXTDOMAINDIR="@localedir@"
28 . "$pkgdatadir/grub-mkconfig_lib"
30 # Do this as early as possible, since other commands might depend on it.
31 # (e.g. the `loadfont' command might need lvm or raid modules)
32 for i in ${GRUB_PRELOAD_MODULES} ; do
36 if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
37 if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
38 if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
39 if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
41 if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
42 if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
43 if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi
46 if [ -s \$prefix/grubenv ]; then
50 if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
52 if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
53 set default="${GRUB_DEFAULT_BUTTON}"
54 elif [ "\${next_entry}" ] ; then
55 set default="\${next_entry}"
60 set default="${GRUB_DEFAULT}"
65 if [ "\${next_entry}" ] ; then
66 set default="\${next_entry}"
71 set default="${GRUB_DEFAULT}"
77 if [ x"\${feature_menuentry_id}" = xy ]; then
78 menuentry_id_option="--id"
80 menuentry_id_option=""
83 export menuentry_id_option
85 if [ "\${prev_saved_entry}" ]; then
86 set saved_entry="\${prev_saved_entry}"
89 save_env prev_saved_entry
93 function savedefault {
94 if [ -z "\${boot_once}" ]; then
95 saved_entry="\${chosen}"
100 function load_video {
102 if [ -n "${GRUB_VIDEO_BACKEND}" ]; then
104 insmod ${GRUB_VIDEO_BACKEND}
107 # If all_video.mod isn't available load all modules available
108 # with versions prior to introduction of all_video.mod
110 if [ x\$feature_all_video_module = xy ]; then
130 for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
131 if [ xserial = "x$x" ]; then
134 if [ xgfxterm = "x$x" ]; then
139 if [ "x$serial" = x1 ]; then
140 if [ "x${GRUB_SERIAL_COMMAND}" = "x" ] ; then
141 grub_warn "$(gettext "Requested serial terminal but GRUB_SERIAL_COMMAND is unspecified. Default parameters will be used.")"
142 GRUB_SERIAL_COMMAND=serial
144 echo "${GRUB_SERIAL_COMMAND}"
147 if [ "x$gfxterm" = x1 ]; then
148 if [ -n "$GRUB_FONT" ] ; then
149 # Make the font accessible
150 prepare_grub_to_access_device `${grub_probe} --target=device "${GRUB_FONT}"`
152 if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
155 for dir in "${pkgdatadir}" "`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" /usr/share/grub ; do
156 for basename in unicode unifont ascii; do
157 path="${dir}/${basename}.pf2"
158 if is_path_readable_by_grub "${path}" > /dev/null ; then
166 if [ -n "${font_path}" ] ; then
168 if [ x\$feature_default_font_path = xy ] ; then
172 # Make the font accessible
173 prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"`
175 font="`make_system_path_relative_to_its_root "${font_path}"`"
178 if loadfont \$font ; then
182 if loadfont unicode ; then
188 set gfxmode=${GRUB_GFXMODE}
193 # Gettext variables and module
194 if [ "x${LANG}" != "xC" ] && [ "x${LANG}" != "x" ]; then
196 set locale_dir=\$prefix/locale
197 set lang=${grub_lang}
207 case x${GRUB_TERMINAL_INPUT} in
209 # Just use the native terminal
213 terminal_input ${GRUB_TERMINAL_INPUT}
218 case x${GRUB_TERMINAL_OUTPUT} in
220 # Just use the native terminal
224 terminal_output --append ${GRUB_TERMINAL_OUTPUT}
229 if [ "x$gfxterm" = x1 ]; then
230 if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \
231 && is_path_readable_by_grub "$GRUB_THEME"; then
232 gettext_printf "Found theme: %s\n" "$GRUB_THEME" >&2
234 prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"`
238 themedir="`dirname "$GRUB_THEME"`"
239 for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do
242 loadfont (\$root)`make_system_path_relative_to_its_root $x`
246 if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then
251 if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then
256 if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then
263 set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME`
266 elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \
267 && is_path_readable_by_grub "$GRUB_BACKGROUND"; then
268 gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2
269 case "$GRUB_BACKGROUND" in
272 *.jpg|*.jpeg) reader=jpeg ;;
273 *) gettext "Unsupported image format" >&2; echo >&2; exit 1 ;;
275 prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"`
278 background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"`
285 if [ "x${3}" != "x" ] ; then
288 elif [ "x${1}" != "x" ] && [ "x${1}" != "x0" ] ; then
289 # Handle the deprecated GRUB_HIDDEN_TIMEOUT scheme.
291 if [ "x${2}" != "x0" ] ; then
292 grub_warn "$(gettext "Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.")"
294 if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then
302 # No hidden timeout, so treat as GRUB_TIMEOUT_STYLE=menu
307 if [ x\$feature_timeout_style = xy ] ; then
308 set timeout_style=${style}
309 set timeout=${timeout}
311 if [ "x${style}" = "xmenu" ] ; then
313 # Fallback normal timeout code in case the timeout_style feature is
316 set timeout=${timeout}
320 # Fallback hidden-timeout code in case the timeout_style feature is
322 elif sleep${verbose} --interruptible ${timeout} ; then
331 if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then
333 if cmostest $GRUB_BUTTON_CMOS_ADDRESS ; then
335 make_timeout "${GRUB_HIDDEN_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_BUTTON}" "${GRUB_TIMEOUT_STYLE_BUTTON}"
337 make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
340 make_timeout "${GRUB_HIDDEN_TIMEOUT}" "${GRUB_TIMEOUT}" "${GRUB_TIMEOUT_STYLE}"
343 if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ] && [ "x$GRUB_BUTTON_CMOS_CLEAN" = "xyes" ]; then
345 cmosclean $GRUB_BUTTON_CMOS_ADDRESS
349 # Play an initial tune
350 if [ "x${GRUB_INIT_TUNE}" != "x" ] ; then
351 echo "play ${GRUB_INIT_TUNE}"
354 if [ "x${GRUB_BADRAM}" != "x" ] ; then
355 echo "badram ${GRUB_BADRAM}"