#!/bin/bash set -euo pipefail echo "🚀 Particle-OS Simple Boot Test" echo "================================" # Check prerequisites echo "Checking prerequisites..." for tool in podman qemu-system-x86_64; do if ! command -v "$tool" >/dev/null 2>&1; then echo "❌ Missing: $tool" exit 1 fi done # Check system tools for tool in parted grub-install partprobe; do if [ ! -x "/usr/sbin/$tool" ]; then echo "❌ Missing: /usr/sbin/$tool" exit 1 fi done echo "✅ Prerequisites satisfied" # Check Phase 2 image if ! podman image exists particle-os:phase2; then echo "❌ Phase 2 image not found. Run 'just build-phase2' first." exit 1 fi echo "✅ Phase 2 image found" # Create test directory TEST_DIR="test" mkdir -p "$TEST_DIR" # Create disk image echo "Creating 2GB disk image..." IMAGE_PATH="$TEST_DIR/particle-os-test.img" truncate -s 2G "$IMAGE_PATH" # Partition the disk echo "Partitioning disk..." echo "yes" | /usr/sbin/parted "$IMAGE_PATH" mklabel gpt /usr/sbin/parted "$IMAGE_PATH" mkpart primary fat32 1MiB 512MiB /usr/sbin/parted "$IMAGE_PATH" mkpart primary ext4 512MiB 100% /usr/sbin/parted "$IMAGE_PATH" set 1 boot on /usr/sbin/parted "$IMAGE_PATH" set 1 esp on # Create loop device echo "Setting up loop device..." LOOP_DEV=$(sudo losetup --find --show "$IMAGE_PATH") echo "Using loop device: $LOOP_DEV" # Wait for partitions sleep 2 sudo partprobe "$LOOP_DEV" sleep 1 # Verify partitions if [ ! -b "${LOOP_DEV}p1" ] || [ ! -b "${LOOP_DEV}p2" ]; then echo "❌ Partition devices not found" sudo losetup -d "$LOOP_DEV" exit 1 fi echo "✅ Partitions created" # Create filesystems echo "Creating filesystems..." sudo mkfs.fat -F32 "${LOOP_DEV}p1" sudo mkfs.ext4 "${LOOP_DEV}p2" # Mount partitions MOUNT_ROOT="$TEST_DIR/mount" MOUNT_BOOT="$MOUNT_ROOT/boot" MOUNT_ROOTFS="$MOUNT_ROOT/rootfs" mkdir -p "$MOUNT_BOOT" "$MOUNT_ROOTFS" sudo mount "${LOOP_DEV}p1" "$MOUNT_BOOT" sudo mount "${LOOP_DEV}p2" "$MOUNT_ROOTFS" # Extract Phase 2 container echo "Extracting Phase 2 container..." podman create --name temp-phase2 particle-os:phase2 podman export temp-phase2 | sudo tar -x -C "$MOUNT_ROOTFS" podman rm temp-phase2 # Set up bootloader echo "Setting up bootloader..." sudo /usr/sbin/grub-install --target=x86_64-efi --efi-directory="$MOUNT_BOOT" --boot-directory="$MOUNT_BOOT" --removable "$LOOP_DEV" # Create GRUB config echo "Creating GRUB configuration..." sudo tee "$MOUNT_BOOT/grub/grub.cfg" > /dev/null <