Clean up grub configuration code

* Use only long kernel names.
* Put advanced options in a submenu.
* Use distro-agnostic labels.
* Don't generate entries with kernel version when we have a single
  version.
This commit is contained in:
Raphaël Hertzog 2016-12-02 22:41:55 +01:00
parent 9c974b26bf
commit f7bb86fd58
3 changed files with 79 additions and 142 deletions

2
debian/changelog vendored
View File

@ -44,6 +44,8 @@ live-build (1:20161128) UNRELEASED; urgency=medium
* Update the way we generate the version of live-build that is displayed by
lb --version.
* Instead of renaming kernel for syslinux, create hardlinks.
* Simplify grub configuration code to use only long kernel names. Put
advanced options in a submenu. Use distro-agnostic labels.
[ Kristian Klausen ]
* Include ext{3,4} journal size when calculating image size. Closes: #801712

View File

@ -64,7 +64,7 @@ Grub_live_entry ()
local INITRD="${3}"
local APPEND="${4}"
LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"${LABEL}\" {"
Grub_live_entry_commands "${KERNEL}" "${INITRD}" "${APPEND} findiso=\${iso_path}"
LINUX_LIVE="${LINUX_LIVE}\n}"
}
@ -72,19 +72,30 @@ Grub_live_entry ()
Grub_install_entry ()
{
LABEL="${1}"
KERNEL="${2}"
INITRD="${3}"
APPEND="${4}"
TYPE="${2}"
KERNEL="${3}"
INITRD="${4}"
APPEND="${5}"
if [ "${LABEL}" != "rescue" ] && [ "${LABEL}" != "rescuegui" ]
if [ "${TYPE}" != "rescue" ] && [ "${TYPE}" != "rescuegui" ]
then
APPEND="${APPEND} quiet"
fi
LINUX_INSTALL="${LINUX_INSTALL}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
LINUX_INSTALL="${LINUX_INSTALL}\nlinux\t\t/${KERNEL} ${APPEND} LB_BOOTAPPEND_INSTALL"
LINUX_INSTALL="${LINUX_INSTALL}\ninitrd\t\t/${INITRD}"
LINUX_INSTALL="${LINUX_INSTALL}\n}"
if [ -z "$LINUX_INSTALL" ]; then
# First entry recorded in LINUX_INSTALL
LINUX_INSTALL="#\t \"Installer\"\n"
LINUX_INSTALL="${LINUX_INSTALL}\nmenuentry \"${LABEL}\" {"
LINUX_INSTALL="${LINUX_INSTALL}\nlinux\t\t/${KERNEL} ${APPEND} LB_BOOTAPPEND_INSTALL"
LINUX_INSTALL="${LINUX_INSTALL}\ninitrd\t\t/${INITRD}"
LINUX_INSTALL="${LINUX_INSTALL}\n}"
else
# Remaining entries recorded in LINUX_ADVANCED_INSTALL
LINUX_ADVANCED_INSTALL="${LINUX_ADVANCED_INSTALL}\nmenuentry \"${LABEL}\" {"
LINUX_ADVANCED_INSTALL="${LINUX_ADVANCED_INSTALL}\nlinux\t\t/${KERNEL} ${APPEND} LB_BOOTAPPEND_INSTALL"
LINUX_ADVANCED_INSTALL="${LINUX_ADVANCED_INSTALL}\ninitrd\t\t/${INITRD}"
LINUX_ADVANCED_INSTALL="${LINUX_ADVANCED_INSTALL}\n}"
fi
}
Grub_live_autodetect_entry ()
@ -96,7 +107,7 @@ Grub_live_autodetect_entry ()
local _486_INITRD="${5}"
local APPEND="${6}"
LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"Debian GNU/Linux - ${LABEL}\" {"
LINUX_LIVE="${LINUX_LIVE}\nmenuentry \"${LABEL}\" {"
LINUX_LIVE="${LINUX_LIVE}\nif cpuid -l ; then"
Grub_live_entry_commands "${AMD64_KERNEL}" "${AMD64_INITRD}" "${APPEND} findiso=\${iso_path}"
LINUX_LIVE="${LINUX_LIVE}\nelse"
@ -200,141 +211,57 @@ fi
LB_BOOTAPPEND_LIVE="$(echo ${LB_BOOTAPPEND_LIVE} | sed -e 's| ||')"
# Assembling kernel configuration
# If Bootloader is not syslinux that means
# binary_syslinux it's not going to rename kernel filenames in a later stage.
# We will use binary_grub2 algorithm which does not rename kernel filenames.
_AMD64_486_NUMBER="0"
FOUND_SYSLINUX=""
OLDIFS="$IFS"
IFS=","
for BOOTLOADER in ${LB_BOOTLOADERS}
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
case ${BOOTLOADER} in
"syslinux" )
FOUND_SYSLINUX="True"
break ;;
esac
if [ "${_FLAVOUR}" = "amd64" -o "${_FLAVOUR}" = "486" ] ; then
_AMD64_486_NUMBER="$((${_AMD64_486_NUMBER} + 1))"
fi
done
IFS="$OLDIFS"
if [ -z ${FOUND_SYSLINUX} ]
then
_AMD64_486_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
if [ "${_FLAVOUR}" = "amd64" -o "${_FLAVOUR}" = "486" ] ; then
_AMD64_486_NUMBER="$((${_AMD64_486_NUMBER} + 1))"
fi
done
if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
# Default entries
AMD64_KERNEL="$(basename chroot/boot/vmlinuz-*amd64)"
AMD64_INITRD="initrd.img-$(echo ${AMD64_KERNEL} | sed -e 's|vmlinuz-||')"
_486_KERNEL="$(basename chroot/boot/vmlinuz-*486)"
_486_INITRD="initrd.img-$(echo ${_486_KERNEL} | sed -e 's|vmlinuz-||')"
Grub_live_autodetect_entry "live (autodetect)" \
"${INITFS}/${AMD64_KERNEL}" \
"${INITFS}/${AMD64_INITRD}" \
"${INITFS}/${_486_KERNEL}" \
"${INITFS}/${_486_INITRD}"
fi
if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
# Default entries
DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
AMD64_KERNEL="$(basename chroot/boot/vmlinuz-*amd64)"
AMD64_INITRD="initrd.img-$(echo ${AMD64_KERNEL} | sed -e 's|vmlinuz-||')"
_486_KERNEL="$(basename chroot/boot/vmlinuz-*486)"
_486_INITRD="initrd.img-$(echo ${_486_KERNEL} | sed -e 's|vmlinuz-||')"
Grub_live_entry "live" "${INITFS}/${DEFAULT_KERNEL}" "${INITFS}/${DEFAULT_INITRD}"
Grub_live_autodetect_entry "live (autodetect)" \
"${INITFS}/${AMD64_KERNEL}" \
"${INITFS}/${AMD64_INITRD}" \
"${INITFS}/${_486_KERNEL}" \
"${INITFS}/${_486_INITRD}"
fi
if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
then
Grub_live_entry "live (fail-safe mode)" "${INITFS}/${DEFAULT_KERNEL}" "${INITFS}/${DEFAULT_INITRD}" "${LB_BOOTAPPEND_FAILSAFE}"
fi
# Default entries
DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
DEFAULT_KERNEL="$(basename chroot/boot/vmlinuz-*${DEFAULT_FLAVOUR})"
DEFAULT_INITRD="initrd.img-$(echo ${DEFAULT_KERNEL} | sed -e 's|vmlinuz-||')"
Grub_live_entry "Boot live system" "${INITFS}/${DEFAULT_KERNEL}" "${INITFS}/${DEFAULT_INITRD}"
if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]
then
Grub_live_entry "Boot live system (fail-safe mode)" "${INITFS}/${DEFAULT_KERNEL}" "${INITFS}/${DEFAULT_INITRD}" "${LB_BOOTAPPEND_FAILSAFE}"
fi
_COUNT=0
for KERNEL in chroot/boot/vmlinuz-*; do
_COUNT=$(( $COUNT + 1 ))
done
if [ $_COUNT -gt 1 ]; then
for KERNEL in chroot/boot/vmlinuz-*
do
VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
Grub_live_entry "live, kernel ${VERSION}" "${INITFS}/$(basename ${KERNEL})" "${INITFS}/initrd.img-${VERSION}"
Grub_live_entry "live, kernel ${VERSION} (fail-safe mode)" "${INITFS}/$(basename ${KERNEL})" "${INITFS}/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
Grub_live_entry "Boot live system, kernel ${VERSION}" "${INITFS}/$(basename ${KERNEL})" "${INITFS}/initrd.img-${VERSION}"
if [ "${LB_BOOTAPPEND_FAILSAFE}" != "none" ]; then
Grub_live_entry "Boot live system, kernel ${VERSION} (fail-safe mode)" "${INITFS}/$(basename ${KERNEL})" "${INITFS}/initrd.img-${VERSION}" "${LB_BOOTAPPEND_FAILSAFE}"
fi
done
else # LB_BOOTLOADERS does not contain syslinux
# If one of the bootloader is syslinux that means
# binary_syslinux it's going to rename kernel filenames.
# We will use binary_syslinux algorithm but without renaming kernel filenames.
# That will ensure binary_syslinux will find the original kernel filenames.
#if [ -e "${_TARGET}/live.cfg.in" ]
#then
# This is all rather suboptimal.. needs prettifying at some point
_FLAVOURS="$(echo ${LB_LINUX_FLAVOURS} | wc -w)"
case "${_FLAVOURS}" in
1)
Grub_live_entry "live (${LB_LINUX_FLAVOURS})" "${INITFS}/vmlinuz" "${INITFS}/initrd.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${LB_LINUX_FLAVOURS}) (failsafe mode)" "${INITFS}/vmlinuz" "${INITFS}/initrd.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
;;
*)
_AMD64_486_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
if [ "${_FLAVOUR}" = "amd64" -o "${_FLAVOUR}" = "486" ] ; then
_AMD64_486_NUMBER="$((${_AMD64_486_NUMBER} + 1))"
fi
done
_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
_NUMBER="$((${_NUMBER} + 1))"
if [ "${_FLAVOUR}" = "amd64" ] ; then
AMD64_KERNEL="vmlinuz${_NUMBER}"
AMD64_INITRD="initrd${_NUMBER}.img"
fi
if [ "${_FLAVOUR}" = "486" ] ; then
_486_KERNEL="vmlinuz${_NUMBER}"
_486_INITRD="initrd${_NUMBER}.img"
fi
done
_NUMBER="0"
for _FLAVOUR in ${LB_LINUX_FLAVOURS}
do
_NUMBER="$((${_NUMBER} + 1))"
if [ "${_NUMBER}" -gt 1 ]
then
Grub_live_entry "live (${_FLAVOUR})" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${_FLAVOUR}) (failsafe mode)" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
else
if [ "${_AMD64_486_NUMBER}" -ge 2 ] ; then
Grub_live_autodetect_entry "live (autodetect)" \
"${INITFS}/${AMD64_KERNEL}" \
"${INITFS}/${AMD64_INITRD}" \
"${INITFS}/${_486_KERNEL}" \
"${INITFS}/${_486_INITRD}"
fi
Grub_live_entry "live (${_FLAVOUR})" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE}"
Grub_live_entry "live (${_FLAVOUR}) (failsafe mode)" "${INITFS}/vmlinuz${_NUMBER}" "${INITFS}/initrd${_NUMBER}.img" "${LB_BOOTAPPEND_LIVE_FAILSAFE}"
fi
done
;;
esac
#fi
fi
LINUX_LIVE="$(/bin/echo ${LINUX_LIVE} | sed -e 's|binary||g' -e 's|//|/|g')"
@ -342,7 +269,6 @@ LINUX_LIVE="$(/bin/echo ${LINUX_LIVE} | sed -e 's|binary||g' -e 's|//|/|g')"
if [ "${LB_DEBIAN_INSTALLER}" != "false" ]
then
LINUX_LIVE="#\t \"Live\"\n${LINUX_LIVE}"
LINUX_INSTALL="#\t \"Installer\"\n"
VMLINUZ_DI="install/vmlinuz"
INITRD_DI="install/initrd.gz"
@ -352,17 +278,20 @@ then
INITRD_GI="install/gtk/initrd.gz"
APPEND_GI="video=vesa:ywrap,mtrr vga=788"
Grub_install_entry "install" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
Grub_install_entry "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
Grub_install_entry "expert" "${VMLINUZ_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
Grub_install_entry "expertgui" "${VMLINUZ_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
Grub_install_entry "rescue" "${VMLINUZ_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
Grub_install_entry "rescuegui" "${VMLINUZ_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
Grub_install_entry "auto" "${VMLINUZ_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
Grub_install_entry "autogui" "${VMLINUZ_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
Grub_install_entry "Start installer" "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
Grub_install_entry "Install in graphical mode" "installgui" "${VMLINUZ_GI}" "${INITRD_GI}" "${APPEND_GI}"
Grub_install_entry "Install in text mode" "install" "${VMLINUZ_DI}" "${INITRD_DI}" "${APPEND_DI}"
Grub_install_entry "Expert install in graphical mode" "expertgui" "${VMLINUZ_GI}" "${INITRD_GI}" "priority=low ${APPEND_GI}"
Grub_install_entry "Expert install in text mode" "expert" "${VMLINUZ_DI}" "${INITRD_DI}" "priority=low ${APPEND_DI}"
Grub_install_entry "Automatic install in graphical mode" "autogui" "${VMLINUZ_GI}" "${INITRD_GI}" "auto=true priority=critical ${APPEND_GI}"
Grub_install_entry "Automatic install in text mode" "auto" "${VMLINUZ_DI}" "${INITRD_DI}" "auto=true priority=critical ${APPEND_DI}"
Grub_install_entry "Rescue system in graphical mode" "rescuegui" "${VMLINUZ_GI}" "${INITRD_GI}" "rescue/enable=true ${APPEND_GI}"
Grub_install_entry "Rescue system in text mode" "rescue" "${VMLINUZ_DI}" "${INITRD_DI}" "rescue/enable=true ${APPEND_DI}"
fi
LINUX_INSTALL="$(/bin/echo ${LINUX_INSTALL} | sed -e 's|binary||g' -e 's|//|/|g')"
LINUX_ADVANCED_INSTALL="$(/bin/echo ${LINUX_ADVANCED_INSTALL} | sed -e 's|binary||g' -e 's|//|/|g')"
# Assembling memtest configuration
if [ -f "${DESTDIR_LIVE}"/memtest ]
@ -376,7 +305,7 @@ fi
mkdir -p binary/boot/grub
cp -a "${_SOURCE}"/* binary/boot/grub/
sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/*.cfg
sed -i -e "s|LINUX_LIVE|${LINUX_LIVE}|" -e "s|LINUX_ADVANCED_INSTALL|${LINUX_ADVANCED_INSTALL}|" -e "s|LINUX_INSTALL|${LINUX_INSTALL}|" -e "s|MEMTEST|${MEMTEST}|" binary/boot/grub/*.cfg
sed -i -e "s#LB_BOOTAPPEND_INSTALL#${LB_BOOTAPPEND_INSTALL}#" -e "s#LB_BOOTAPPEND_LIVE#${LB_BOOTAPPEND_LIVE}#" binary/boot/grub/*.cfg
sed -i -e 's|\ $||g' binary/boot/grub/*.cfg

View File

@ -31,4 +31,10 @@ LINUX_LIVE
LINUX_INSTALL
submenu 'Advanced options...' {
LINUX_ADVANCED_INSTALL
MEMTEST
}