3 # Generate grub.cfg by inspecting /boot contents.
4 # Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
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.
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.
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/>.
19 transform
="@program_transform_name@"
22 exec_prefix
=@exec_prefix@
25 sysconfdir
=@sysconfdir@
26 package_version
=@PACKAGE_VERSION@
27 datarootdir
=@datarootdir@
29 pkgdatadir
=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`
30 grub_prefix
=`echo /boot/grub | sed ${transform}`
32 grub_mkconfig_dir
=${sysconfdir}/grub.d
34 grub_mkdevicemap
=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
35 grub_probe
=${sbindir}/`echo grub-probe | sed ${transform}`
42 Generate a grub config file
44 -o, --output=FILE output generated config to FILE [default=stdout]
45 -h, --help print this message and exit
46 -v, --version print the version information and exit
48 Report bugs to <bug-grub@gnu.org>.
52 # Check the arguments.
53 for option
in "$@"; do
59 echo "$0 (GNU GRUB ${package_version})"
66 grub_cfg
=`echo "$option" | sed 's/--output=//'`
69 echo "Unrecognized option \`$option'" 1>&2
76 .
${libdir}/grub
/grub-mkconfig_lib
78 if [ "x$EUID" = "x" ] ; then
82 if [ "$EUID" != 0 ] ; then
84 case "`uname 2>/dev/null`" in
86 # Cygwin: Assume root if member of admin group
87 for g
in `id -G 2>/dev/null` ; do
93 if [ $root != t
] ; then
94 echo "$0: You must run this as root" >&2
99 set $grub_mkdevicemap dummy
100 if test -f "$1"; then
103 echo "$1: Not found." 1>&2
107 set $grub_probe dummy
108 if test -f "$1"; then
111 echo "$1: Not found." 1>&2
115 mkdir
-p ${grub_prefix}
117 if test -e ${grub_prefix}/device.map
; then : ; else
121 # Device containing our userland. Typically used for root= parameter.
122 GRUB_DEVICE
="`${grub_probe} --target=device /`"
123 GRUB_DEVICE_UUID
="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
125 # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
126 GRUB_DEVICE_BOOT
="`${grub_probe} --target=device /boot`"
127 GRUB_DEVICE_BOOT_UUID
="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
129 # Filesystem for the device containing our userland. Used for stuff like
130 # choosing Hurd filesystem module.
131 GRUB_FS
="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`"
133 if test -f ${sysconfdir}/default
/grub
; then
134 .
${sysconfdir}/default
/grub
137 # XXX: should this be deprecated at some point?
138 if [ "x${GRUB_TERMINAL}" != "x" ] ; then
139 GRUB_TERMINAL_INPUT
="${GRUB_TERMINAL}"
140 GRUB_TERMINAL_OUTPUT
="${GRUB_TERMINAL}"
143 case x
${GRUB_TERMINAL_OUTPUT} in
145 # If this platform supports gfxterm, try to use it.
146 if test -e ${grub_prefix}/gfxterm.mod
; then
149 if test -e ${grub_prefix}/$i.mod
; then
150 GRUB_VIDEO_BACKEND
=$i
154 if [ -n "${GRUB_VIDEO_BACKEND}" ] ; then
155 GRUB_TERMINAL_OUTPUT
=gfxterm
156 elif [ "${GRUB_TERMINAL_OUTPUT}" = "gfxterm" ] ; then
157 echo "No suitable backend could be found for gfxterm." >&2 ; exit 1
161 xconsole | xserial | xofconsole
) ;;
162 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
165 # check for terminals that require fonts
166 case ${GRUB_TERMINAL_OUTPUT} in
168 if [ -n "$GRUB_FONT" ] ; then
169 if is_path_readable_by_grub
${GRUB_FONT} > /dev
/null
; then
170 GRUB_FONT_PATH
=${GRUB_FONT}
172 echo "No such font or not readable by grub: ${GRUB_FONT}" >&2
176 for dir
in ${pkgdatadir} /boot
/grub
/usr
/share
/grub
; do
177 for basename in unicode unifont ascii
; do
178 path
="${dir}/${basename}.pf2"
179 if is_path_readable_by_grub
${path} > /dev
/null
; then
180 GRUB_FONT_PATH
=${path}
184 if [ "${basename}" = "ascii" ] ; then
185 # make sure all our children behave in conformance with ascii..
192 if [ -z "${GRUB_FONT_PATH}" ] ; then
193 # fallback to the native terminal for this platform
194 unset GRUB_TERMINAL_OUTPUT
198 # make sure all our children behave in conformance with ascii..
202 # These are defined in this script, export them here so that user can
207 GRUB_DEVICE_BOOT_UUID \
210 GRUB_PRELOAD_MODULES \
213 # These are optional, user-defined variables.
214 export GRUB_DEFAULT \
215 GRUB_HIDDEN_TIMEOUT \
216 GRUB_HIDDEN_TIMEOUT_QUIET \
220 GRUB_CMDLINE_LINUX_DEFAULT \
221 GRUB_TERMINAL_INPUT \
222 GRUB_TERMINAL_OUTPUT \
223 GRUB_SERIAL_COMMAND \
224 GRUB_DISABLE_LINUX_UUID \
225 GRUB_DISABLE_LINUX_RECOVERY \
227 GRUB_DISABLE_OS_PROBER
229 if test "x${grub_cfg}" != "x"; then
230 rm -f ${grub_cfg}.new
231 exec > ${grub_cfg}.new
233 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
234 # firmware implementations (e.g. OFW or EFI).
235 chmod 444 ${grub_cfg}.new || true
237 echo "Generating grub.cfg ..." >&2
241 # DO NOT EDIT THIS FILE
243 # It is automatically generated by $0 using templates
244 # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
248 for i
in ${grub_mkconfig_dir}/* ; do
250 # emacsen backup files. FIXME: support other editors
253 if grub_file_is_not_garbage
"$i" && test -x "$i" ; then
255 echo "### BEGIN $i ###"
257 echo "### END $i ###"
263 if test "x${grub_cfg}" != "x" ; then
264 # none of the children aborted with error, install the new grub.cfg
265 mv -f ${grub_cfg}.new
${grub_cfg}