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@"
. "@datadir@/@PACKAGE@/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"
2011-02-09 11:23:11 +00:00
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${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
if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
2010-07-01 21:24:21 +00:00
|| ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
2010-07-02 11:32:05 +00:00
|| uses_abstraction "${GRUB_DEVICE}" lvm; then
2008-06-26 07:03:26 +00:00
LINUX_ROOT_DEVICE=${GRUB_DEVICE}
2008-05-30 21:53:17 +00:00
else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
fi
2012-02-27 18:07:09 +00:00
GRUBFS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`"
2012-03-10 14:21:25 +00:00
if [ x"$GRUBFS" = x ]; then
GRUBFS="$(stat -f --printf=%T / || true)"
fi
2012-02-27 18:07:09 +00:00
case x"$GRUBFS" in
xbtrfs)
rootsubvol="`make_system_path_relative_to_its_root /`"
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`
2012-02-27 18:07:09 +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
2010-11-01 11:49:40 +00:00
save_default_entry | sed -e "s/^/\t/"
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
2011-05-10 08:40:22 +00:00
if [ x$dirname = x/ ]; then
if [ -z "${prepare_root_cache}" ]; then
prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
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
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
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 ...")"
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-03-29 02:23:12 +00:00
initrd ${rel_dirname}/${initrd}
EOF
fi
2012-03-04 21:18:33 +00:00
sed "s/^/$submenu_indentation/" << EOF
2009-03-29 02:23:12 +00:00
}
EOF
}
2012-04-18 21:25:21 +00:00
machine=`uname -m`
case "x$machine" in
2011-03-29 17:47:34 +00:00
xi?86 | xx86_64)
2011-03-30 17:22:28 +00:00
list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
2011-03-29 17:47:34 +00:00
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done` ;;
*)
2011-03-30 17:22:28 +00:00
list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
2011-03-29 17:47:34 +00:00
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done` ;;
esac
2012-04-18 21:25:21 +00:00
case "$machine" in
i?86) GENKERNEL_ARCH="x86" ;;
mips|mips64) GENKERNEL_ARCH="mips" ;;
mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
arm*) GENKERNEL_ARCH="arm" ;;
*) GENKERNEL_ARCH="$machine" ;;
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
2012-03-04 21:18:33 +00:00
is_first_entry=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
initrd=
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
initrd="$i"
break
fi
done
2010-10-18 08:08:42 +00:00
2011-03-30 18:42:42 +00:00
config=
2011-03-30 18:53:23 +00:00
for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
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
2007-12-29 20:53:20 +00:00
if test -n "${initrd}" ; then
2012-02-03 10:42:22 +00:00
gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
2010-10-18 08:08:42 +00:00
elif test -z "${initramfs}" ; 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.
2008-06-26 07:03:26 +00:00
linux_root_device_thisversion=${GRUB_DEVICE}
2007-12-29 20:53:20 +00:00
fi
2012-03-04 21:18:33 +00:00
if [ "x$is_first_entry" = xtrue ]; then
linux_entry "${OS}" "${version}" simple \
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
submenu_indentation="\t"
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' {"
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
2007-05-13 19:28:54 +00:00
list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
2012-03-04 21:18:33 +00:00
is_first_entry=false
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.
if [ x"$is_first_entry" != xtrue ]; then
echo '}'
fi
echo "$title_correction_code"