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 grub_prefix
=`echo /boot/grub | sed ${transform}`
28 grub_mkconfig_dir
=${sysconfdir}/grub.d
30 grub_mkdevicemap
=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
31 grub_probe
=${sbindir}/`echo grub-probe | sed ${transform}`
38 Generate a grub config file
40 -o, --output=FILE output generated config to FILE [default=stdout]
41 -h, --help print this message and exit
42 -v, --version print the version information and exit
44 Report bugs to <bug-grub@gnu.org>.
48 # Check the arguments.
49 for option
in "$@"; do
55 echo "$0 (GNU GRUB ${PACKAGE_VERSION})"
62 grub_cfg
=`echo "$option" | sed 's/--output=//'`
65 echo "Unrecognized option \`$option'" 1>&2
72 .
${libdir}/grub
/grub-mkconfig_lib
74 if [ "x$EUID" = "x" ] ; then
78 if [ "$EUID" != 0 ] ; then
80 case "`uname 2>/dev/null`" in
82 # Cygwin: Assume root if member of admin group
83 for g
in `id -G 2>/dev/null` ; do
89 if [ $root != t
] ; then
90 echo "$0: You must run this as root" >&2
95 set $grub_mkdevicemap dummy
99 echo "$1: Not found." 1>&2
103 set $grub_probe dummy
104 if test -f "$1"; then
107 echo "$1: Not found." 1>&2
111 mkdir
-p ${grub_prefix}
113 if test -e ${grub_prefix}/device.map
; then : ; else
117 # Device containing our userland. Typically used for root= parameter.
118 GRUB_DEVICE
="`${grub_probe} --target=device /`"
119 GRUB_DEVICE_UUID
="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
121 # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
122 GRUB_DEVICE_BOOT
="`${grub_probe} --target=device /boot`"
123 GRUB_DEVICE_BOOT_UUID
="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
125 # Filesystem for the device containing our userland. Used for stuff like
126 # choosing Hurd filesystem module.
127 GRUB_FS
="`${grub_probe} --target=fs / 2> /dev/null || echo unknown`"
129 if test -f ${sysconfdir}/default
/grub
; then
130 .
${sysconfdir}/default
/grub
133 # XXX: should this be deprecated at some point?
134 if [ "x${GRUB_TERMINAL}" != "x" ] ; then
135 GRUB_TERMINAL_INPUT
="${GRUB_TERMINAL}"
136 GRUB_TERMINAL_OUTPUT
="${GRUB_TERMINAL}"
139 case x
${GRUB_TERMINAL_OUTPUT} in
141 # If this platform supports gfxterm, try to use it.
142 if test -e ${grub_prefix}/gfxterm.mod
; then
143 GRUB_TERMINAL_OUTPUT
=gfxterm
146 xconsole | xserial | xofconsole | xgfxterm
) ;;
147 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
150 # check for terminals that require fonts
151 case ${GRUB_TERMINAL_OUTPUT} in
153 if path
=`font_path` ; then
154 GRUB_FONT_PATH
="${path}"
156 # fallback to the native terminal for this platform
157 unset GRUB_TERMINAL_OUTPUT
162 # does our terminal support utf-8 ?
163 case ${GRUB_TERMINAL_OUTPUT} in
166 # make sure all our children behave in conformance with ascii..
171 # These are defined in this script, export them here so that user can
173 export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES
175 # These are optional, user-defined variables.
176 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL_INPUT GRUB_TERMINAL_OUTPUT GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_GFXMODE
178 if test "x${grub_cfg}" != "x"; then
179 rm -f ${grub_cfg}.new
180 exec > ${grub_cfg}.new
182 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
183 # firmware implementations (e.g. OFW or EFI).
184 chmod 444 ${grub_cfg}.new || true
186 echo "Generating grub.cfg ..." >&2
190 # DO NOT EDIT THIS FILE
192 # It is automatically generated by $0 using templates
193 # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
197 for i
in ${grub_mkconfig_dir}/* ; do
199 # emacsen backup files. FIXME: support other editors
202 if grub_file_is_not_garbage
"$i" && test -x "$i" ; then
204 echo "### BEGIN $i ###"
206 echo "### END $i ###"
212 if test "x${grub_cfg}" != "x" ; then
213 # none of the children aborted with error, install the new grub.cfg
214 mv -f ${grub_cfg}.new
${grub_cfg}