archy/image-recipe/create-bootable-usb.sh
Dorian 8f0b080e73 Enhance boot configuration for custom ISO with USB delay and filesystem support
- Added isofs module to boot configurations for both UEFI (GRUB) and Legacy BIOS (Syslinux) to enable ISO9660 filesystem support.
- Updated boot parameters to improve USB delay and debugging capabilities for better hardware compatibility.
2026-01-31 23:37:56 +00:00

115 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# Create a proper bootable USB for Alpine/Archipelago
# This formats the USB and installs Alpine in a way that works on problematic hardware
set -e
USB_DEVICE="${1}"
ISO_FILE="${2:-/Users/dorian/Projects/archy/image-recipe/results/archipelago-3.19-hp-prodesk-uefi-x86_64.iso}"
if [ -z "$USB_DEVICE" ]; then
echo "Usage: $0 /dev/diskN [iso-file]"
echo ""
echo "Available disks:"
diskutil list | grep "external"
exit 1
fi
if [ ! -f "$ISO_FILE" ]; then
echo "❌ ISO file not found: $ISO_FILE"
exit 1
fi
echo "╔════════════════════════════════════════════════════════╗"
echo "║ Create Bootable USB for HP ProDesk ║"
echo "╚════════════════════════════════════════════════════════╝"
echo ""
echo "⚠️ WARNING: This will ERASE all data on $USB_DEVICE"
echo ""
echo "📀 ISO: $(basename $ISO_FILE)"
echo "💾 USB: $USB_DEVICE"
echo ""
echo "Press Ctrl+C to cancel, or Enter to continue..."
read
# Unmount
echo "🔓 Unmounting USB..."
diskutil unmountDisk "$USB_DEVICE" || true
# Create a single FAT32 partition with MBR
echo "🗂️ Creating FAT32 partition..."
sudo diskutil eraseDisk FAT32 ALPINE MBR "$USB_DEVICE"
# Wait for partition to settle
sleep 2
# Extract the ISO
echo "📦 Extracting ISO..."
ISO_MOUNT="/tmp/alpine-iso-$$"
mkdir -p "$ISO_MOUNT"
# Use 7z to extract the ISO
if command -v 7z >/dev/null 2>&1; then
7z x "$ISO_FILE" -o"$ISO_MOUNT" -y >/dev/null
else
echo "❌ 7z not found. Installing with brew..."
brew install p7zip
7z x "$ISO_FILE" -o"$ISO_MOUNT" -y >/dev/null
fi
# Find the USB mount point
USB_MOUNT=$(diskutil info "${USB_DEVICE}s1" | grep "Mount Point" | awk '{print $3}')
if [ -z "$USB_MOUNT" ]; then
echo "❌ Could not find USB mount point"
hdiutil detach "$ISO_MOUNT"
exit 1
fi
echo "💾 USB mounted at: $USB_MOUNT"
# Copy all files from ISO to USB
echo "📋 Copying Alpine files to USB..."
rsync -av --progress "$ISO_MOUNT/" "$USB_MOUNT/"
# Install syslinux bootloader
echo "🔧 Installing bootloader..."
# Rename isolinux to syslinux for USB boot
if [ -d "$USB_MOUNT/boot/syslinux" ]; then
if [ -f "$USB_MOUNT/boot/syslinux/isolinux.bin" ]; then
mv "$USB_MOUNT/boot/syslinux/isolinux.bin" "$USB_MOUNT/boot/syslinux/syslinux.bin" 2>/dev/null || true
fi
if [ -f "$USB_MOUNT/boot/syslinux/isolinux.cfg" ]; then
mv "$USB_MOUNT/boot/syslinux/isolinux.cfg" "$USB_MOUNT/boot/syslinux/syslinux.cfg" 2>/dev/null || true
fi
fi
# Update syslinux config to remove ISO-specific options
if [ -f "$USB_MOUNT/boot/syslinux/syslinux.cfg" ]; then
sed -i '' 's/isolinux/syslinux/g' "$USB_MOUNT/boot/syslinux/syslinux.cfg"
fi
# Sync and clean up
echo "🔄 Syncing..."
sync
rm -rf "$ISO_MOUNT"
diskutil unmount "$USB_MOUNT"
# Make the USB bootable by writing MBR
echo "🚀 Making USB bootable..."
if [ -f "/tmp/alpine-iso-$$/boot/syslinux/mbr.bin" ]; then
sudo dd if="/tmp/alpine-iso-$$/boot/syslinux/mbr.bin" of="$USB_DEVICE" bs=440 count=1 conv=notrunc 2>/dev/null || true
fi
echo ""
echo "✅ Bootable USB created successfully!"
echo ""
echo "📋 Next steps:"
echo " 1. Boot HP ProDesk from USB"
echo " 2. In BIOS: Legacy mode, Secure Boot OFF"
echo " 3. Should boot to Alpine login"
echo ""
echo "🎯 If this still fails, the HP ProDesk may need Alpine installed"
echo " to internal drive first (can't boot from USB at all)"
echo ""