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 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-02-13 21:05:11 -05:00
parent d482cf4d0c
commit d3a8e63b36
2 changed files with 18 additions and 3 deletions

View File

@@ -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

View File

@@ -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 ))