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
="${prefix}"
22 datarootdir
="${prefix}/share"
24 .
"${datarootdir}/grub/grub-mkconfig_lib"
26 export TEXTDOMAIN
=grub
27 export TEXTDOMAINDIR
="${datarootdir}/locale"
29 CLASS
="--class gnu-linux --class gnu --class os"
31 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
34 OS
="${GRUB_DISTRIBUTOR} GNU/Linux"
35 CLASS
="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
38 # loop-AES arranges things so that /dev/loop/X can be our root device, but
39 # the initrds that Linux uses don't like that.
40 case ${GRUB_DEVICE} in
41 /dev
/loop
/*|
/dev
/loop
[0-9])
42 GRUB_DEVICE
=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
46 if [ "x${GRUB_DEVICE_UUID}" = "x" ] ||
[ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
47 ||
! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
48 || uses_abstraction
"${GRUB_DEVICE}" lvm
; then
49 LINUX_ROOT_DEVICE
=${GRUB_DEVICE}
51 LINUX_ROOT_DEVICE
=UUID
=${GRUB_DEVICE_UUID}
54 GRUBFS
="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
56 if [ x
"$GRUBFS" = x
]; then
57 GRUBFS
="$(stat -f --printf=%T / || true)"
62 rootsubvol
="`make_system_path_relative_to_its_root /`"
63 rootsubvol
="${rootsubvol#/}"
64 if [ "x${rootsubvol}" != x
]; then
65 GRUB_CMDLINE_LINUX
="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
68 rpool
=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
69 bootfs
="`make_system_path_relative_to_its_root / | sed -e "s
,@$
,,"`"
70 LINUX_ROOT_DEVICE
="ZFS=${rpool}${bootfs}"
74 title_correction_code
=
83 if [ -z "$boot_device_id" ]; then
84 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
86 if [ x
$type != xsimple
] ; then
89 title
="$(gettext_printf "%s
, with Linux
%s
(recovery mode
)" "${os}" "${version}")" ;;
91 title
="$(gettext_printf "%s
, with Linux
%s
" "${os}" "${version}")" ;;
93 if [ x
"$title" = x
"$GRUB_ACTUAL_DEFAULT" ] ||
[ x
"Previous Linux versions>$title" = x
"$GRUB_ACTUAL_DEFAULT" ]; then
94 replacement_title
="$(echo "Advanced options
for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
95 quoted
="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
96 title_correction_code
="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
97 grub_warn
"$(gettext_printf "Please don
't use old title \`%s' for GRUB_DEFAULT
, use \
`%s' (for versions before 2.00) or \`%s
' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
99 echo "menuentry '$
(echo "$title" | grub_quote
)' ${CLASS} \$menuentry_id_option 'gnulinux-
$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
101 echo "menuentry '$
(echo "$os" | grub_quote
)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-
$boot_device_id' {" | sed "s/^/$submenu_indentation/"
103 if [ x$type != xrecovery ] ; then
104 save_default_entry | sed -e "s/^/\t/"
107 # Use ELILO's generic
"efifb" when it
's known to be available.
108 # FIXME: We need an interface to select vesafb in case efifb can't be used.
109 if [ "x$GRUB_GFXPAYLOAD_LINUX" = x
]; then
110 echo " load_video" |
sed "s/^/$submenu_indentation/"
111 if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev
/null \
112 && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev
/null
; then
113 echo " set gfxpayload=keep" |
sed "s/^/$submenu_indentation/"
116 if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext
]; then
117 echo " load_video" |
sed "s/^/$submenu_indentation/"
119 echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" |
sed "s/^/$submenu_indentation/"
122 echo " insmod gzio" |
sed "s/^/$submenu_indentation/"
124 if [ x
$dirname = x
/ ]; then
125 if [ -z "${prepare_root_cache}" ]; then
126 prepare_root_cache
="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s
/^
/\t/")"
128 printf '%s\n' "${prepare_root_cache}" |
sed "s/^/$submenu_indentation/"
130 if [ -z "${prepare_boot_cache}" ]; then
131 prepare_boot_cache
="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s
/^
/\t/")"
133 printf '%s\n' "${prepare_boot_cache}" |
sed "s/^/$submenu_indentation/"
135 message
="$(gettext_printf "Loading Linux
%s ...
" ${version})"
136 sed "s/^/$submenu_indentation/" << EOF
138 linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
140 if test -n "${initrd}" ; then
141 # TRANSLATORS: ramdisk isn't identifier. Should be translated.
142 message
="$(gettext_printf "Loading initial ramdisk ...
")"
143 sed "s/^/$submenu_indentation/" << EOF
145 initrd ${rel_dirname}/${initrd}
148 sed "s/^/$submenu_indentation/" << EOF
156 list
=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
157 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
160 list
=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
161 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
166 i?
86) GENKERNEL_ARCH
="x86" ;;
167 mips|mips64
) GENKERNEL_ARCH
="mips" ;;
168 mipsel|mips64el
) GENKERNEL_ARCH
="mipsel" ;;
169 arm
*) GENKERNEL_ARCH
="arm" ;;
170 *) GENKERNEL_ARCH
="$machine" ;;
176 title_correction_code
=
178 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
179 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
180 submenu_indentation
=""
183 while [ "x$list" != "x" ] ; do
184 linux
=`version_find_latest $list`
185 gettext_printf
"Found linux image: %s\n" "$linux" >&2
186 basename=`basename $linux`
187 dirname=`dirname $linux`
188 rel_dirname
=`make_system_path_relative_to_its_root $dirname`
189 version
=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
190 alt_version
=`echo $version | sed -e "s,\.old$,,g"`
191 linux_root_device_thisversion
="${LINUX_ROOT_DEVICE}"
194 for i
in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
195 "initrd-${version}" "initramfs-${version}.img" \
196 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
197 "initrd-${alt_version}" "initramfs-${alt_version}.img" \
198 "initramfs-genkernel-${version}" \
199 "initramfs-genkernel-${alt_version}" \
200 "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
201 "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
202 if test -e "${dirname}/${i}" ; then
209 for i
in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
210 if test -e "${i}" ; then
217 if test -n "${config}" ; then
218 initramfs
=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
221 if test -n "${initrd}" ; then
222 gettext_printf
"Found initrd image: %s\n" "${dirname}/${initrd}" >&2
223 elif test -z "${initramfs}" ; then
224 # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
225 # no initrd or builtin initramfs, it can't work here.
226 linux_root_device_thisversion
=${GRUB_DEVICE}
229 if [ "x$is_first_entry" = xtrue
]; then
230 linux_entry
"Serial Console: ${OS}" "${version}" simple \
231 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} console=ttyS0,115200n8"
233 submenu_indentation
="\t"
235 if [ -z "$boot_device_id" ]; then
236 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
240 list
=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
243 echo "$title_correction_code"