4 # Generate grub.cfg by inspecting /boot contents.
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/>.
20 transform
="@program_transform_name@"
22 exec_prefix
="@exec_prefix@"
23 datarootdir
="@datarootdir@"
26 exec_prefix
="@exec_prefix@"
29 sysconfdir
="@sysconfdir@"
30 PACKAGE_NAME
=@PACKAGE_NAME@
31 PACKAGE_VERSION
=@PACKAGE_VERSION@
34 if [ "x$pkgdatadir" = x
]; then
35 pkgdatadir
="${datadir}/@PACKAGE@"
38 grub_mkconfig_dir
="${sysconfdir}"/grub.d
42 grub_probe
="${sbindir}/`echo grub-probe | sed "${transform}"`"
43 grub_script_check
="${bindir}/`echo grub-script-check | sed "${transform}"`"
45 .
"${pkgdatadir}/grub-mkconfig_lib"
50 gettext_printf
"Usage: %s [OPTION]\n" "$self"
51 gettext "Generate a grub config file"; echo
53 printf " -o, --output=%-11s%s\n" "$(gettext FILE)" "$(gettext "output generated config to FILE
[default
=stdout
]")"
54 printf " -h, --help %s\n" "$(gettext "print this message and
exit")"
55 printf " -v, --version %s\n" "$(gettext "print the version information and
exit")"
57 gettext "Report bugs to <bug-grub@gnu.org>."; echo
64 if test $# -eq 0; then
65 gettext_printf
"%s: option requires an argument -- '%s'" "$0" "$opt" 1>&2
71 # Check the arguments.
82 echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
85 grub_cfg
=`argument $option "$@"`; shift;;
87 grub_cfg
=`echo "$option" | sed 's/--output=//'`
90 gettext_printf
"Unrecognized option \`%s'\n" "$option" 1>&2
94 # Explicitly ignore non-option arguments, for compatibility.
98 if [ "x$EUID" = "x" ] ; then
102 if [ "$EUID" != 0 ] ; then
104 case "`uname 2>/dev/null`" in
106 # Cygwin: Assume root if member of admin group
107 for g
in `id -G 2>/dev/null` ; do
113 if [ $root != t
] ; then
114 gettext_printf
"%s: You must run this as root\n" "$self" >&2
119 set $grub_probe dummy
120 if test -f "$1"; then
123 gettext_print
"%s: Not found.\n" "$1" 1>&2
127 # Device containing our userland. Typically used for root= parameter.
128 GRUB_DEVICE
="`${grub_probe} --target=device /`"
129 GRUB_DEVICE_UUID
="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
131 # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
132 GRUB_DEVICE_BOOT
="`${grub_probe} --target=device /boot`"
133 GRUB_DEVICE_BOOT_UUID
="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
135 # Filesystem for the device containing our userland. Used for stuff like
136 # choosing Hurd filesystem module.
137 GRUB_FS
="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
139 if test -f ${sysconfdir}/default
/grub
; then
140 .
${sysconfdir}/default
/grub
143 # XXX: should this be deprecated at some point?
144 if [ "x${GRUB_TERMINAL}" != "x" ] ; then
145 GRUB_TERMINAL_INPUT
="${GRUB_TERMINAL}"
146 GRUB_TERMINAL_OUTPUT
="${GRUB_TERMINAL}"
150 if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
151 GRUB_TERMINAL_OUTPUT
=gfxterm
;
155 for x
in ${GRUB_TERMINAL_OUTPUT}; do
158 xconsole | xserial | xofconsole
)
159 # make sure all our children behave in conformance with ascii..
161 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
165 # These are defined in this script, export them here so that user can
170 GRUB_DEVICE_BOOT_UUID \
175 # These are optional, user-defined variables.
176 export GRUB_DEFAULT \
177 GRUB_HIDDEN_TIMEOUT \
178 GRUB_HIDDEN_TIMEOUT_QUIET \
180 GRUB_DEFAULT_BUTTON \
181 GRUB_HIDDEN_TIMEOUT_BUTTON \
182 GRUB_TIMEOUT_BUTTON \
183 GRUB_BUTTON_CMOS_ADDRESS \
184 GRUB_BUTTON_CMOS_CLEAN \
187 GRUB_CMDLINE_LINUX_DEFAULT \
189 GRUB_CMDLINE_XEN_DEFAULT \
190 GRUB_CMDLINE_LINUX_XEN_REPLACE \
191 GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \
192 GRUB_CMDLINE_NETBSD \
193 GRUB_CMDLINE_NETBSD_DEFAULT \
194 GRUB_CMDLINE_GNUMACH \
195 GRUB_TERMINAL_INPUT \
196 GRUB_TERMINAL_OUTPUT \
197 GRUB_SERIAL_COMMAND \
198 GRUB_DISABLE_LINUX_UUID \
199 GRUB_DISABLE_RECOVERY \
204 GRUB_GFXPAYLOAD_LINUX \
205 GRUB_DISABLE_OS_PROBER \
208 GRUB_ENABLE_CRYPTODISK \
211 if test "x${grub_cfg}" != "x"; then
212 rm -f "${grub_cfg}.new"
213 oldumask
=$
(umask); umask 077
214 exec > "${grub_cfg}.new"
217 gettext "Generating grub.cfg ..." >&2
222 # DO NOT EDIT THIS FILE
224 # It is automatically generated by $self using templates
225 # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
229 for i
in ${grub_mkconfig_dir}/* ; do
231 # emacsen backup files. FIXME: support other editors
233 # emacsen autosave files. FIXME: support other editors
236 if grub_file_is_not_garbage
"$i" && test -x "$i" ; then
238 echo "### BEGIN $i ###"
240 echo "### END $i ###"
246 if test "x${grub_cfg}" != "x" ; then
247 if ! ${grub_script_check} ${grub_cfg}.new
; then
248 gettext_printf
"Syntax errors are detected in generated GRUB config file.
249 Ensure that there are no errors in /etc/default/grub
250 and /etc/grub.d/* files or please file a bug report with
251 %s file attached." "${grub_cfg}.new" >&2
253 # none of the children aborted with error, install the new grub.cfg
254 mv -f ${grub_cfg}.new
${grub_cfg}