From c0d5034e562c845df3de88906e59fad9e62688e1 Mon Sep 17 00:00:00 2001 From: Dorian Date: Sat, 14 Mar 2026 03:05:04 +0000 Subject: [PATCH] feat: auto-create swap file on first boot - Add swap creation to first-boot-containers.sh - Size: 50% of RAM (min 2GB, max 8GB) - Creates /swapfile, adds to /etc/fstab for persistence - Runs before container creation to prevent OOM during startup Co-Authored-By: Claude Opus 4.6 (1M context) --- loop/plan.md | 2 +- scripts/first-boot-containers.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/loop/plan.md b/loop/plan.md index 01bdf189..aab63924 100644 --- a/loop/plan.md +++ b/loop/plan.md @@ -303,7 +303,7 @@ Every test must pass **10 consecutive times** from BOTH .228→.198 AND .198→. - [ ] **ISO-01** — Audit ISO build script for all current apps. Verify `CAPTURE_PATTERNS` and `CONTAINER_IMAGES` in `build-auto-installer-iso.sh` include ALL apps currently running on .228 (33+ containers). Any missing container means a fresh install won't have that app. **Acceptance**: ISO capture list matches the full container inventory on .228. -- [ ] **ISO-02** — Add swap file creation to first-boot. In the first-boot script, auto-create a swap file sized at 50% of RAM (min 2GB, max 8GB). Add to fstab. **Acceptance**: Fresh install from ISO has swap configured automatically. +- [x] **ISO-02** — Added swap creation to first-boot-containers.sh. Calculates 50% of RAM (min 2GB, max 8GB), creates /swapfile, sets permissions 600, mkswap + swapon, adds to /etc/fstab. Skips if swap already exists. Runs before container creation so apps have swap available. - [ ] **ISO-03** — Add container dependency ordering to first-boot. Same startup ordering as CONT-02 but for the first-boot-containers.sh script. **Acceptance**: Fresh install starts containers in dependency order with zero crash loops. diff --git a/scripts/first-boot-containers.sh b/scripts/first-boot-containers.sh index 39616a23..3632887f 100644 --- a/scripts/first-boot-containers.sh +++ b/scripts/first-boot-containers.sh @@ -37,6 +37,28 @@ wait_for_container() { log "First-boot container creation starting (host=$TARGET_IP)" +# Create swap file if not present (50% of RAM, min 2GB, max 8GB) +if ! swapon --show | grep -q /swapfile; then + TOTAL_MEM_KB=$(awk '/MemTotal/ {print $2}' /proc/meminfo) + SWAP_MB=$((TOTAL_MEM_KB / 2 / 1024)) + [ "$SWAP_MB" -lt 2048 ] && SWAP_MB=2048 + [ "$SWAP_MB" -gt 8192 ] && SWAP_MB=8192 + log "Creating ${SWAP_MB}MB swap file..." + if dd if=/dev/zero of=/swapfile bs=1M count="$SWAP_MB" status=progress 2>>"$LOG"; then + chmod 600 /swapfile + mkswap /swapfile >>"$LOG" 2>&1 + swapon /swapfile + if ! grep -q '/swapfile' /etc/fstab; then + echo '/swapfile none swap sw 0 0' >> /etc/fstab + fi + log "Swap created: ${SWAP_MB}MB" + else + log "WARNING: Failed to create swap file" + fi +else + log "Swap already configured" +fi + # Ensure network exists (matches deploy) $DOCKER network create archy-net 2>/dev/null || true