From 477b2eceeff6f350640c0427b8d4b84870c6f2c8 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 28 May 2021 10:23:58 +0000 Subject: [PATCH] master: Create GRUB EFI image on ISO9660 filesystem, too Previously, the GRUB EFI image was only installed on the FAT file system and not on the ISO9660 one. Signed-off-by: Michael Tremer --- src/bricklayer-master | 84 +++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/src/bricklayer-master b/src/bricklayer-master index cbe4852..293feab 100644 --- a/src/bricklayer-master +++ b/src/bricklayer-master @@ -162,64 +162,68 @@ make_grub_efi_config() { make_grub_efi_image() { local path="${1}" - local label="${2}" + local efiboot="${2}" + local label="${3}" - local grub_efi_arch="${arch}" + local config="$(mktemp)" - case "${arch}" in - aarch64) - grub_efi_arch="a64" - ;; - x86_64) - grub_efi_arch="x64" - ;; - esac + # Write early GRUB configuration + make_grub_efi_config "${label}" > "${config}" + + # Generate a GRUB image + if ! in_buildsystem --bind="${tempdir}" --bind="${config}" \ + grub-mkimage \ + --format="${arch}-efi" \ + --prefix="/EFI/BOOT" \ + --output="${path}" \ + --config="${config}" \ + "${GRUB_MODULES[@]}"; then + echo "Could not generate GRUB EFI image" >&2 + rm -f "${config}" + return 1 + fi + + # Remove configuration + rm -f "${config}" # Allocate file - if ! allocate_file "${path}" 1440; then + if ! allocate_file "${efiboot}" 1440; then return 1 fi # Format it with FAT - if ! mkdosfs -F 12 -n "BRICKLAYER_EFI" "${path}"; then + if ! mkdosfs -F 12 -n "BRICKLAYER_EFI" "${efiboot}"; then echo "Could not format the EFI filesystem" >&2 + rm -f "${efiboot}" return 1 fi local tempdir="$(mktemp -d)" - local config="$(mktemp)" # Mount the disk - if ! mount -o loop "${path}" "${tempdir}"; then + if ! mount -o loop "${efiboot}" "${tempdir}"; then echo "Could not mount EFI filesystem" >&2 + rm -rf "${efiboot}" "${tempdir}" return 1 fi mkdir -p "${tempdir}/EFI/BOOT" - # Write early GRUB configuration - make_grub_efi_config "${label}" > "${config}" - - # Generate a GRUB image - if ! in_buildsystem --bind="${tempdir}" --bind="${config}" \ - grub-mkimage \ - --format="${arch}-efi" \ - --prefix="/EFI/BOOT" \ - --output="${tempdir}/EFI/BOOT/boot${grub_efi_arch}.efi" \ - --config="${config}" \ - "${GRUB_MODULES[@]}"; then - echo "Could not generate GRUB EFI image" >&2 - umount "${tempdir}" - rm -rf "${tempdir}" "${config}" + # Copy GRUB EFI image onto the FAT partition + if ! cp -- "${path}" "${tempdir}/EFI/BOOT/${path##*/}"; then + echo "Could not copy GRUB EFI image onto the FAT filesystem" >&2 + rm -rf "${efiboot}" "${tempdir}" return 1 fi + # Umount the filesystem if ! umount "${tempdir}"; then - rm -rf "${tempdir}" "${config}" + rm -rf "${efiboot}" "${tempdir}" return 1 fi - rm -rf "${tempdir}" "${config}" + # Cleanup + rm -rf "${tempdir}" return 0 } @@ -381,7 +385,25 @@ mkimage() { # Generate GRUB EFI image if [ "${has_efi_boot}" = "true" ]; then - if ! make_grub_efi_image "${tempdir}/boot/efiboot.img" "${label}"; then + local grub_efi_arch="${arch}" + + case "${arch}" in + aarch64) + grub_efi_arch="a64" + ;; + x86_64) + grub_efi_arch="x64" + ;; + esac + + # Create a directory for EFI stuff + mkdir -p "${tempdir}/EFI/BOOT" + + # Generate a GRUB EFI image + if ! make_grub_efi_image \ + "${tempdir}/EFI/BOOT/boot${grub_efi_arch}.efi" \ + "${tempdir}/boot/efiboot.img" \ + "${label}"; then rm -rf "${tempdir}" return 1 fi -- 2.47.3