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}"
144 if [ "x${GRUB_TERMINAL_OUTPUT}" == x
]; then
145 GRUB_TERMINAL_OUTPUT
=gfxterm
;
149 for x
in ${GRUB_TERMINAL_OUTPUT}; do
150 if [ x
${x} == xgfxterm
]; then
151 # If this platform supports gfxterm, try to use it.
152 if ! test -e ${grub_prefix}/gfxterm.mod
; then
153 if [ "x$termoutdefault" != "x1" ]; then
154 echo "gfxterm isn't available on your platform" >&2 ; exit 1
156 GRUB_TERMINAL_OUTPUT
=
159 # FIXME: this should do something smarter than just loading first
161 GRUB_VIDEO_BACKEND
=$
(head -n 1 ${grub_prefix}/video.lst || true
)
162 if [ -z "${GRUB_VIDEO_BACKEND}" ] ; then
163 if [ "x$termoutdefault" != "x1" ]; then
164 echo "No suitable backend could be found for gfxterm." >&2 ; exit 1
166 GRUB_TERMINAL_OUTPUT
=
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 if [ "x$termoutdefault" != "x1" ]; then
194 echo "No font for gfxterm found." >&2 ; exit 1
196 GRUB_TERMINAL_OUTPUT
=
201 for x
in ${GRUB_TERMINAL_OUTPUT}; do
204 xconsole | xserial | xofconsole
)
205 # make sure all our children behave in conformance with ascii..
207 *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
211 # These are defined in this script, export them here so that user can
216 GRUB_DEVICE_BOOT_UUID \
219 GRUB_PRELOAD_MODULES \
222 # These are optional, user-defined variables.
223 export GRUB_DEFAULT \
224 GRUB_HIDDEN_TIMEOUT \
225 GRUB_HIDDEN_TIMEOUT_QUIET \
229 GRUB_CMDLINE_LINUX_DEFAULT \
230 GRUB_TERMINAL_INPUT \
231 GRUB_TERMINAL_OUTPUT \
232 GRUB_SERIAL_COMMAND \
233 GRUB_DISABLE_LINUX_UUID \
234 GRUB_DISABLE_LINUX_RECOVERY \
237 GRUB_GFXPAYLOAD_LINUX \
238 GRUB_DISABLE_OS_PROBER \
242 if test "x${grub_cfg}" != "x"; then
243 rm -f ${grub_cfg}.new
244 exec > ${grub_cfg}.new
246 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
247 # firmware implementations (e.g. OFW or EFI).
248 chmod 400 ${grub_cfg}.new || grub_warn
"Could not make ${grub_cfg}.new readable by only root.\
249 This means that if the generated config contains a password it is readable by everyone"
251 echo "Generating grub.cfg ..." >&2
255 # DO NOT EDIT THIS FILE
257 # It is automatically generated by $0 using templates
258 # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
262 for i
in ${grub_mkconfig_dir}/* ; do
264 # emacsen backup files. FIXME: support other editors
267 if grub_file_is_not_garbage
"$i" && test -x "$i" ; then
269 echo "### BEGIN $i ###"
271 echo "### END $i ###"
277 if test "x${grub_cfg}" != "x" ; then
278 # none of the children aborted with error, install the new grub.cfg
279 mv -f ${grub_cfg}.new
${grub_cfg}