2010-06-29 15:20:49 +00:00
#! /bin/sh
set -e
2007-05-04 07:11:44 +00:00
2009-08-08 17:59:19 +00:00
# grub-mkconfig helper script.
2010-01-07 18:20:11 +00:00
# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
2007-05-04 07:11:44 +00:00
#
2007-07-21 23:32:33 +00:00
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
2007-05-04 07:11:44 +00:00
# (at your option) any later version.
#
2007-07-21 23:32:33 +00:00
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2007-05-04 07:11:44 +00:00
#
# You should have received a copy of the GNU General Public License
2007-07-21 23:32:33 +00:00
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2007-05-04 07:11:44 +00:00
2012-01-24 12:17:36 +00:00
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
2015-04-29 16:18:54 +00:00
. "$pkgdatadir/grub-mkconfig_lib"
2008-01-10 13:52:24 +00:00
2009-11-16 20:19:42 +00:00
export TEXTDOMAIN=@PACKAGE@
2012-01-24 12:17:36 +00:00
export TEXTDOMAINDIR="@localedir@"
2009-11-16 20:19:42 +00:00
2010-01-07 18:20:11 +00:00
CLASS="--class gnu-linux --class gnu --class os"
2008-01-10 13:52:24 +00:00
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
2007-05-04 07:11:44 +00:00
OS=GNU/Linux
else
OS="${GRUB_DISTRIBUTOR} GNU/Linux"
2013-09-23 15:48:38 +00:00
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
2007-05-04 07:11:44 +00:00
fi
2008-06-26 07:03:26 +00:00
# loop-AES arranges things so that /dev/loop/X can be our root device, but
# the initrds that Linux uses don't like that.
case ${GRUB_DEVICE} in
/dev/loop/*|/dev/loop[0-9])
GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
;;
esac
2018-04-17 05:36:26 +00:00
# Default to disabling partition uuid support to maintian compatibility with
# older kernels.
GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
2016-02-01 17:13:48 +00:00
# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
# and mounting btrfs requires user space scanning, so force UUID in this case.
2018-04-17 05:36:26 +00:00
if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ) \
|| ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
|| ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
2016-03-05 22:30:48 +00:00
|| ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
2008-06-26 07:03:26 +00:00
LINUX_ROOT_DEVICE=${GRUB_DEVICE}
2018-04-17 05:36:26 +00:00
elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
|| [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
2008-05-30 21:53:17 +00:00
else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
fi
2013-12-07 15:09:39 +00:00
case x"$GRUB_FS" in
2012-02-27 18:07:09 +00:00
xbtrfs)
2013-12-24 16:47:27 +00:00
rootsubvol="`make_system_path_relative_to_its_root /`"
2012-02-27 18:07:09 +00:00
rootsubvol="${rootsubvol#/}"
if [ "x${rootsubvol}" != x ]; then
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
fi;;
xzfs)
2012-03-10 12:36:08 +00:00
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
2013-12-24 16:47:27 +00:00
bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
2012-03-10 12:36:08 +00:00
LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
2012-03-10 13:42:26 +00:00
;;
2012-02-27 18:07:09 +00:00
esac
2011-04-13 11:57:26 +00:00
2012-03-04 21:18:33 +00:00
title_correction_code=
2009-03-29 02:23:12 +00:00
linux_entry ()
{
2009-11-16 20:19:42 +00:00
os="$1"
version="$2"
2012-03-04 21:18:33 +00:00
type="$3"
2009-11-16 20:19:42 +00:00
args="$4"
2012-03-04 21:18:33 +00:00
2012-03-04 13:55:13 +00:00
if [ -z "$boot_device_id" ]; then
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
fi
2012-03-04 21:18:33 +00:00
if [ x$type != xsimple ] ; then
case $type in
recovery)
title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
*)
title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
esac
if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
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")"
fi
echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
else
echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
fi
if [ x$type != xrecovery ] ; then
2012-09-18 11:04:06 +00:00
save_default_entry | grub_add_tab
2010-11-01 11:49:40 +00:00
fi
2010-01-20 17:01:12 +00:00
# Use ELILO's generic "efifb" when it's known to be available.
# FIXME: We need an interface to select vesafb in case efifb can't be used.
2010-02-10 18:53:13 +00:00
if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
2012-03-04 21:18:33 +00:00
echo " load_video" | sed "s/^/$submenu_indentation/"
2011-03-30 18:42:42 +00:00
if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
&& grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
2012-03-04 21:18:33 +00:00
echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
2010-02-10 18:53:13 +00:00
fi
else
2010-11-01 11:36:00 +00:00
if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
2012-03-04 21:18:33 +00:00
echo " load_video" | sed "s/^/$submenu_indentation/"
2010-11-01 11:36:00 +00:00
fi
2012-03-04 21:18:33 +00:00
echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
2010-01-20 17:01:12 +00:00
fi
2012-03-04 21:18:33 +00:00
echo " insmod gzio" | sed "s/^/$submenu_indentation/"
2011-05-14 20:47:28 +00:00
2013-12-24 16:47:27 +00:00
if [ x$dirname = x/ ]; then
2011-05-10 08:40:22 +00:00
if [ -z "${prepare_root_cache}" ]; then
2012-09-18 11:04:06 +00:00
prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
2011-05-10 08:40:22 +00:00
fi
2012-03-04 21:18:33 +00:00
printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
2011-05-10 08:40:22 +00:00
else
if [ -z "${prepare_boot_cache}" ]; then
2012-09-18 11:04:06 +00:00
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
2011-05-10 08:40:22 +00:00
fi
2012-03-04 21:18:33 +00:00
printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
2009-10-26 16:28:04 +00:00
fi
2010-12-21 12:49:29 +00:00
message="$(gettext_printf "Loading Linux %s ..." ${version})"
2012-03-04 21:18:33 +00:00
sed "s/^/$submenu_indentation/" << EOF
2012-07-22 18:02:17 +00:00
echo '$(echo "$message" | grub_quote)'
2009-11-16 20:19:42 +00:00
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
2009-03-29 02:23:12 +00:00
EOF
if test -n "${initrd}" ; then
2012-02-26 16:28:05 +00:00
# TRANSLATORS: ramdisk isn't identifier. Should be translated.
2010-12-21 12:49:29 +00:00
message="$(gettext_printf "Loading initial ramdisk ...")"
2018-02-24 22:44:58 +00:00
initrd_path=
for i in ${initrd}; do
initrd_path="${initrd_path} ${rel_dirname}/${i}"
done
2012-03-04 21:18:33 +00:00
sed "s/^/$submenu_indentation/" << EOF
2012-07-22 18:02:17 +00:00
echo '$(echo "$message" | grub_quote)'
2018-02-24 22:44:58 +00:00
initrd $(echo $initrd_path)
2009-03-29 02:23:12 +00:00
EOF
fi
2012-03-04 21:18:33 +00:00
sed "s/^/$submenu_indentation/" << EOF
2009-03-29 02:23:12 +00:00
}
EOF
}
2013-12-24 16:47:27 +00:00
machine=`uname -m`
case "x$machine" in
xi?86 | xx86_64)
2014-12-07 11:56:17 +00:00
list=
for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
done ;;
2013-12-24 16:47:27 +00:00
*)
2014-12-07 11:56:17 +00:00
list=
for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
done ;;
2013-12-24 16:47:27 +00:00
esac
case "$machine" in
i?86) GENKERNEL_ARCH="x86" ;;
2012-04-18 21:25:21 +00:00
mips|mips64) GENKERNEL_ARCH="mips" ;;
mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
arm*) GENKERNEL_ARCH="arm" ;;
2013-12-24 16:47:27 +00:00
*) GENKERNEL_ARCH="$machine" ;;
2012-04-18 21:25:21 +00:00
esac
2009-10-26 16:28:04 +00:00
prepare_boot_cache=
2011-05-10 08:40:22 +00:00
prepare_root_cache=
2012-03-04 13:55:13 +00:00
boot_device_id=
2012-03-04 21:18:33 +00:00
title_correction_code=
# Extra indentation to add to menu entries in a submenu. We're not in a submenu
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
2007-05-13 19:28:54 +00:00
2013-11-03 23:15:31 +00:00
is_top_level=true
2007-05-13 19:28:54 +00:00
while [ "x$list" != "x" ] ; do
2009-08-07 12:05:06 +00:00
linux=`version_find_latest $list`
2012-02-03 10:42:22 +00:00
gettext_printf "Found linux image: %s\n" "$linux" >&2
2007-05-13 19:28:54 +00:00
basename=`basename $linux`
dirname=`dirname $linux`
2008-05-30 11:04:08 +00:00
rel_dirname=`make_system_path_relative_to_its_root $dirname`
2007-05-13 19:28:54 +00:00
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
2008-01-02 08:34:41 +00:00
alt_version=`echo $version | sed -e "s,\.old$,,g"`
2008-06-26 07:03:26 +00:00
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
2007-12-29 20:53:20 +00:00
2018-02-24 22:44:58 +00:00
initrd_early=
for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
if test -e "${dirname}/${i}" ; then
initrd_early="${initrd_early} ${i}"
fi
done
initrd_real=
2011-11-03 14:21:47 +00:00
for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
2010-06-26 19:31:40 +00:00
"initrd-${version}" "initramfs-${version}.img" \
"initrd.img-${alt_version}" "initrd-${alt_version}.img" \
2011-03-30 17:22:28 +00:00
"initrd-${alt_version}" "initramfs-${alt_version}.img" \
"initramfs-genkernel-${version}" \
2012-04-18 21:25:21 +00:00
"initramfs-genkernel-${alt_version}" \
"initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
"initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
2007-12-29 20:53:20 +00:00
if test -e "${dirname}/${i}" ; then
2018-02-24 22:44:58 +00:00
initrd_real="${i}"
2007-12-29 20:53:20 +00:00
break
fi
done
2010-10-18 08:08:42 +00:00
2018-02-24 22:44:58 +00:00
initrd=
if test -n "${initrd_early}" || test -n "${initrd_real}"; then
initrd="${initrd_early} ${initrd_real}"
initrd_display=
for i in ${initrd}; do
initrd_display="${initrd_display} ${dirname}/${i}"
done
gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
fi
2011-03-30 18:42:42 +00:00
config=
2013-12-24 16:47:27 +00:00
for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
2011-03-30 18:53:23 +00:00
if test -e "${i}" ; then
config="${i}"
2010-10-18 08:08:42 +00:00
break
fi
done
2011-03-30 18:42:42 +00:00
initramfs=
if test -n "${config}" ; then
initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
fi
2018-02-24 22:44:58 +00:00
if test -z "${initramfs}" && test -z "${initrd_real}" ; then
2012-02-27 18:07:09 +00:00
# "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
2010-10-18 08:08:42 +00:00
# no initrd or builtin initramfs, it can't work here.
2018-04-17 05:36:26 +00:00
if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
|| [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
linux_root_device_thisversion=${GRUB_DEVICE}
else
linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
fi
2007-12-29 20:53:20 +00:00
fi
2013-11-03 23:15:31 +00:00
if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
2012-03-04 21:18:33 +00:00
linux_entry "${OS}" "${version}" simple \
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
2012-09-18 11:04:06 +00:00
submenu_indentation="$grub_tab"
2012-03-04 21:18:33 +00:00
if [ -z "$boot_device_id" ]; then
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
fi
# TRANSLATORS: %s is replaced with an OS name
echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
2013-11-03 23:15:31 +00:00
is_top_level=false
2012-03-04 21:18:33 +00:00
fi
linux_entry "${OS}" "${version}" advanced \
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
2010-10-12 12:47:04 +00:00
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
2012-03-04 21:18:33 +00:00
linux_entry "${OS}" "${version}" recovery \
"single ${GRUB_CMDLINE_LINUX}"
2009-06-21 11:21:59 +00:00
fi
2007-12-29 20:53:20 +00:00
2014-07-08 22:54:30 +00:00
list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
2007-05-04 07:11:44 +00:00
done
2012-03-04 21:18:33 +00:00
# If at least one kernel was found, then we need to
# add a closing '}' for the submenu command.
2013-11-03 23:15:31 +00:00
if [ x"$is_top_level" != xtrue ]; then
2012-03-04 21:18:33 +00:00
echo '}'
fi
echo "$title_correction_code"