From dfa5b2f4149f4d4b57ceb80774ad0f7803a504cc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 29 Dec 2025 19:39:56 +0000 Subject: [PATCH] Fix Docker image build by avoiding loop devices and installing udev Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- scripts/docker-image-create-uefi-old.sh | 156 ++++++++++++++++++++++++ scripts/docker-image-create-uefi.sh | 141 +++++++++++---------- scripts/docker-image-install-tools.sh | 3 +- 3 files changed, 232 insertions(+), 68 deletions(-) create mode 100755 scripts/docker-image-create-uefi-old.sh diff --git a/scripts/docker-image-create-uefi-old.sh b/scripts/docker-image-create-uefi-old.sh new file mode 100755 index 0000000..0058a4b --- /dev/null +++ b/scripts/docker-image-create-uefi-old.sh @@ -0,0 +1,156 @@ +#!/bin/bash +# Create UEFI-bootable SparkOS image with GPT partition table + +set -e + +mkdir -p /output /staging/esp /staging/root + +echo "=== Creating UEFI-bootable SparkOS image with GRUB ===" + +# Create 1GB disk image (larger for kernel + bootloader) +dd if=/dev/zero of=/output/sparkos.img bs=1M count=1024 + +# Create GPT partition table +echo "Creating GPT partition table..." +parted -s /output/sparkos.img mklabel gpt + +# Create EFI System Partition (ESP) - 200MB, FAT32 +echo "Creating EFI System Partition..." +parted -s /output/sparkos.img mkpart ESP fat32 1MiB 201MiB +parted -s /output/sparkos.img set 1 esp on + +# Create root partition - remaining space, ext4 +echo "Creating root partition..." +parted -s /output/sparkos.img mkpart primary ext4 201MiB 100% + +# Use libguestfs to format and populate partitions without loop devices +echo "Formatting partitions using guestfish..." +guestfish -a /output/sparkos.img <<'EOF' +run +mkfs vfat /dev/sda1 label:SPARKOSEFI +mkfs ext4 /dev/sda2 label:SparkOS +mount /dev/sda2 / +mkdir-p /boot +EOF + +# Prepare ESP contents +echo "Preparing ESP contents..." + +# Prepare ESP contents +echo "Preparing ESP contents..." +mkdir -p /staging/esp/EFI/BOOT +mkdir -p /staging/esp/boot/grub + +# Create GRUB EFI binary using grub-mkstandalone +grub-mkstandalone \ + --format=x86_64-efi \ + --output=/staging/esp/EFI/BOOT/BOOTX64.EFI \ + --locales="" \ + --fonts="" \ + "boot/grub/grub.cfg=/dev/null" + +# Find the kernel +KERNEL_PATH=$(find /kernel/boot -name "vmlinuz-*" | head -1) +KERNEL_VERSION=$(basename $KERNEL_PATH | sed 's/vmlinuz-//') +INITRD_PATH=$(find /kernel/boot -name "initrd.img-*" | head -1) + +# Copy kernel and initrd to staging +echo "Copying kernel to staging..." +cp $KERNEL_PATH /staging/esp/boot/vmlinuz +if [ -f "$INITRD_PATH" ]; then cp $INITRD_PATH /staging/esp/boot/initrd.img; fi + +# Create GRUB configuration +printf '%s\n' \ + 'set timeout=3' \ + 'set default=0' \ + '' \ + 'menuentry "SparkOS" {' \ + ' linux /boot/vmlinuz root=LABEL=SparkOS rw init=/sbin/init console=tty1 quiet' \ + '}' \ + > /staging/esp/boot/grub/grub.cfg + +# Prepare root filesystem contents +echo "Preparing root filesystem..." +mkdir -p /staging/root/{bin,sbin,etc,proc,sys,dev,tmp,usr/{bin,sbin,lib,lib64},var/{log,run},root,home/spark,boot} + +# Install SparkOS init +cp /build/init /staging/root/sbin/init +chmod 755 /staging/root/sbin/init + +# Install busybox +echo "Installing busybox..." +cp /bin/busybox /staging/root/bin/busybox +chmod 755 /staging/root/bin/busybox + +# Create busybox symlinks for essential commands +for cmd in sh ls cat echo mount umount mkdir rm cp mv chmod chown ln ps kill; do + ln -sf busybox /staging/root/bin/$cmd +done + +# Create system configuration files +echo "sparkos" > /staging/root/etc/hostname +echo "127.0.0.1 localhost" > /staging/root/etc/hosts +echo "127.0.1.1 sparkos" >> /staging/root/etc/hosts +echo "root:x:0:0:root:/root:/bin/sh" > /staging/root/etc/passwd +echo "spark:x:1000:1000:SparkOS User:/home/spark:/bin/sh" >> /staging/root/etc/passwd +echo "root:x:0:" > /staging/root/etc/group +echo "spark:x:1000:" >> /staging/root/etc/group + +# Copy README to root partition +cp /build/config/image-readme.txt /staging/root/README.txt + +# Copy ESP contents to the image +echo "Populating EFI System Partition..." +guestfish -a /output/sparkos.img <<'EOF' +run +mount /dev/sda1 / +mkdir-p /EFI +mkdir-p /EFI/BOOT +mkdir-p /boot +mkdir-p /boot/grub +EOF + +# Copy files using guestfish +echo "Copying bootloader files..." +guestfish -a /output/sparkos.img -m /dev/sda1 < /mnt/esp/boot/grub/grub.cfg + > /staging/esp/boot/grub/grub.cfg -# Set up root filesystem -echo "Setting up root filesystem..." -mkdir -p /mnt/root/{bin,sbin,etc,proc,sys,dev,tmp,usr/{bin,sbin,lib,lib64},var/{log,run},root,home/spark,boot} +# Prepare root filesystem contents +echo "Preparing root filesystem..." +mkdir -p /staging/root/{bin,sbin,etc,proc,sys,dev,tmp,usr/{bin,sbin,lib,lib64},var/{log,run},root,home/spark,boot} # Install SparkOS init -cp /build/init /mnt/root/sbin/init -chmod 755 /mnt/root/sbin/init +cp /build/init /staging/root/sbin/init +chmod 755 /staging/root/sbin/init # Install busybox echo "Installing busybox..." -cp /bin/busybox /mnt/root/bin/busybox -chmod 755 /mnt/root/bin/busybox +cp /bin/busybox /staging/root/bin/busybox +chmod 755 /staging/root/bin/busybox # Create busybox symlinks for essential commands for cmd in sh ls cat echo mount umount mkdir rm cp mv chmod chown ln ps kill; do - ln -sf busybox /mnt/root/bin/$cmd + ln -sf busybox /staging/root/bin/$cmd done # Create system configuration files -echo "sparkos" > /mnt/root/etc/hostname -echo "127.0.0.1 localhost" > /mnt/root/etc/hosts -echo "127.0.1.1 sparkos" >> /mnt/root/etc/hosts -echo "root:x:0:0:root:/root:/bin/sh" > /mnt/root/etc/passwd -echo "spark:x:1000:1000:SparkOS User:/home/spark:/bin/sh" >> /mnt/root/etc/passwd -echo "root:x:0:" > /mnt/root/etc/group -echo "spark:x:1000:" >> /mnt/root/etc/group +echo "sparkos" > /staging/root/etc/hostname +echo "127.0.0.1 localhost" > /staging/root/etc/hosts +echo "127.0.1.1 sparkos" >> /staging/root/etc/hosts +echo "root:x:0:0:root:/root:/bin/sh" > /staging/root/etc/passwd +echo "spark:x:1000:1000:SparkOS User:/home/spark:/bin/sh" >> /staging/root/etc/passwd +echo "root:x:0:" > /staging/root/etc/group +echo "spark:x:1000:" >> /staging/root/etc/group # Copy README to root partition -cp /build/config/image-readme.txt /mnt/root/README.txt +cp /build/config/image-readme.txt /staging/root/README.txt -# Sync and unmount +# Create 1GB disk image +echo "Creating disk image..." +dd if=/dev/zero of=/output/sparkos.img bs=1M count=1024 + +# Create GPT partition table using sgdisk +echo "Creating GPT partition table..." +sgdisk -Z /output/sparkos.img 2>/dev/null || true +sgdisk -n 1:2048:411647 -t 1:ef00 -c 1:"EFI System" /output/sparkos.img +sgdisk -n 2:411648:0 -t 2:8300 -c 2:"Linux filesystem" /output/sparkos.img + +# Extract partition regions using dd +echo "Extracting partition regions..." +dd if=/output/sparkos.img of=/tmp/esp.img bs=512 skip=2048 count=409600 2>/dev/null +dd if=/output/sparkos.img of=/tmp/root.img bs=512 skip=411648 2>/dev/null + +# Format ESP partition (FAT32) +echo "Formatting EFI System Partition (FAT32)..." +mkfs.vfat -F 32 -n "SPARKOSEFI" /tmp/esp.img >/dev/null + +# Populate ESP using mtools (no mount needed!) +echo "Populating ESP with bootloader and kernel..." +export MTOOLS_SKIP_CHECK=1 +mmd -i /tmp/esp.img ::/EFI +mmd -i /tmp/esp.img ::/EFI/BOOT +mmd -i /tmp/esp.img ::/boot +mmd -i /tmp/esp.img ::/boot/grub +mcopy -i /tmp/esp.img /staging/esp/EFI/BOOT/BOOTX64.EFI ::/EFI/BOOT/ +mcopy -i /tmp/esp.img /staging/esp/boot/vmlinuz ::/boot/ +if [ -f "/staging/esp/boot/initrd.img" ]; then + mcopy -i /tmp/esp.img /staging/esp/boot/initrd.img ::/boot/ +fi +mcopy -i /tmp/esp.img /staging/esp/boot/grub/grub.cfg ::/boot/grub/ + +# Format root partition (ext4) with directory contents (no mount needed!) +echo "Formatting root partition (ext4) and populating..." +mke2fs -t ext4 -L "SparkOS" -d /staging/root /tmp/root.img >/dev/null 2>&1 + +# Write partitions back to image +echo "Writing partitions to image..." +dd if=/tmp/esp.img of=/output/sparkos.img bs=512 seek=2048 count=409600 conv=notrunc 2>/dev/null +dd if=/tmp/root.img of=/output/sparkos.img bs=512 seek=411648 conv=notrunc 2>/dev/null + +# Clean up temporary files +rm -f /tmp/esp.img /tmp/root.img + +# Finalize echo "Finalizing image..." sync -umount /mnt/esp -umount /mnt/root -losetup -d $LOOP_DEV # Compress the image echo "Compressing image..." diff --git a/scripts/docker-image-install-tools.sh b/scripts/docker-image-install-tools.sh index f58c18a..d73b93a 100755 --- a/scripts/docker-image-install-tools.sh +++ b/scripts/docker-image-install-tools.sh @@ -16,5 +16,6 @@ apt-get install -y \ grub-common \ wget \ busybox-static \ - kmod + kmod \ + udev rm -rf /var/lib/apt/lists/*