summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-05-04 16:12:45 +0100
committerLyndon Brown <jnqnfe@gmail.com>2020-05-04 21:40:13 +0100
commitd7883ec32b2bb907fce17fb759c08c5cd9851fc3 (patch)
tree94b2294140e7c902a33e0262aa6adf5a1d07b98e
parent3f840aeeba982a858a881271a3bb48bca5b50dd8 (diff)
downloadvyos-live-build-d7883ec32b2bb907fce17fb759c08c5cd9851fc3.tar.gz
vyos-live-build-d7883ec32b2bb907fce17fb759c08c5cd9851fc3.zip
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
-rwxr-xr-xfunctions/configuration.sh56
-rwxr-xr-xscripts/build/binary_grub-efi2
-rwxr-xr-xscripts/build/binary_grub-legacy2
-rwxr-xr-xscripts/build/binary_grub-pc2
-rwxr-xr-xscripts/build/binary_hdd21
-rwxr-xr-xscripts/build/binary_syslinux2
-rwxr-xr-xscripts/build/config8
-rwxr-xr-xscripts/build/source_debian9
8 files changed, 60 insertions, 42 deletions
diff --git a/functions/configuration.sh b/functions/configuration.sh
index 85873bdcd..b74ea0e50 100755
--- a/functions/configuration.sh
+++ b/functions/configuration.sh
@@ -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
diff --git a/scripts/build/binary_grub-efi b/scripts/build/binary_grub-efi
index 2fec81d63..2ee26f40d 100755
--- a/scripts/build/binary_grub-efi
+++ b/scripts/build/binary_grub-efi
@@ -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
diff --git a/scripts/build/binary_grub-legacy b/scripts/build/binary_grub-legacy
index 6399b8e5f..4acbd2e50 100755
--- a/scripts/build/binary_grub-legacy
+++ b/scripts/build/binary_grub-legacy
@@ -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
diff --git a/scripts/build/binary_grub-pc b/scripts/build/binary_grub-pc
index ac6fd04a1..f639b1aa1 100755
--- a/scripts/build/binary_grub-pc
+++ b/scripts/build/binary_grub-pc
@@ -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
diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd
index beaff873d..c6aeedb15 100755
--- a/scripts/build/binary_hdd
+++ b/scripts/build/binary_hdd
@@ -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
diff --git a/scripts/build/binary_syslinux b/scripts/build/binary_syslinux
index 2374d5c55..d4f4bf272 100755
--- a/scripts/build/binary_syslinux
+++ b/scripts/build/binary_syslinux
@@ -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
diff --git a/scripts/build/config b/scripts/build/config
index f8fd5ff89..2bd929bc1 100755
--- a/scripts/build/config
+++ b/scripts/build/config
@@ -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}"
diff --git a/scripts/build/source_debian b/scripts/build/source_debian
index 2eed78861..ade03add9 100755
--- a/scripts/build/source_debian
+++ b/scripts/build/source_debian
@@ -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