config: improve BIOS/EFI bootloader selection handling

the design choice from when EFI support was introduced was to change
`--bootloader` to `--bootloaders`, with users specifying their selection
of BIOS and EFI bootloaders together. at this time there were not even any
decent validation checks being performed, and invalid combinations could
cause some chaos.

since then proper validation was put in place, including checking that
only a single instance of each of BIOS and EFI bootloaders exists in the
selection.

here we tweak things such that we stick with the same option, but we split
the selection up such that we store the BIOS and EFI selections separately
within the saved config file, and offer it up to scripts to help simplify
those scripts.

we must however retain support for splitting from the combined option,
both because we still use it in the combined option, and for backwards
compatibility with older saved configs.

Gbp-Dch: Short
This commit is contained in:
Lyndon Brown 2020-05-04 16:12:45 +01:00
parent 3f840aeeba
commit d7883ec32b
8 changed files with 60 additions and 42 deletions

View File

@ -287,24 +287,33 @@ Prepare_config ()
;;
esac
if [ -z "${LB_BOOTLOADERS}" ]
then
case "${LB_ARCHITECTURE}" in
amd64|i386)
case "${LB_IMAGE_TYPE}" in
hdd|netboot)
LB_BOOTLOADERS="syslinux"
;;
*)
LB_BOOTLOADERS="syslinux,grub-efi"
;;
esac
;;
esac
case "${LB_ARCHITECTURE}" in
amd64|i386)
LB_BOOTLOADER_BIOS="${LB_BOOTLOADER_BIOS:-syslinux}"
if ! In_list "${LB_IMAGE_TYPE}" hdd netboot; then
LB_BOOTLOADER_EFI="${LB_BOOTLOADER_EFI:-grub-efi}"
fi
;;
esac
# Command line option combines BIOS and EFI selection in one.
# Also, need to support old config files that held `LB_BOOTLOADERS`.
# Note that this function does not perform validation, so none is done here.
if [ -n "${LB_BOOTLOADERS}" ]; then
LB_BOOTLOADERS="$(echo "${LB_BOOTLOADERS}" | tr "," " ")"
unset LB_BOOTLOADER_BIOS
unset LB_BOOTLOADER_EFI
local BOOTLOADER
for BOOTLOADER in $LB_BOOTLOADERS; do
case "${BOOTLOADER}" in
grub-legacy|grub-pc|syslinux)
LB_BOOTLOADER_BIOS="${BOOTLOADER}"
;;
grub-efi)
LB_BOOTLOADER_EFI="${BOOTLOADER}"
;;
esac
done
fi
LB_BOOTLOADERS="$(echo "${LB_BOOTLOADERS}" | tr "," " ")"
LB_FIRST_BOOTLOADER=$(echo "${LB_BOOTLOADERS}" | awk '{ print $1 }')
LB_CHECKSUMS="${LB_CHECKSUMS:-sha256}"
@ -572,9 +581,18 @@ Validate_config_permitted_values ()
exit 1
fi
if [ -z "${LB_BOOTLOADERS}" ]; then
if [ -z "${LB_BOOTLOADER_BIOS}" ] && [ -z "${LB_BOOTLOADER_EFI}" ]; then
Echo_warning "You have specified no bootloaders; I predict that you will experience some problems!"
else
fi
if [ -n "${LB_BOOTLOADER_BIOS}" ] && ! In_list "${LB_BOOTLOADER_BIOS}" grub-legacy grub-pc syslinux; then
Echo_error "You have specified an invalid BIOS bootloader."
exit 1
fi
if [ -n "${LB_BOOTLOADER_EFI}" ] && ! In_list "${LB_BOOTLOADER_EFI}" grub-efi; then
Echo_error "You have specified an invalid EFI bootloader."
exit 1
fi
if [ -n "${LB_BOOTLOADERS}" ]; then
local BOOTLOADER
local BOOTLOADERS_BIOS=0
local BOOTLOADERS_EFI=0

View File

@ -21,7 +21,7 @@ USAGE="${PROGRAM} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
if ! In_list "grub-efi" $LB_BOOTLOADERS; then
if [ "${LB_BOOTLOADER_EFI}" != "grub-efi" ]; then
exit 0
fi

View File

@ -21,7 +21,7 @@ USAGE="${PROGRAM} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
if ! In_list "grub-legacy" $LB_BOOTLOADERS; then
if [ "${LB_BOOTLOADER_BIOS}" != "grub-legacy" ]; then
exit 0
fi

View File

@ -21,7 +21,7 @@ USAGE="${PROGRAM} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
if ! In_list "grub-pc" $LB_BOOTLOADERS; then
if [ "${LB_BOOTLOADER_BIOS}" != "grub-pc" ]; then
exit 0
fi

View File

@ -52,15 +52,11 @@ Check_package chroot /sbin/parted parted
Check_package host /sbin/fdisk fdisk
Check_package host /sbin/losetup mount
for BOOTLOADER in ${LB_BOOTLOADERS}; do
case "${BOOTLOADER}" in
grub-legacy)
Check_package chroot /usr/sbin/grub grub
;;
esac
done
case "${LB_BOOTLOADER_BIOS}" in
grub-legacy)
Check_package chroot /usr/sbin/grub grub
;;
case ${LB_FIRST_BOOTLOADER} in
syslinux)
case ${LB_BINARY_FILESYSTEM} in
fat*|ntfs)
@ -189,8 +185,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
then
if [ "${LB_BOOTLOADER_BIOS}" = "syslinux" ]; then
dd if=chroot/usr/lib/$(echo ${_BOOTLOADER} | tr [a-z] [A-Z])/mbr.bin of=${FREELO} bs=440 count=1
fi
;;
@ -209,8 +204,7 @@ case "${LB_BUILD_WITH_CHROOT}" in
parted -s "${FREELO}" set 1 boot on || true
parted -s "${FREELO}" set 1 lba off || true
if [ "${LB_FIRST_BOOTLOADER}" = "syslinux" ]
then
if [ "${LB_BOOTLOADER_BIOS}" = "syslinux" ]; then
dd if=/usr/lib/$(echo ${_BOOTLOADER} | tr [a-z] [A-Z])/mbr.bin of=${FREELO} bs=440 count=1
fi
;;
@ -275,8 +269,7 @@ cp -T ${CP_OPTIONS} binary/ chroot/binary.tmp
FIXME()
{
if [ "${LB_FIRST_BOOTLOADER}" = "grub-legacy" ]
then
if [ "${LB_BOOTLOADER_BIOS}" = "grub-legacy" ]; then
cat > chroot/grub.sh << EOF
#!/bin/sh

View File

@ -21,7 +21,7 @@ USAGE="${PROGRAM} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
if ! In_list "syslinux" $LB_BOOTLOADERS; then
if [ "${LB_BOOTLOADER_BIOS}" != "syslinux" ]; then
exit 0
fi

View File

@ -364,6 +364,7 @@ Local_arguments ()
;;
--bootloaders|--bootloader)
# This will be split up into BIOS and EFI selections by `Prepare_config()`
LB_BOOTLOADERS="${2}"
shift 2
;;
@ -1182,8 +1183,11 @@ LB_BOOTAPPEND_INSTALL="${LB_BOOTAPPEND_INSTALL}"
# Set boot parameters
LB_BOOTAPPEND_LIVE_FAILSAFE="${LB_BOOTAPPEND_LIVE_FAILSAFE}"
# Set bootloaders
LB_BOOTLOADERS="${LB_BOOTLOADERS}"
# Set BIOS bootloader
LB_BOOTLOADER_BIOS="${LB_BOOTLOADER_BIOS}"
# Set EFI bootloader
LB_BOOTLOADER_EFI="${LB_BOOTLOADER_EFI}"
# Set checksums
LB_CHECKSUMS="${LB_CHECKSUMS}"

View File

@ -54,9 +54,12 @@ Chroot chroot "sh source-selection.sh"
rm -f chroot/source-selection.sh
mv chroot/source-selection.txt ./
for BOOTLOADER in ${LB_BOOTLOADERS}; do
echo "${BOOTLOADER}" >> source-selection.txt
done
if [ -n "${LB_BOOTLOADER_BIOS}" ]; then
echo "${LB_BOOTLOADER_BIOS}" >> source-selection.txt
fi
if [ -n "${LB_BOOTLOADER_EFI}" ]; then
echo "${LB_BOOTLOADER_EFI}" >> source-selection.txt
fi
echo "live-build" >> source-selection.txt