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
="@exec_prefix@"
22 datarootdir
="@datarootdir@"
24 .
"$pkgdatadir/grub-mkconfig_lib"
26 export TEXTDOMAIN
=@PACKAGE@
27 export TEXTDOMAINDIR
="@localedir@"
29 CLASS
="--class gnu-linux --class gnu --class os --class xen"
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|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${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 # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
47 # and mounting btrfs requires user space scanning, so force UUID in this case.
48 if [ "x${GRUB_DEVICE_UUID}" = "x" ] ||
[ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
49 ||
! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
50 ||
( test -e "${GRUB_DEVICE}" && uses_abstraction
"${GRUB_DEVICE}" lvm
); then
51 LINUX_ROOT_DEVICE
=${GRUB_DEVICE}
53 LINUX_ROOT_DEVICE
=UUID
=${GRUB_DEVICE_UUID}
56 # Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
57 if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
58 GRUB_CMDLINE_LINUX
="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
60 if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
61 GRUB_CMDLINE_LINUX_DEFAULT
="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
66 rootsubvol
="`make_system_path_relative_to_its_root /`"
67 rootsubvol
="${rootsubvol#/}"
68 if [ "x${rootsubvol}" != x
]; then
69 GRUB_CMDLINE_LINUX
="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
72 rpool
=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
73 bootfs
="`make_system_path_relative_to_its_root / | sed -e "s
,@$
,,"`"
74 LINUX_ROOT_DEVICE
="ZFS=${rpool}${bootfs}"
78 title_correction_code
=
88 if [ -z "$boot_device_id" ]; then
89 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
91 if [ x
$type != xsimple
] ; then
92 if [ x
$type = xrecovery
] ; then
93 title
="$(gettext_printf "%s
, with Xen
%s and Linux
%s
(recovery mode
)" "${os}" "${xen_version}" "${version}")"
95 title
="$(gettext_printf "%s
, with Xen
%s and Linux
%s
" "${os}" "${xen_version}" "${version}")"
97 replacement_title
="$(echo "Advanced options
for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
98 if [ x
"Xen ${xen_version}>$title" = x
"$GRUB_ACTUAL_DEFAULT" ]; then
99 quoted
="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
100 title_correction_code
="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
101 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")"
103 echo "menuentry '$
(echo "$title" | grub_quote
)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-
$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
105 title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
106 echo "menuentry '$
(echo "$title" | grub_quote
)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-
$boot_device_id' {" | sed "s/^/$submenu_indentation/"
108 if [ x$type != xrecovery ] ; then
109 save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
112 if [ -z "${prepare_boot_cache}" ]; then
113 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
115 printf '%s
\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
116 xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
117 lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
118 sed "s/^/$submenu_indentation/" << EOF
119 echo '$
(echo "$xmessage" | grub_quote
)'
120 if [ "\$grub_platform" = "pc" -o "\$grub_platform" = "" ]; then
123 xen_rm_opts="no-real-mode edd=off"
125 multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts}
126 echo '$
(echo "$lmessage" | grub_quote
)'
127 module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
129 if test -n "${initrd}" ; then
130 # TRANSLATORS: ramdisk isn't identifier. Should be translated.
131 message
="$(gettext_printf "Loading initial ramdisk ...
")"
132 sed "s/^/$submenu_indentation/" << EOF
133 echo '$(echo "$message" | grub_quote)'
134 module --nounzip ${rel_dirname}/${initrd}
137 sed "s/^/$submenu_indentation/" << EOF
143 for i
in /boot
/vmlinu
[xz
]-* /vmlinu
[xz
]-* /boot
/kernel-
*; do
144 if grub_file_is_not_garbage
"$i"; then
145 basename=$
(basename $i)
146 version
=$
(echo $basename |
sed -e "s,^[^0-9]*-,,g")
147 dirname=$
(dirname $i)
149 for j
in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
150 if test -e "${j}" ; then
155 if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev
/null ||
grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev
/null
); then linux_list
="$linux_list $i" ; fi
158 if [ "x${linux_list}" = "x" ] ; then
172 for i
in /boot
/xen
*; do
173 if grub_file_is_not_garbage
"$i" && file_is_not_sym
"$i" ; then xen_list
="$xen_list $i" ; fi
178 title_correction_code
=
183 i?
86) GENKERNEL_ARCH
="x86" ;;
184 mips|mips64
) GENKERNEL_ARCH
="mips" ;;
185 mipsel|mips64el
) GENKERNEL_ARCH
="mipsel" ;;
186 arm
*) GENKERNEL_ARCH
="arm" ;;
187 *) GENKERNEL_ARCH
="$machine" ;;
190 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
191 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
192 submenu_indentation
=""
196 while [ "x${xen_list}" != "x" ] ; do
198 current_xen
=`version_find_latest $xen_list`
199 xen_basename
=`basename ${current_xen}`
200 xen_dirname
=`dirname ${current_xen}`
201 rel_xen_dirname
=`make_system_path_relative_to_its_root $xen_dirname`
202 xen_version
=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
203 if [ -z "$boot_device_id" ]; then
204 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
206 if [ "x$is_top_level" != xtrue
]; then
207 echo " submenu '$(gettext_printf "Xen hypervisor
, version
%s
" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
209 while [ "x$list" != "x" ] ; do
210 linux
=`version_find_latest $list`
211 gettext_printf
"Found linux image: %s\n" "$linux" >&2
212 basename=`basename $linux`
213 dirname=`dirname $linux`
214 rel_dirname
=`make_system_path_relative_to_its_root $dirname`
215 version
=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
216 alt_version
=`echo $version | sed -e "s,\.old$,,g"`
217 linux_root_device_thisversion
="${LINUX_ROOT_DEVICE}"
220 for i
in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
221 "initrd-${version}" "initramfs-${version}.img" \
222 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
223 "initrd-${alt_version}" "initramfs-${alt_version}.img" \
224 "initramfs-genkernel-${version}" \
225 "initramfs-genkernel-${alt_version}" \
226 "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
227 "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do
228 if test -e "${dirname}/${i}" ; then
233 if test -n "${initrd}" ; then
234 gettext_printf
"Found initrd image: %s\n" "${dirname}/${initrd}" >&2
236 # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
237 linux_root_device_thisversion
=${GRUB_DEVICE}
240 if [ "x$is_top_level" = xtrue
] && [ "x${GRUB_DISABLE_SUBMENU}" != xy
]; then
241 linux_entry
"${OS}" "${version}" "${xen_version}" simple \
242 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
244 submenu_indentation
="$grub_tab$grub_tab"
246 if [ -z "$boot_device_id" ]; then
247 boot_device_id
="$(grub_get_device_id "${GRUB_DEVICE}")"
249 # TRANSLATORS: %s is replaced with an OS name
250 echo "submenu '$(gettext_printf "Advanced options
for %s
(with Xen hypervisor
)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
251 echo " submenu '$(gettext_printf "Xen hypervisor
, version
%s
" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
255 linux_entry
"${OS}" "${version}" "${xen_version}" advanced \
256 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
257 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
258 linux_entry
"${OS}" "${version}" "${xen_version}" recovery \
259 "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
262 list
=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
264 if [ x
"$is_top_level" != xtrue
]; then
267 xen_list
=`echo $xen_list | tr ' ' '\n' | fgrep -vx "$current_xen" | tr '\n' ' '`
270 # If at least one kernel was found, then we need to
271 # add a closing '}' for the submenu command.
272 if [ x
"$is_top_level" != xtrue
]; then
276 echo "$title_correction_code"