banger/make-rootfs.sh
Thales Maciel 3cf33d1e0a
Streamline VM overlays and rootfs packages
Move the default guest package list into a repo manifest and record a hash beside built rootfs images so run/make-rootfs can warn when the docker-ready image is stale.

Switch the Firecracker launch path to a single sparse root overlay per VM instead of separate /home and /var disks, so many VMs can share the same base image while still installing packages under /var and working from /root.

Keep older images bootable by masking stale home.mount and var.mount units at boot, and scrub those obsolete fstab entries when customize.sh rebuilds an image. Verified with bash -n on the updated scripts; no live VM boot was run in this environment.
2026-03-15 19:36:54 -03:00

74 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
log() {
printf '[make-rootfs] %s\n' "$*"
}
usage() {
cat <<'EOF'
Usage: ./make-rootfs.sh [--size <size>] [--base-rootfs <path>]
Builds rootfs-docker.ext4 using customize.sh. If --base-rootfs is omitted,
the first existing file is used:
./rootfs.ext4
./ubuntu-noble-rootfs/rootfs.ext4
./ubuntu-lts/rootfs.ext4
EOF
}
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR/packages.sh"
OUT_ROOTFS="$DIR/rootfs-docker.ext4"
SIZE_SPEC="6G"
BASE_ROOTFS=""
while [[ $# -gt 0 ]]; do
case "$1" in
--size)
SIZE_SPEC="${2:-}"
shift 2
;;
--base-rootfs)
BASE_ROOTFS="${2:-}"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
log "unknown option: $1"
usage
exit 1
;;
esac
done
if [[ -f "$OUT_ROOTFS" ]]; then
OUT_ROOTFS_WARNING="$(banger_rootfs_manifest_warning "$OUT_ROOTFS" || true)"
if [[ -n "$OUT_ROOTFS_WARNING" ]]; then
log "warning: $OUT_ROOTFS_WARNING"
fi
log "already exists: $OUT_ROOTFS"
exit 0
fi
if [[ -z "$BASE_ROOTFS" ]]; then
if [[ -f "$DIR/rootfs.ext4" ]]; then
BASE_ROOTFS="$DIR/rootfs.ext4"
elif [[ -f "$DIR/ubuntu-noble-rootfs/rootfs.ext4" ]]; then
BASE_ROOTFS="$DIR/ubuntu-noble-rootfs/rootfs.ext4"
elif [[ -f "$DIR/ubuntu-lts/rootfs.ext4" ]]; then
BASE_ROOTFS="$DIR/ubuntu-lts/rootfs.ext4"
else
log "no base rootfs found"
exit 1
fi
fi
log "building $OUT_ROOTFS from $BASE_ROOTFS"
exec "$DIR/customize.sh" "$BASE_ROOTFS" \
--out "$OUT_ROOTFS" \
--size "$SIZE_SPEC" \
--docker