]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
master: Create a minimal GRUB EFI image
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 May 2021 15:46:23 +0000 (15:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 27 May 2021 15:46:23 +0000 (15:46 +0000)
This is making the boot process more similar to what we are using in
IPFire 2 by jumping back to the "regular" bootloader when in EFI mode.

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

index 86dcb0438cd679a023811b8ec5362a22e250695c..b7df38125642a19289bb7685d33e8674c9f44366 100644 (file)
@@ -55,6 +55,16 @@ GRUB_INSTALL_MODULES=(
        ls
 )
 
+GRUB_EFI_MODULES=(
+       "disk"
+       "iso9660"
+       "search"
+)
+
+make_label() {
+       echo "BL_$(date -u "+%Y%m%d%H%M")"
+}
+
 allocate_file() {
        local path="${1}"
        local size="${2}"
@@ -149,8 +159,16 @@ make_grub_bios_image() {
        return 0
 }
 
+make_grub_efi_config() {
+       local label="${1}"
+
+       echo "search.fs_label \"${label}\" root"
+       echo "set prefix=(\$root)/EFI/BOOT"
+}
+
 make_grub_efi_image() {
        local path="${1}"
+       local label="${2}"
 
        local grub_efi_arch="${arch}"
 
@@ -164,7 +182,7 @@ make_grub_efi_image() {
        esac
 
        # Allocate file
-       if ! allocate_file "${path}" 2880; then
+       if ! allocate_file "${path}" 1440; then
                return 1
        fi
 
@@ -175,6 +193,7 @@ make_grub_efi_image() {
        fi
 
        local tempdir="$(mktemp -d)"
+       local config="$(mktemp)"
 
        # Mount the disk
        if ! mount -o loop "${path}" "${tempdir}"; then
@@ -184,23 +203,30 @@ make_grub_efi_image() {
 
        mkdir -p "${tempdir}/EFI/BOOT"
 
+       # Write early GRUB configuration
+       make_grub_efi_config "${label}" > "${config}"
+
        # Generate a GRUB image
-       if ! in_buildsystem --bind="${tempdir}" \
-                       grub-mkstandalone \
+       if ! in_buildsystem --bind="${tempdir}" --bind="${config}" \
+                       grub-mkimage \
                                --format="${arch}-efi" \
+                               --prefix="/EFI/BOOT" \
                                --output="${tempdir}/EFI/BOOT/boot${grub_efi_arch}.efi" \
-                               --fonts="" --locales="" --themes=""; then
+                               --config="${config}" \
+                               "${GRUB_EFI_MODULES[@]}"; then
                echo "Could not generate GRUB EFI image" >&2
                umount "${tempdir}"
-               rm -rf "${tempdir}"
+               rm -rf "${tempdir}" "${config}"
                return 1
        fi
 
        if ! umount "${tempdir}"; then
-               rm -rf "${tempdir}"
+               rm -rf "${tempdir}" "${config}"
                return 1
        fi
 
+       rm -rf "${tempdir}" "${config}"
+
        return 0
 }
 
@@ -361,7 +387,7 @@ mkimage() {
 
        # Generate GRUB EFI image
        if [ "${has_efi_boot}" = "true" ]; then
-               if ! make_grub_efi_image "${tempdir}/boot/efiboot.img"; then
+               if ! make_grub_efi_image "${tempdir}/boot/efiboot.img" "${label}"; then
                        rm -rf "${tempdir}"
                        return 1
                fi