]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
master: Install temporary system and call grub-mkstandalone in it
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 May 2021 12:47:45 +0000 (12:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 13 May 2021 12:47:45 +0000 (12:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/bricklayer-master

index 6736c02c167471a0bf0e41928d16c010644eebf7..e28a46bfbbbf721b4f47e233169eb8f6a397d70a 100644 (file)
@@ -28,6 +28,12 @@ PACKAGES=(
        "kernel"
 )
 
+BUILDSYSTEM_PACKAGES=(
+       "@Base"
+       "dracut"
+       "grub"
+)
+
 # Compress as best as we can
 ZSTD_COMPRESSION_LEVEL=22
 
@@ -48,6 +54,30 @@ allocate_file() {
        dd if=/dev/zero of="${path}" bs=1k count="${size}"
 }
 
+make_buildsystem() {
+       local path="${1}"
+
+       local packages=(
+               "${BUILDSYSTEM_PACKAGES[@]}"
+       )
+
+       # Install packages
+       if ! pakfire --config="${PAKFIRE_CONFIG}" --root="${path}" \
+                       install --without-recommends "${packages[@]}"; then
+               echo "Could not install build system" >&2
+               return 1
+       fi
+}
+
+in_buildsystem() {
+       if [ -z "${buildsystem}" ]; then
+               echo "Build system isn't set up" >&2
+               return 1
+       fi
+
+       pakfire --config="${PAKFIRE_CONFIG}" --root="${buildsystem}" execute "$@"
+}
+
 make_live_system_image() {
        local filename="${1}"
 
@@ -83,27 +113,30 @@ make_boot_catalog() {
 make_grub_bios_image() {
        local path="${1}"
 
-       local core_img="$(mktemp)"
+       local tempdir="$(mktemp -d)"
 
        # Create a standalone image
-       if ! grub-mkstandalone \
-                       --format="${grub_arch}-pc" \
-                       --output="${core_img}" \
-                       --modules="${GRUB_MODULES[@]}" \
-                       --install-modules="${GRUB_MODULES[@]}" \
-                       --fonts="" --locales=""; then
-               unlink "${core_img}"
+       if ! in_buildsystem --bind="${tempdir}" \
+                       grub-mkstandalone \
+                               --verbose \
+                               --format="${grub_arch}-pc" \
+                               --output="${tempdir}/core.img" \
+                               --modules="${GRUB_MODULES[@]}" \
+                               --install-modules="${GRUB_MODULES[@]}" \
+                               --fonts="" --locales="" --themes=""; then
+               rm -rf "${tempdir}"
                return 1
        fi
 
        # Append cdboot.img with the generated core.img
-       if ! cat "/usr/lib/grub/${grub_arch}-pc/cdboot.img" "${core_img}" > "${path}"; then
-               unlink "${core_img}" "${path}"
+       if ! cat "${buildsystem}/usr/lib/grub/${grub_arch}-pc/cdboot.img" "${tempdir}/core.img" \
+                       > "${path}"; then
+               unlink "${tempdir}" "${path}"
                return 1
        fi
 
        # Cleanup
-       unlink "${core_img}"
+       rm -rf "${tempdir}"
 
        return 0
 }
@@ -111,6 +144,17 @@ make_grub_bios_image() {
 make_grub_efi_image() {
        local path="${1}"
 
+       local grub_efi_arch="${arch}"
+
+       case "${arch}" in
+               aarch64)
+                       grub_efi_arch="a64"
+                       ;;
+               x86_64)
+                       grub_efi_arch="x64"
+                       ;;
+       esac
+
        # Allocate file
        if ! allocate_file "${path}" 2880; then
                return 1
@@ -133,10 +177,11 @@ make_grub_efi_image() {
        mkdir -p "${tempdir}/EFI/BOOT"
 
        # Generate a GRUB image
-       if ! grub-mkstandalone \
-                       --format="${grub_arch}-efi" \
-                       --output="${tempdir}/EFI/BOOT/bootx64.efi" \
-                       --fonts="" --locales=""; then
+       if ! in_buildsystem --bind="${tempdir}" \
+                       grub-mkstandalone \
+                               --format="${arch}-efi" \
+                               --output="${tempdir}/EFI/BOOT/boot${grub_efi_arch}.efi" \
+                               --fonts="" --locales="" --themes=""; then
                echo "Could not generate GRUB EFI image" >&2
                umount "${tempdir}"
                rm -rf "${tempdir}"
@@ -304,7 +349,7 @@ main() {
 
                x86_64)
                        has_bios_boot="true"
-                       #has_efi_boot="true"
+                       has_efi_boot="true"
                        ;;
 
                # Throw an error on unhandled architectures
@@ -314,12 +359,22 @@ main() {
                        ;;
        esac
 
+       local buildsystem="$(mktemp -d)"
+
+       # Install a system with all tools we need
+       if ! make_buildsystem "${buildsystem}"; then
+               return 1
+       fi
+
        # Make image and delete it if something went wrong
-       if ! mkimage "${filename}"; then
-               rm -f "${filename}"
+       if ! mkimage "${buildsystem}" "${filename}"; then
+               rm -rf "${buildsystem}" "${filename}"
                return 1
        fi
 
+       # Remove temporary system
+       rm -rf "${buildsystem}"
+
        return 0
 }