diff --git a/scripts/bootc-image-builder.sh b/scripts/bootc-image-builder.sh index aa10c8c..89f58fa 100755 --- a/scripts/bootc-image-builder.sh +++ b/scripts/bootc-image-builder.sh @@ -133,15 +133,12 @@ log_info "Container image: $CONTAINER_IMAGE" log_info "Output format: $OUTPUT_FORMAT" log_info "Output directory: $OUTPUT_DIR" -# Create temporary working directory -# Use /var/tmp or /home instead of /tmp to avoid tmpfs space limitations -WORK_DIR=$(mktemp -d /var/tmp/bootc-builder-XXXXXX 2>/dev/null || mktemp -d /home/joe/tmp/bootc-builder-XXXXXX 2>/dev/null || echo "/home/joe/tmp/bootc-builder-$$") -if [[ ! -d "$WORK_DIR" ]]; then - mkdir -p "$WORK_DIR" || { - log_error "Failed to create working directory" - exit 1 - } -fi +# Create working directory in project directory +WORK_DIR="$(pwd)/work/bootc-builder-$(date +%s)" +mkdir -p "$WORK_DIR" || { + log_error "Failed to create working directory" + exit 1 +} log_info "Working directory: $WORK_DIR" # Check available space @@ -176,7 +173,7 @@ cleanup_on_exit() { for loop_dev in /dev/loop*; do if [[ -b "$loop_dev" ]]; then local mount_point - mount_point=$(losetup -l "$loop_dev" 2>/dev/null | grep -o "/var/tmp/bootc-builder-[^[:space:]]*" || true) + mount_point=$(losetup -l "$loop_dev" 2>/dev/null | grep -o ".*/work/bootc-builder-[^[:space:]]*" || true) if [[ -n "$mount_point" ]]; then log_info "Detaching orphaned loop device $loop_dev..." sudo losetup -d "$loop_dev" 2>/dev/null || true @@ -215,7 +212,7 @@ cleanup_existing_loop_devices() { for loop_dev in /dev/loop*; do if [[ -b "$loop_dev" ]]; then local mount_point - mount_point=$(losetup -l "$loop_dev" 2>/dev/null | grep -o "/var/tmp/bootc-builder-[^[:space:]]*" || true) + mount_point=$(losetup -l "$loop_dev" 2>/dev/null | grep -o ".*/work/bootc-builder-[^[:space:]]*" || true) if [[ -n "$mount_point" ]]; then log_warn "Found existing loop device $loop_dev from previous run, cleaning up..." # Try to unmount if mounted @@ -277,7 +274,7 @@ fi # Create disk image using qemu-img (no sudo required) log_info "Creating disk image..." -IMAGE_SIZE="2G" # Default size, could be made configurable +IMAGE_SIZE="8G" # Increased size for enhanced simple-cli with Bazzite features # Create a proper disk image with partitions for bootloader installation log_info "Creating partitioned disk image for bootloader installation..." @@ -363,22 +360,40 @@ if [[ -x "$GRUB_INSTALL" ]]; then # Generate GRUB configuration manually since grub-mkconfig needs host environment log_info "Generating GRUB configuration manually..." + # Find the actual kernel and initrd files in the container + KERNEL_FILE=$(find "$MOUNT_POINT/boot" -name "vmlinuz-*" | head -1) + INITRD_FILE=$(find "$MOUNT_POINT/boot" -name "initrd.img-*" | head -1) + + if [[ -z "$KERNEL_FILE" ]] || [[ -z "$INITRD_FILE" ]]; then + log_error "Kernel or initrd not found in container" + log_error "Available files in /boot:" + ls -la "$MOUNT_POINT/boot/" || true + exit 1 + fi + + # Extract just the filename without the full path + KERNEL_NAME=$(basename "$KERNEL_FILE") + INITRD_NAME=$(basename "$INITRD_FILE") + + log_info "Found kernel: $KERNEL_NAME" + log_info "Found initrd: $INITRD_NAME" + # Create a basic GRUB configuration for the container - cat > "$MOUNT_POINT/boot/grub/grub.cfg" << 'EOF' + cat > "$MOUNT_POINT/boot/grub/grub.cfg" << EOF # GRUB configuration for simple-cli container -set timeout=5 +set timeout=1 set default=0 menuentry "Simple CLI" { set root=(hd0,msdos1) - linux /boot/vmlinuz-6.12.38+deb13-amd64 root=/dev/sda1 rw console=ttyS0 - initrd /boot/initrd.img-6.12.38+deb13-amd64 + linux /boot/$KERNEL_NAME root=/dev/sda1 rw console=ttyS0 quiet splash fastboot + initrd /boot/$INITRD_NAME } menuentry "Simple CLI (Recovery)" { set root=(hd0,msdos1) - linux /boot/vmlinuz-6.12.38+deb13-amd64 root=/dev/sda1 rw single console=ttyS0 - initrd /boot/initrd.img-6.12.38+deb13-amd64 + linux /boot/$KERNEL_NAME root=/dev/sda1 rw single console=ttyS0 + initrd /boot/$INITRD_NAME } EOF diff --git a/test-boot-performance.sh b/test-boot-performance.sh new file mode 100755 index 0000000..cb5a5a8 --- /dev/null +++ b/test-boot-performance.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# Test Boot Performance Script +# Tests the boot performance of our optimized simple-cli image + +set -euo pipefail + +IMAGE_PATH="/tmp/simple-cli-output/simple-cli_latest.qcow2" +OUTPUT_LOG="/tmp/boot-performance-test.log" + +echo "๐Ÿš€ Testing Boot Performance of Optimized Simple-CLI Image" +echo "========================================================" +echo "Image: $IMAGE_PATH" +echo "Output log: $OUTPUT_LOG" +echo "" + +# Check if image exists +if [ ! -f "$IMAGE_PATH" ]; then + echo "โŒ Error: Image not found at $IMAGE_PATH" + exit 1 +fi + +echo "โœ… Image found, starting boot performance test..." +echo "" + +# Function to clean up QEMU processes +cleanup() { + echo "๐Ÿงน Cleaning up QEMU processes..." + pkill -f "qemu-system-x86_64.*simple-cli" 2>/dev/null || true + sleep 2 +} + +# Set up cleanup on exit +trap cleanup EXIT + +echo "โฑ๏ธ Starting QEMU with optimized image..." +echo "๐Ÿ“ Boot output will be logged to: $OUTPUT_LOG" +echo "" + +# Start QEMU and capture output +echo "Starting boot test at $(date)" > "$OUTPUT_LOG" +echo "=========================================" >> "$OUTPUT_LOG" + +# Run QEMU with timeout and capture output +timeout 60 qemu-system-x86_64 \ + -m 2G \ + -smp 2 \ + -drive file="$IMAGE_PATH",format=qcow2 \ + -nographic \ + -serial mon:stdio \ + -display none \ + 2>&1 | tee -a "$OUTPUT_LOG" & + +QEMU_PID=$! +echo "QEMU started with PID: $QEMU_PID" + +# Wait for QEMU to start booting +sleep 5 + +# Monitor the boot process +echo "๐Ÿ” Monitoring boot process..." +BOOT_START=$(date +%s) +BOOT_COMPLETE=false + +while [ $(( $(date +%s) - BOOT_START )) -lt 60 ]; do + if ! kill -0 $QEMU_PID 2>/dev/null; then + echo "โœ… QEMU process completed" + BOOT_COMPLETE=true + break + fi + + # Check if we've reached a login prompt or similar + if grep -q "login\|Login\|simple@" "$OUTPUT_LOG" 2>/dev/null; then + echo "โœ… Boot completed - login prompt detected" + BOOT_COMPLETE=true + break + fi + + sleep 1 +done + +# Calculate boot time +BOOT_END=$(date +%s) +BOOT_TIME=$((BOOT_END - BOOT_START)) + +echo "" +echo "๐Ÿ“Š Boot Performance Results" +echo "==========================" +echo "Boot time: ${BOOT_TIME} seconds" +echo "Status: $([ "$BOOT_COMPLETE" = true ] && echo "โœ… SUCCESS" || echo "โŒ TIMEOUT")" +echo "" + +# Show boot log summary +echo "๐Ÿ“‹ Boot Log Summary" +echo "===================" +if [ -f "$OUTPUT_LOG" ]; then + echo "Last 20 lines of boot output:" + tail -20 "$OUTPUT_LOG" | sed 's/^/ /' +else + echo "No boot log found" +fi + +echo "" +echo "๐ŸŽฏ Boot Performance Analysis Complete!" +echo "Check $OUTPUT_LOG for full boot details"