ISO builder: native Ubuntu version, no Docker needed

This commit is contained in:
Jino Jose 2026-06-23 16:13:11 +05:30
parent 5d9cec4fe8
commit 8a350b4d86

View File

@ -1,70 +1,44 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ───────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────
# Cezen AI Suite — Custom ISO Builder # Cezen AI Suite — Custom ISO Builder
# Runs on macOS using Docker. Produces a bootable USB image. # Runs directly on Ubuntu 22.04 (run on the server)
# #
# Usage: bash autoinstall/build-iso.sh # Usage:
# Output: autoinstall/cezen-ai-ubuntu2204.iso # cd ~/aipackage
# bash autoinstall/build-iso.sh
# #
# Requirements: # Output: ~/aipackage/autoinstall/cezen-ai-ubuntu2204.iso
# - Docker Desktop running on your MacBook # Then copy the ISO to a USB stick or burn it.
# - ~6 GB free disk space (ISO download + work)
# ───────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────
set -e set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" WORK_DIR="/tmp/cezen-iso-work"
ORIGINAL_ISO="/tmp/ubuntu-22.04.5-live-server-amd64.iso"
OUTPUT_ISO="$SCRIPT_DIR/cezen-ai-ubuntu2204.iso" OUTPUT_ISO="$SCRIPT_DIR/cezen-ai-ubuntu2204.iso"
UBUNTU_ISO_URL="https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso" UBUNTU_URL="https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso"
echo "╔══════════════════════════════════════════╗" echo "╔══════════════════════════════════════════╗"
echo "║ Cezen AI — ISO Builder ║" echo "║ Cezen AI — ISO Builder ║"
echo "╚══════════════════════════════════════════╝" echo "╚══════════════════════════════════════════╝"
echo "" echo ""
# Check Docker is running # ── Install build tools ────────────────────────
if ! docker info &>/dev/null; then echo "→ Installing build tools..."
echo "ERROR: Docker is not running. Start Docker Desktop and try again."
exit 1
fi
echo "✓ Docker is running"
# Check autoinstall files exist
if [ ! -f "$SCRIPT_DIR/user-data" ] || [ ! -f "$SCRIPT_DIR/meta-data" ]; then
echo "ERROR: user-data or meta-data not found in $SCRIPT_DIR"
exit 1
fi
echo "✓ Autoinstall files found"
echo ""
echo "→ Building ISO inside Docker container (Ubuntu 22.04)..."
echo " This will take 515 minutes depending on internet speed."
echo ""
docker run --rm \
-v "$SCRIPT_DIR:/autoinstall" \
-v "$REPO_ROOT:/repo" \
ubuntu:22.04 \
bash -c '
set -e
# Install tools
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq apt-get update -qq
apt-get install -y -qq xorriso wget isolinux rsync apt-get install -y -qq xorriso wget isolinux
echo "✓ Tools ready"
WORK_DIR="/tmp/iso-work" # ── Download Ubuntu ISO ────────────────────────
ORIGINAL_ISO="/tmp/ubuntu-22.04.5-live-server-amd64.iso" if [ -f "$ORIGINAL_ISO" ]; then
UBUNTU_URL="https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso" echo "✓ Ubuntu ISO already downloaded"
else
# Download Ubuntu ISO if not already cached
if [ ! -f "$ORIGINAL_ISO" ]; then
echo "→ Downloading Ubuntu 22.04.5 Server ISO (~1.8 GB)..." echo "→ Downloading Ubuntu 22.04.5 Server ISO (~1.8 GB)..."
wget -q --show-progress -O "$ORIGINAL_ISO" "$UBUNTU_URL" wget --show-progress -O "$ORIGINAL_ISO" "$UBUNTU_URL"
echo "✓ Downloaded"
fi fi
echo "✓ Ubuntu ISO ready"
# Extract ISO contents # ── Extract ISO ────────────────────────────────
echo "→ Extracting ISO..." echo "→ Extracting ISO..."
rm -rf "$WORK_DIR" rm -rf "$WORK_DIR"
mkdir -p "$WORK_DIR" mkdir -p "$WORK_DIR"
@ -72,47 +46,46 @@ xorriso -osirrox on \
-indev "$ORIGINAL_ISO" \ -indev "$ORIGINAL_ISO" \
-extract / "$WORK_DIR" 2>/dev/null -extract / "$WORK_DIR" 2>/dev/null
chmod -R u+w "$WORK_DIR" chmod -R u+w "$WORK_DIR"
echo "✓ ISO extracted" echo "✓ Extracted"
# Inject autoinstall files # ── Inject autoinstall files ───────────────────
echo "→ Injecting autoinstall config..." echo "→ Injecting autoinstall config..."
mkdir -p "$WORK_DIR/nocloud" mkdir -p "$WORK_DIR/nocloud"
cp /autoinstall/user-data "$WORK_DIR/nocloud/user-data" cp "$SCRIPT_DIR/user-data" "$WORK_DIR/nocloud/user-data"
cp /autoinstall/meta-data "$WORK_DIR/nocloud/meta-data" cp "$SCRIPT_DIR/meta-data" "$WORK_DIR/nocloud/meta-data"
echo "✓ user-data and meta-data injected"
# Modify GRUB to auto-select install with autoinstall # ── Patch GRUB ────────────────────────────────
echo "→ Patching GRUB config..."
GRUB_CFG="$WORK_DIR/boot/grub/grub.cfg" GRUB_CFG="$WORK_DIR/boot/grub/grub.cfg"
# Backup original
cp "$GRUB_CFG" "$GRUB_CFG.orig" cp "$GRUB_CFG" "$GRUB_CFG.orig"
# Set default to first entry and zero timeout # Set 5 second countdown then auto-install
sed -i "s/set timeout=.*/set timeout=5/" "$GRUB_CFG" sed -i "s/set timeout=.*/set timeout=5/" "$GRUB_CFG"
sed -i "s/set timeout_style=.*/set timeout_style=countdown/" "$GRUB_CFG" sed -i "s/set timeout_style=.*/set timeout_style=countdown/" "$GRUB_CFG"
# Add autoinstall + nocloud parameters to the first linux line # Add autoinstall params to the first linux kernel line
# This patches the "Install Ubuntu Server" entry
sed -i "/^\s*linux.*vmlinuz/s/$/ autoinstall quiet ds=nocloud;s=\/cdrom\/nocloud\//" "$GRUB_CFG" sed -i "/^\s*linux.*vmlinuz/s/$/ autoinstall quiet ds=nocloud;s=\/cdrom\/nocloud\//" "$GRUB_CFG"
echo "✓ GRUB patched"
echo "✓ GRUB config patched" # ── Get EFI partition info for repacking ───────
# Get original ISO metadata for repacking
MBR_TEMPLATE=$(mktemp) MBR_TEMPLATE=$(mktemp)
dd if="$ORIGINAL_ISO" bs=1 count=432 of="$MBR_TEMPLATE" 2>/dev/null dd if="$ORIGINAL_ISO" bs=1 count=432 of="$MBR_TEMPLATE" 2>/dev/null
# Get EFI partition info EFI_START=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk '{print $2}')
EFI_START=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk "{print \$2}") EFI_SIZE=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk '{print $4}')
EFI_SIZE=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk "{print \$4}")
echo "→ Repacking ISO..." # ── Repack ISO ─────────────────────────────────
echo "→ Repacking ISO (this takes ~2 minutes)..."
xorriso -as mkisofs \ xorriso -as mkisofs \
-r \ -r \
-V "Cezen_AI_Ubuntu2204" \ -V "Cezen_AI_Ubuntu2204" \
-o /autoinstall/cezen-ai-ubuntu2204.iso \ -o "$OUTPUT_ISO" \
--grub2-mbr "$MBR_TEMPLATE" \ --grub2-mbr "$MBR_TEMPLATE" \
-partition_offset 16 \ -partition_offset 16 \
--mbr-force-bootable \ --mbr-force-bootable \
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b "$WORK_DIR/boot/grub/efi.img" \ -append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b \
"$WORK_DIR/boot/grub/efi.img" \
-appended_part_as_gpt \ -appended_part_as_gpt \
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \ -iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
-c "/boot.catalog" \ -c "/boot.catalog" \
@ -127,18 +100,17 @@ xorriso -as mkisofs \
-boot-load-size 4 \ -boot-load-size 4 \
"$WORK_DIR" 2>/dev/null "$WORK_DIR" 2>/dev/null
echo "✓ ISO built successfully"
ls -lh /autoinstall/cezen-ai-ubuntu2204.iso
'
echo "" echo ""
echo "╔══════════════════════════════════════════════════════╗" echo "╔══════════════════════════════════════════════════════╗"
echo "║ ISO built: autoinstall/cezen-ai-ubuntu2204.iso ║" echo "║ Done! ║"
echo "║ ║"
echo "║ Flash to USB: ║"
echo "║ sudo dd if=autoinstall/cezen-ai-ubuntu2204.iso \ ║"
echo "║ of=/dev/diskX bs=4m status=progress ║"
echo "║ (replace /dev/diskX with your USB drive) ║"
echo "╚══════════════════════════════════════════════════════╝" echo "╚══════════════════════════════════════════════════════╝"
echo "" echo ""
echo "→ To find your USB drive: diskutil list" ls -lh "$OUTPUT_ISO"
echo ""
echo "→ Copy to your MacBook:"
echo " scp user@172.16.10.180:~/aipackage/autoinstall/cezen-ai-ubuntu2204.iso ."
echo ""
echo "→ Flash to USB on MacBook:"
echo " diskutil list # find USB e.g. /dev/disk4"
echo " diskutil unmountDisk /dev/disk4"
echo " sudo dd if=cezen-ai-ubuntu2204.iso of=/dev/disk4 bs=4m status=progress"