2N/A#! /bin/sh
2N/Aset -e
2N/A
2N/A# grub-mkconfig helper script.
2N/A# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
2N/A#
2N/A# GRUB is free software: you can redistribute it and/or modify
2N/A# it under the terms of the GNU General Public License as published by
2N/A# the Free Software Foundation, either version 3 of the License, or
2N/A# (at your option) any later version.
2N/A#
2N/A# GRUB is distributed in the hope that it will be useful,
2N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A# GNU General Public License for more details.
2N/A#
2N/A# You should have received a copy of the GNU General Public License
2N/A# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A
2N/Aprefix=@prefix@
2N/Aexec_prefix=@exec_prefix@
2N/Abindir=@bindir@
2N/Alibdir=@libdir@
2N/Adatarootdir=@datarootdir@
2N/A. ${libdir}/@PACKAGE@/grub-mkconfig_lib
2N/A
2N/Aexport TEXTDOMAIN=@PACKAGE@
2N/Aexport TEXTDOMAINDIR=@localedir@
2N/A
2N/ACLASS="--class gnu-linux --class gnu --class os --class xen"
2N/A
2N/Aif [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
2N/A OS=GNU/Linux
2N/Aelse
2N/A OS="${GRUB_DISTRIBUTOR} GNU/Linux"
2N/A CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
2N/Afi
2N/A
2N/A# loop-AES arranges things so that /dev/loop/X can be our root device, but
2N/A# the initrds that Linux uses don't like that.
2N/Acase ${GRUB_DEVICE} in
2N/A /dev/loop/*|/dev/loop[0-9])
2N/A GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
2N/A ;;
2N/Aesac
2N/A
2N/Aif [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
2N/A || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
2N/A || uses_abstraction "${GRUB_DEVICE}" lvm; then
2N/A LINUX_ROOT_DEVICE=${GRUB_DEVICE}
2N/Aelse
2N/A LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
2N/Afi
2N/A
2N/A# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
2N/Aif [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
2N/A GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
2N/Afi
2N/Aif [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
2N/A GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
2N/Afi
2N/A
2N/Aif [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then
2N/A rootsubvol="`make_system_path_relative_to_its_root /`"
2N/A rootsubvol="${rootsubvol#/}"
2N/A if [ "x${rootsubvol}" != x ]; then
2N/A GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
2N/A fi
2N/Afi
2N/A
2N/Alinux_entry ()
2N/A{
2N/A os="$1"
2N/A version="$2"
2N/A xen_version="$3"
2N/A recovery="$4"
2N/A args="$5"
2N/A xen_args="$6"
2N/A if ${recovery} ; then
2N/A title="$(gettext_quoted "%s, with Xen %s and Linux %s (recovery mode)")"
2N/A else
2N/A title="$(gettext_quoted "%s, with Xen %s and Linux %s")"
2N/A fi
2N/A printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${xen_version}" "${version}"
2N/A if ! ${recovery} ; then
2N/A save_default_entry | sed -e "s/^/\t/"
2N/A fi
2N/A
2N/A if [ -z "${prepare_boot_cache}" ]; then
2N/A prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
2N/A fi
2N/A printf '%s\n' "${prepare_boot_cache}"
2N/A xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
2N/A lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
2N/A cat << EOF
2N/A echo '$xmessage'
2N/A multiboot ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
2N/A echo '$lmessage'
2N/A module ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
2N/AEOF
2N/A if test -n "${initrd}" ; then
2N/A message="$(gettext_printf "Loading initial ramdisk ...")"
2N/A cat << EOF
2N/A echo '$message'
2N/A module ${rel_dirname}/${initrd}
2N/AEOF
2N/A fi
2N/A cat << EOF
2N/A}
2N/AEOF
2N/A}
2N/A
2N/Alinux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
2N/A if grub_file_is_not_garbage "$i"; then
2N/A basename=$(basename $i)
2N/A version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
2N/A dirname=$(dirname $i)
2N/A config=
2N/A for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
2N/A if test -e "${j}" ; then
2N/A config="${j}"
2N/A break
2N/A fi
2N/A done
2N/A if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi
2N/A fi
2N/A done`
2N/Aif [ "x${linux_list}" = "x" ] ; then
2N/A exit 0
2N/Afi
2N/Axen_list=`for i in /boot/xen*; do
2N/A if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
2N/A done`
2N/Aprepare_boot_cache=
2N/A
2N/Awhile [ "x${xen_list}" != "x" ] ; do
2N/A list="${linux_list}"
2N/A current_xen=`version_find_latest $xen_list`
2N/A xen_basename=`basename ${current_xen}`
2N/A xen_dirname=`dirname ${current_xen}`
2N/A rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
2N/A xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
2N/A echo "submenu \"Xen ${xen_version}\" {"
2N/A while [ "x$list" != "x" ] ; do
2N/A linux=`version_find_latest $list`
2N/A echo "Found linux image: $linux" >&2
2N/A basename=`basename $linux`
2N/A dirname=`dirname $linux`
2N/A rel_dirname=`make_system_path_relative_to_its_root $dirname`
2N/A version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
2N/A alt_version=`echo $version | sed -e "s,\.old$,,g"`
2N/A linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
2N/A
2N/A initrd=
2N/A for i in "initrd.img-${version}" "initrd-${version}.img" \
2N/A "initrd-${version}" "initrd.img-${alt_version}" \
2N/A "initrd-${alt_version}.img" "initrd-${alt_version}" \
2N/A "initramfs-genkernel-${version}" \
2N/A "initramfs-genkernel-${alt_version}" ; do
2N/A if test -e "${dirname}/${i}" ; then
2N/A initrd="$i"
2N/A break
2N/A fi
2N/A done
2N/A if test -n "${initrd}" ; then
2N/A echo "Found initrd image: ${dirname}/${initrd}" >&2
2N/A else
2N/A # "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
2N/A linux_root_device_thisversion=${GRUB_DEVICE}
2N/A fi
2N/A
2N/A linux_entry "${OS}" "${version}" "${xen_version}" false \
2N/A "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
2N/A if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
2N/A linux_entry "${OS}" "${version}" "${xen_version}" true \
2N/A "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
2N/A fi
2N/A
2N/A list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
2N/A done
2N/A echo "}"
2N/A xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
2N/Adone