From d3a8e63b366195f204ce31521afa5cb0d5046059 Mon Sep 17 00:00:00 2001 From: cproudlock Date: Fri, 13 Feb 2026 21:05:11 -0500 Subject: [PATCH] Fully unattended USB install: patch GRUB and remove cloud-init - build-usb.sh now patches the ISO's grub.cfg with xorriso to add 'autoinstall' kernel param (skips confirmation prompt) and reduces GRUB timeout from 30s to 5s - Disable and remove cloud-init on the installed system to prevent boot delays on air-gapped network - Fix ISO size calculation to use patched ISO for CIDATA partition offset Co-Authored-By: Claude Opus 4.6 --- autoinstall/user-data | 3 ++- build-usb.sh | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/autoinstall/user-data b/autoinstall/user-data index 1f68515..75137d6 100644 --- a/autoinstall/user-data +++ b/autoinstall/user-data @@ -1,7 +1,6 @@ #cloud-config autoinstall: version: 1 - interactive-sections: [] # Locale, keyboard, timezone locale: en_US.UTF-8 @@ -105,6 +104,8 @@ autoinstall: # Disable cloud-init on the installed system (no longer needed after autoinstall) - curtin in-target --target=/target -- touch /etc/cloud/cloud-init.disabled + - curtin in-target --target=/target -- dpkg --configure -a + - curtin in-target --target=/target -- apt-get remove -y cloud-init cloud-guest-utils user-data: disable_root: false diff --git a/build-usb.sh b/build-usb.sh index 6e4a4af..08c12bd 100755 --- a/build-usb.sh +++ b/build-usb.sh @@ -105,14 +105,28 @@ done # --- Write ISO to USB --- echo "[2/6] Writing Ubuntu ISO to $USB_DEV (this may take several minutes)..." -dd if="$ISO_PATH" of="$USB_DEV" bs=4M status=progress oflag=sync + +# Patch ISO to add 'autoinstall' kernel parameter (skips confirmation prompt) +PATCHED_ISO=$(mktemp /tmp/ubuntu-autoinstall-XXXXXX.iso) +cp "$ISO_PATH" "$PATCHED_ISO" +PATCHED_GRUB=$(mktemp /tmp/grub-XXXXXX.cfg) +xorriso -osirrox on -indev "$ISO_PATH" -extract /boot/grub/grub.cfg "$PATCHED_GRUB" 2>/dev/null +sed -i 's|linux\t/casper/vmlinuz ---|linux\t/casper/vmlinuz autoinstall ---|' "$PATCHED_GRUB" +sed -i 's/^set timeout=30/set timeout=5/' "$PATCHED_GRUB" +xorriso -indev "$PATCHED_ISO" -outdev "$PATCHED_ISO" \ + -map "$PATCHED_GRUB" /boot/grub/grub.cfg \ + -boot_image any replay 2>/dev/null +echo " Patched GRUB: added 'autoinstall' kernel param, reduced timeout to 5s" + +ISO_SIZE=$(stat -c%s "$PATCHED_ISO") +dd if="$PATCHED_ISO" of="$USB_DEV" bs=4M status=progress oflag=sync sync +rm -f "$PATCHED_ISO" "$PATCHED_GRUB" # --- Find the end of the ISO to create CIDATA partition --- echo "[3/6] Creating CIDATA partition after ISO data..." # Get ISO size in bytes and calculate the start sector for the new partition -ISO_SIZE=$(stat -c%s "$ISO_PATH") SECTOR_SIZE=512 # Start the CIDATA partition 1MB after the ISO ends (alignment) START_SECTOR=$(( (ISO_SIZE / SECTOR_SIZE) + 2048 ))