universalisos/kernel/make-uefi-iso.sh
Fábio Coutada 62e8454f91 build: add UEFI ISO builder, test boot scripts, EIM config
- make-uefi-iso.sh: UEFI ISO image builder
- test_boot.S, test_boot.ld: test boot assembly and linker script
- eim_config.toml: EIM (External Interface Module) configuration
- edk2-ovmf RPM for UEFI firmware
- GAP_ANALYSIS_PIKEOS_PARITY.md: PikeOS parity gap analysis
2026-07-15 15:33:07 +01:00

108 lines
3.1 KiB
Bash

#!/bin/bash
# UniversalisOS x86_64 — UEFI Bootable ISO Creator
#
# Creates a bootable ISO image with:
# - GRUB2 UEFI bootloader
# - Kernel ELF binary
# - UEFI application (optional)
#
# Prerequisites: grub-mkrescue, xorriso, mtools
#
# Usage: ./make-uefi-iso.sh [kernel.elf] [output.iso]
#
# SPDX-License-Identifier: MIT
set -e
KERNEL="${1:-/home/fabiorafaelcoutada/portugalfuturista/universalisos/kernel/build/uos-x86_64.elf}"
OUTPUT="${2:-/tmp/uos-uefi.iso}"
WORKDIR="/tmp/uos-iso-build"
GRUB_CFG="$(dirname "$0")/src/arch/x86_64/grub-uefi.cfg"
OVMF_PATH="$(dirname "$0")/src/arch/x86_64/ovmf/OVMF.fd"
echo "=== UniversalisOS UEFI ISO Builder ==="
echo "Kernel: $KERNEL"
echo "Output: $OUTPUT"
# Check prerequisites
if ! command -v grub-mkrescue &>/dev/null; then
echo "ERROR: grub-mkrescue not found. Install grub2-common or grub2-tools."
echo " sudo dnf install grub2-tools-extra xorriso mtools"
exit 1
fi
# Check if kernel exists
if [ ! -f "$KERNEL" ]; then
echo "ERROR: Kernel not found at $KERNEL"
echo "Build first: make ARCH=x86_64 PLATFORM=qemu-x86_64-virt"
exit 1
fi
# Clean work directory
rm -rf "$WORKDIR"
mkdir -p "$WORKDIR/boot/grub"
mkdir -p "$WORKDIR/EFI/UOS"
mkdir -p "$WORKDIR/EFI/BOOT"
# Copy kernel
cp "$KERNEL" "$WORKDIR/boot/uos-x86_64.elf"
cp "$KERNEL" "$WORKDIR/EFI/UOS/kernel.elf"
# Copy GRUB config
if [ -f "$GRUB_CFG" ]; then
cp "$GRUB_CFG" "$WORKDIR/boot/grub/grub.cfg"
else
echo "WARNING: grub-uefi.cfg not found, using default"
cat > "$WORKDIR/boot/grub/grub.cfg" << 'EOF'
set default=0
set timeout=5
menuentry "UniversalisOS" {
multiboot2 /boot/uos-x86_64.elf
boot
}
EOF
fi
# Create the ISO
echo "Creating ISO image..."
grub-mkrescue -o "$OUTPUT" "$WORKDIR" 2>/dev/null || {
echo "grub-mkrescue failed, trying alternative method..."
# Alternative: create a basic ISO with the kernel
# Use xorriso directly
xorriso -as mkisofs \
-R -J -joliet-long \
-b boot/grub/i386-pc/eltorito.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e EFI/BOOT/BOOTX64.EFI \
-no-emul-boot \
-isohybrid-gpt-basdat \
-o "$OUTPUT" \
"$WORKDIR" 2>/dev/null || {
echo "WARNING: ISO creation failed. Use QEMU directly with OVMF."
echo ""
echo "Alternative QEMU commands:"
echo " # Direct multiboot (no ISO needed):"
echo " qemu-system-x86_64 -kernel $KERNEL -m 4096 -enable-kvm -cpu host -serial stdio -display none"
echo ""
echo " # With UEFI firmware (OVMF):"
echo " qemu-system-x86_64 -bios $OVMF_PATH -kernel $KERNEL -m 4096 -serial stdio -nographic"
exit 0
}
}
echo "ISO created: $OUTPUT"
echo "Size: $(du -h "$OUTPUT" | cut -f1)"
echo ""
echo "Test with:"
echo " # UEFI boot:"
echo " qemu-system-x86_64 -bios $OVMF_PATH -cdrom $OUTPUT -m 4096 -serial stdio -nographic"
echo ""
echo " # Direct kernel boot:"
echo " qemu-system-x86_64 -kernel $KERNEL -m 4096 -enable-kvm -cpu host -serial stdio -display none"
# Clean up
rm -rf "$WORKDIR"