]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
master: Create GRUB EFI image on ISO9660 filesystem, too
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 May 2021 10:23:58 +0000 (10:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 May 2021 10:23:58 +0000 (10:23 +0000)
Previously, the GRUB EFI image was only installed on the FAT file system
and not on the ISO9660 one.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/bricklayer-master

index cbe48529e247927757bbd8010c9e0cb8b2791de3..293feab33154047fa4131249f2c4f0fabe0d5e82 100644 (file)
@@ -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