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) <noreply@anthropic.com>
This commit is contained in:
Dorian 2026-03-14 03:05:04 +00:00
parent 510dd8b05f
commit c0d5034e56
2 changed files with 23 additions and 1 deletions

View File

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

View File

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