|
|
e7f3321 |
#! /bin/sh
|
|
|
e7f3321 |
set -e
|
|
|
e7f3321 |
|
|
|
e7f3321 |
# grub-mkconfig helper script.
|
|
|
e7f3321 |
# Copyright (C) 2011 Michal Ambroz <rebus@seznam.cz>
|
|
|
e7f3321 |
#
|
|
|
e7f3321 |
# you can redistribute it and/or modify
|
|
|
e7f3321 |
# it under the terms of the GNU General Public License as published by
|
|
|
e7f3321 |
# the Free Software Foundation, either version 3 of the License, or
|
|
|
e7f3321 |
# (at your option) any later version.
|
|
|
e7f3321 |
#
|
|
|
e7f3321 |
# Distributed in the hope that it will be useful,
|
|
|
e7f3321 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
e7f3321 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
e7f3321 |
# GNU General Public License for more details.
|
|
|
e7f3321 |
#
|
|
|
e7f3321 |
# You should have received a copy of the GNU General Public License
|
|
|
e7f3321 |
# along with the script. If not, see <http://www.gnu.org/licenses/>.
|
|
|
e7f3321 |
|
|
|
e7f3321 |
prefix=/usr
|
|
|
e7f3321 |
exec_prefix=/usr
|
|
|
e7f3321 |
bindir=/usr/bin
|
|
|
22671c3 |
grublibdir=/usr/share/grub
|
|
|
22671c3 |
. ${grublibdir}/grub-mkconfig_lib
|
|
|
e7f3321 |
|
|
|
e7f3321 |
export TEXTDOMAIN=grub
|
|
|
e7f3321 |
export TEXTDOMAINDIR=${prefix}/share/locale
|
|
|
e7f3321 |
|
|
|
e7f3321 |
CLASS=""
|
|
|
e7f3321 |
|
|
|
e7f3321 |
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
|
|
|
e7f3321 |
OS=Memtest
|
|
|
e7f3321 |
else
|
|
|
e7f3321 |
OS="${GRUB_DISTRIBUTOR} Memtest"
|
|
|
e7f3321 |
fi
|
|
|
e7f3321 |
|
|
|
05c6bab |
CONF_FILE="/etc/memtest86+.conf"
|
|
|
05c6bab |
CONF_ELF_VAR="INSTALL_ELF"
|
|
|
05c6bab |
|
|
|
05c6bab |
MEMTEST86_ELF=`[ -r "$CONF_FILE" ] && sed -n "/^\s*${CONF_ELF_VAR}\s*=/ {s/^\s*${CONF_ELF_VAR}\s*=\s*\(.*\)$/\1/; T end; s/\s*\(\S\)*\s*/\1/; p; :end}" "$CONF_FILE" 2>/dev/null`
|
|
|
05c6bab |
if [ "x${MEMTEST86_ELF}" = "x" ] || [ "x${MEMTEST86_ELF}" = "x1" ] || [ "x${MEMTEST86_ELF}" = "xtrue" ]; then
|
|
|
05c6bab |
MEMTEST86_ELF=1
|
|
|
05c6bab |
BANNER_SUFFIX=
|
|
|
05c6bab |
IMAGE="elf-memtest"
|
|
|
05c6bab |
else
|
|
|
05c6bab |
MEMTEST86_ELF=0
|
|
|
05c6bab |
IMAGE="memtest"
|
|
|
05c6bab |
BANNER_SUFFIX=" (non-ELF)"
|
|
|
05c6bab |
fi
|
|
|
05c6bab |
|
|
|
e7f3321 |
# loop-AES arranges things so that /dev/loop/X can be our root device, but
|
|
|
e7f3321 |
# the initrds that Linux uses don't like that.
|
|
|
e7f3321 |
case ${GRUB_DEVICE} in
|
|
|
e7f3321 |
/dev/loop/*|/dev/loop[0-9])
|
|
|
e7f3321 |
GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
|
|
|
e7f3321 |
;;
|
|
|
e7f3321 |
esac
|
|
|
e7f3321 |
|
|
|
e7f3321 |
if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
|
|
|
e7f3321 |
|| ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
|
|
|
e7f3321 |
|| uses_abstraction "${GRUB_DEVICE}" lvm; then
|
|
|
e7f3321 |
LINUX_ROOT_DEVICE=${GRUB_DEVICE}
|
|
|
e7f3321 |
else
|
|
|
e7f3321 |
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
|
|
|
e7f3321 |
fi
|
|
|
e7f3321 |
|
|
|
e7f3321 |
if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then
|
|
|
e7f3321 |
rootsubvol="`make_system_path_relative_to_its_root /`"
|
|
|
e7f3321 |
rootsubvol="${rootsubvol#/}"
|
|
|
e7f3321 |
if [ "x${rootsubvol}" != x ]; then
|
|
|
e7f3321 |
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
|
|
|
e7f3321 |
fi
|
|
|
e7f3321 |
fi
|
|
|
e7f3321 |
|
|
|
e7f3321 |
memtest_entry ()
|
|
|
e7f3321 |
{
|
|
|
e7f3321 |
os="$1"
|
|
|
e7f3321 |
version="$2"
|
|
|
e7f3321 |
recovery="$3"
|
|
|
e7f3321 |
args="$4"
|
|
|
e7f3321 |
title="$(gettext_quoted "%s %s")"
|
|
|
05c6bab |
printf "menuentry '${title}${BANNER_SUFFIX}' {\n" "${os}" "${version}"
|
|
|
e7f3321 |
|
|
|
e7f3321 |
|
|
|
e7f3321 |
if [ x$dirname = x/ ]; then
|
|
|
e7f3321 |
if [ -z "${prepare_root_cache}" ]; then
|
|
|
e7f3321 |
prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/")"
|
|
|
e7f3321 |
fi
|
|
|
e7f3321 |
printf '%s\n' "${prepare_root_cache}"
|
|
|
e7f3321 |
else
|
|
|
e7f3321 |
if [ -z "${prepare_boot_cache}" ]; then
|
|
|
e7f3321 |
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
|
|
e7f3321 |
fi
|
|
|
e7f3321 |
printf '%s\n' "${prepare_boot_cache}"
|
|
|
e7f3321 |
fi
|
|
|
05c6bab |
message="$(gettext_printf "Loading %s %s ..." "${os}" "${version}")"
|
|
|
05c6bab |
if [ "x${MEMTEST86_ELF}" = "x1" ]; then
|
|
|
05c6bab |
cat << EOF
|
|
|
4e39524 |
insmod bsd
|
|
|
e7f3321 |
echo '$message'
|
|
|
4e39524 |
knetbsd ${rel_dirname}/${basename}
|
|
|
e7f3321 |
}
|
|
|
e7f3321 |
EOF
|
|
|
05c6bab |
else
|
|
|
05c6bab |
cat << EOF
|
|
|
05c6bab |
echo '$message'
|
|
|
05c6bab |
linux16 ${rel_dirname}/${basename}
|
|
|
05c6bab |
}
|
|
|
05c6bab |
EOF
|
|
|
05c6bab |
fi
|
|
|
e7f3321 |
}
|
|
|
e7f3321 |
|
|
|
e7f3321 |
case x`uname -m` in
|
|
|
e7f3321 |
xi?86 | xx86_64)
|
|
|
05c6bab |
list=`for i in /boot/${IMAGE}* ; do
|
|
|
e7f3321 |
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
|
|
e7f3321 |
done` ;;
|
|
|
e7f3321 |
*)
|
|
|
05c6bab |
list=`for i in /boot/${IMAGE}* ; do
|
|
|
e7f3321 |
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
|
|
|
e7f3321 |
done` ;;
|
|
|
e7f3321 |
esac
|
|
|
e7f3321 |
|
|
|
e7f3321 |
prepare_boot_cache=
|
|
|
e7f3321 |
prepare_root_cache=
|
|
|
e7f3321 |
|
|
|
e7f3321 |
while [ "x$list" != "x" ] ; do
|
|
|
e7f3321 |
linux=`version_find_latest $list`
|
|
|
e7f3321 |
echo "Found memtest image: $linux" >&2
|
|
|
e7f3321 |
basename=`basename $linux`
|
|
|
e7f3321 |
dirname=`dirname $linux`
|
|
|
e7f3321 |
rel_dirname=`make_system_path_relative_to_its_root $dirname`
|
|
|
e7f3321 |
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
|
|
|
e7f3321 |
alt_version=`echo $version | sed -e "s,\.old$,,g"`
|
|
|
e7f3321 |
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
|
|
|
e7f3321 |
|
|
|
e7f3321 |
|
|
|
e7f3321 |
memtest_entry "${OS}" "${version}" false \
|
|
|
e7f3321 |
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
|
|
|
e7f3321 |
|
|
|
e7f3321 |
list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
|
|
|
e7f3321 |
done
|