Harden GRUB recipe with error guards and host-tool verification

Add || exit 1 to all critical build steps (mkdir, cd, touch, configure,
make, grub-mkimage) so failures surface immediately instead of silently
continuing. Verify gcc/make/bison/flex are present before starting the
build. Update grub.cfg help text to reference fat_tool.py instead of
unavailable mtools.
This commit is contained in:
2026-04-17 22:02:47 +01:00
parent 3fb2d55171
commit 8bc64b0a5e
2 changed files with 17 additions and 9 deletions
+3 -3
View File
@@ -6,9 +6,9 @@
# Place this file at EFI/BOOT/grub.cfg on the ESP. # Place this file at EFI/BOOT/grub.cfg on the ESP.
# The install-grub.sh script handles this automatically. # The install-grub.sh script handles this automatically.
# #
# To customize: edit this file before running install-grub.sh, # To customize: edit this file before building GRUB (make r.grub),
# or modify the ESP directly with mtools: # or modify the ESP directly with fat_tool.py:
# mcopy -i harddrive.img@@1048576 grub.cfg ::EFI/BOOT/grub.cfg # python3 local/scripts/fat_tool.py cp-in harddrive.img 1048576 grub.cfg EFI/BOOT/grub.cfg
set default=0 set default=0
set timeout=5 set timeout=5
+14 -6
View File
@@ -26,12 +26,20 @@ script = """
unset CC CXX CPP LD AR NM RANLIB OBJCOPY STRIP PKG_CONFIG unset CC CXX CPP LD AR NM RANLIB OBJCOPY STRIP PKG_CONFIG
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
# Verify host tools are available before starting the build.
for tool in gcc make bison flex; do
if ! command -v "${tool}" &>/dev/null; then
echo "ERROR: Required host tool '${tool}' not found" >&2
exit 1
fi
done
# Out-of-tree build (GRUB requires this for some configurations) # Out-of-tree build (GRUB requires this for some configurations)
mkdir -p "${COOKBOOK_BUILD}/grub-build" mkdir -p "${COOKBOOK_BUILD}/grub-build" || exit 1
cd "${COOKBOOK_BUILD}/grub-build" cd "${COOKBOOK_BUILD}/grub-build" || exit 1
# GRUB release tarballs miss extra_deps.lst (normally generated by autogen.sh) # GRUB release tarballs miss extra_deps.lst (normally generated by autogen.sh)
touch "${COOKBOOK_SOURCE}/grub-core/extra_deps.lst" touch "${COOKBOOK_SOURCE}/grub-core/extra_deps.lst" || exit 1
# Configure for host, targeting x86_64 EFI platform output. # Configure for host, targeting x86_64 EFI platform output.
# --target=x86_64 means "produce boot images for x86_64" # --target=x86_64 means "produce boot images for x86_64"
@@ -48,10 +56,10 @@ echo "Configuring GRUB for x86_64 EFI..."
--disable-grub-mount \ --disable-grub-mount \
--disable-device-mapper \ --disable-device-mapper \
--disable-libzfs \ --disable-libzfs \
--prefix="${COOKBOOK_STAGE}/usr" --prefix="${COOKBOOK_STAGE}/usr" || exit 1
echo "Building GRUB..." echo "Building GRUB..."
make -j "${COOKBOOK_MAKE_JOBS}" make -j "${COOKBOOK_MAKE_JOBS}" || exit 1
# Create output directory # Create output directory
mkdir -p "${COOKBOOK_STAGE}/usr/lib/boot" mkdir -p "${COOKBOOK_STAGE}/usr/lib/boot"
@@ -101,7 +109,7 @@ echo "Creating standalone GRUB EFI image..."
ls \ ls \
cat \ cat \
halt \ halt \
reboot reboot || exit 1
# Verify output # Verify output
if [ ! -f "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" ]; then if [ ! -f "${COOKBOOK_STAGE}/usr/lib/boot/grub.efi" ]; then