121 lines
3.1 KiB
Bash
Executable file
121 lines
3.1 KiB
Bash
Executable file
#!/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 <<EOF
|
|
set timeout=5
|
|
set default=0
|
|
|
|
menuentry "Particle-OS Phase 2" {
|
|
search --set=root --file /vmlinuz-6.12.38+deb13-amd64
|
|
linux /vmlinuz-6.12.38+deb13-amd64 root=/dev/sda2 rw console=ttyS0
|
|
initrd /initrd.img-6.12.38+deb13-amd64
|
|
}
|
|
EOF
|
|
|
|
# Cleanup mounts
|
|
echo "Cleaning up mounts..."
|
|
sudo umount "$MOUNT_BOOT" "$MOUNT_ROOTFS"
|
|
sudo losetup -d "$LOOP_DEV"
|
|
|
|
echo ""
|
|
echo "🎉 Boot test setup complete!"
|
|
echo "Image created at: $IMAGE_PATH"
|
|
echo ""
|
|
echo "To test booting, run:"
|
|
echo "qemu-system-x86_64 -m 2048 -smp 2 -drive file=$IMAGE_PATH,format=raw,if=virtio -enable-kvm -serial stdio -nographic"
|
|
echo ""
|
|
echo "Or use virt-manager on your other PC to test this image."
|