110 lines
4.2 KiB
Bash
Executable File
110 lines
4.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
IN="input"
|
|
OUT="output"
|
|
ISO_ROOT="iso_root"
|
|
IMG="$OUT/efiboot.img"
|
|
ISO="$OUT/ipxe.iso"
|
|
|
|
rm -rf "$ISO_ROOT" "$IMG" "$ISO"
|
|
mkdir -p "$ISO_ROOT/EFI/BOOT" "$ISO_ROOT/IPXE" "$OUT"
|
|
|
|
# stub.efi for direct loading by BOOT*.EFI and future direct loading by firmware (and future shim flow)
|
|
cp "$OUT/stubx64.efi" "$ISO_ROOT/EFI/BOOT/stubx64.efi"
|
|
[ -f "$OUT/stubaa64.efi" ] && cp "$OUT/stubaa64.efi" "$ISO_ROOT/EFI/BOOT/"
|
|
[ -f "$OUT/stubia32.efi" ] && cp "$OUT/stubia32.efi" "$ISO_ROOT/EFI/BOOT/"
|
|
|
|
# Current flow: direct EFI boot
|
|
cp "$OUT/BOOTX64.EFI" "$ISO_ROOT/EFI/BOOT/BOOTX64.EFI"
|
|
[ -f "$OUT/BOOTAA64.EFI" ] && cp "$OUT/BOOTAA64.EFI" "$ISO_ROOT/EFI/BOOT/"
|
|
[ -f "$OUT/BOOTIA32.EFI" ] && cp "$OUT/BOOTIA32.EFI" "$ISO_ROOT/EFI/BOOT/"
|
|
|
|
# Future flow: shim → grub*.efi/BOOT*.EFI → stub*.efi
|
|
# cp "input/shim/shimx64.efi" "$ISO_ROOT/EFI/BOOT/BOOTX64.EFI"
|
|
# cp "$OUT/BOOTX64.EFI" "$ISO_ROOT/EFI/BOOT/grubx64.efi"
|
|
|
|
# MOK manager binaries for direct loading by shim and future direct loading by firmware (and future shim flow)
|
|
[ -f "$OUT/mmx64.efi" ] && cp "$OUT/mmx64.efi" "$ISO_ROOT/EFI/BOOT/"
|
|
[ -f "$OUT/mmaa64.efi" ] && cp "$OUT/mmaa64.efi" "$ISO_ROOT/EFI/BOOT/"
|
|
[ -f "$OUT/mmia32.efi" ] && cp "$OUT/mmia32.efi" "$ISO_ROOT/EFI/BOOT/"
|
|
|
|
# Signing cert for direct loading by shim and future direct loading by firmware (and future shim flow)
|
|
cp keys/signing.der "$ISO_ROOT/EFI/BOOT/cert.der"
|
|
|
|
# iPXE binaries for direct loading by firmware and future shim flow
|
|
[ -f "$IN/ipxe-snp.efi" ] && cp "$IN/ipxe-snp.efi" "$ISO_ROOT/IPXE/ipxe-snp.efi"
|
|
[ -f "$IN/ipxe.efi" ] && cp "$IN/ipxe.efi" "$ISO_ROOT/IPXE/ipxe.efi"
|
|
|
|
# If autoexec.ipxe file is present, copy it over to the ISO root
|
|
[ -f "$IN/autoexec.ipxe" ] && cp "$IN/autoexec.ipxe" "$ISO_ROOT/autoexec.ipxe"
|
|
|
|
# Build EFI boot image
|
|
dd if=/dev/zero of="$IMG" bs=1M count=8
|
|
mkfs.vfat -F 12 "$IMG"
|
|
|
|
mmd -i "$IMG" ::/EFI
|
|
mmd -i "$IMG" ::/EFI/BOOT
|
|
|
|
# Copy BOOT*.EFI to the EFI System Partition for direct loading by shim (and future direct loading by firmware)
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/BOOTX64.EFI" ::/EFI/BOOT/BOOTX64.EFI
|
|
|
|
# Copy stub*.efi to the EFI System Partition
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/stubx64.efi" ::/EFI/BOOT/stubx64.efi
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/stubaa64.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/stubaa64.efi" ::/EFI/BOOT/stubaa64.efi
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/stubia32.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/stubia32.efi" ::/EFI/BOOT/stubia32.efi
|
|
|
|
# Copy BOOT*.EFI, cert.der, and MOK manager binaries to the EFI System Partition for direct loading by firmware (and future shim flow)
|
|
[ -f "$ISO_ROOT/EFI/BOOT/BOOTAA64.EFI" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/BOOTAA64.EFI" ::/EFI/BOOT/BOOTAA64.EFI
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/BOOTIA32.EFI" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/BOOTIA32.EFI" ::/EFI/BOOT/BOOTIA32.EFI
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/cert.der" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/cert.der" ::/EFI/BOOT/cert.der
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/mmx64.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/mmx64.efi" ::/EFI/BOOT/mmx64.efi
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/mmaa64.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/mmaa64.efi" ::/EFI/BOOT/mmaa64.efi
|
|
|
|
[ -f "$ISO_ROOT/EFI/BOOT/mmia32.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/EFI/BOOT/mmia32.efi" ::/EFI/BOOT/mmia32.efi
|
|
|
|
# Copy iPXE binaries to the EFI System Partition for direct loading by firmware (and future shim flow)
|
|
mmd -i "$IMG" ::/IPXE
|
|
[ -f "$ISO_ROOT/IPXE/ipxe-snp.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/IPXE/ipxe-snp.efi" ::/IPXE/ipxe-snp.efi
|
|
|
|
[ -f "$ISO_ROOT/IPXE/ipxe.efi" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/IPXE/ipxe.efi" ::/IPXE/ipxe.efi
|
|
|
|
# If autoexec.ipxe file is present, copy it over to the EFI System Partition
|
|
[ -f "$ISO_ROOT/IPXE/autoexec.ipxe" ] && \
|
|
mcopy -i "$IMG" "$ISO_ROOT/autoexec.ipxe" ::/IPXE/autoexec.ipxe
|
|
|
|
# build EFI System Partition image for El Torito booting
|
|
cp "$IMG" "$ISO_ROOT/efiboot.img"
|
|
|
|
# Build ISO
|
|
xorriso -as mkisofs \
|
|
-iso-level 3 \
|
|
-full-iso9660-filenames \
|
|
-volid "IPXE_BOOT" \
|
|
-eltorito-platform efi \
|
|
-eltorito-boot efiboot.img \
|
|
-no-emul-boot \
|
|
-append_partition 2 0xef "$IMG" \
|
|
-appended_part_as_gpt \
|
|
-output "$ISO" \
|
|
"$ISO_ROOT"
|
|
|
|
xorriso -indev "$ISO" -report_el_torito plain
|
|
|
|
echo "Created $ISO" |