Add auto-expand service in pull-image.sh

Create a systemd oneshot service that expands the rootfs on first boot
after flashing. The service self-destructs after running.

This ensures release images fill the SD card while keeping the
download size small (16GB shrunk image).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Aaron D. Lee
2026-01-08 11:02:01 -05:00
parent 3027706d49
commit cc745fbdfa

View File

@@ -123,6 +123,37 @@ else
echo -e "${GREEN} Rootfs already ~16GB${NC}"
fi
# ============================================================================
# Re-enable auto-expand for release image
# ============================================================================
echo
echo -e "${YELLOW}Re-enabling auto-expand for release...${NC}"
TEMP_ROOT=$(mktemp -d)
mount "$ROOT_PART" "$TEMP_ROOT"
# Create the resize service that runs on first boot
cat > "$TEMP_ROOT/etc/systemd/system/rpi-resizerootfs.service" <<'RESIZE_EOF'
[Unit]
Description=Resize root filesystem to fill SD card
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'resize2fs $(findmnt -n -o SOURCE /) && systemctl disable rpi-resizerootfs.service && rm -f /etc/systemd/system/rpi-resizerootfs.service'
ExecStartPost=/bin/systemctl daemon-reload
[Install]
WantedBy=multi-user.target
RESIZE_EOF
# Enable the service
mkdir -p "$TEMP_ROOT/etc/systemd/system/multi-user.target.wants"
ln -sf /etc/systemd/system/rpi-resizerootfs.service "$TEMP_ROOT/etc/systemd/system/multi-user.target.wants/rpi-resizerootfs.service"
umount "$TEMP_ROOT"
rmdir "$TEMP_ROOT"
echo -e "${GREEN} Auto-expand service installed${NC}"
# ============================================================================
# Pull image
# ============================================================================