customize base rootfs arg

This commit is contained in:
Thales Maciel 2026-02-05 14:37:03 -03:00
parent 01517dd902
commit a8078f2393
3 changed files with 25 additions and 15 deletions

View file

@ -68,10 +68,12 @@ reboot
## Customize Rootfs (Docker + Kernel Modules)
Use `customize.sh` to build a writable rootfs with Docker and kernel modules
preloaded so Docker works out of the box.
preloaded so Docker works out of the box. Pass the base rootfs as a positional
argument; the output defaults to `docker-<base filename>` in the same directory
unless you pass `--out`.
```
./customize.sh rootfs-docker.ext4 --size 6G --docker
./customize.sh ./rootfs.ext4 --size 6G --docker
```
Options:
@ -80,6 +82,7 @@ Options:
- `--initrd`: initrd path (default: `./wtf/root/boot/initrd.img-6.8.0-94-generic`).
- `--modules`: kernel modules directory (default: `./wtf/root/lib/modules/6.8.0-94-generic`).
- `--docker`: install Docker packages into the image.
- `--out`: output rootfs path (default: `docker-<base filename>`).
After boot, enable NAT and validate Docker:
```

View file

@ -7,7 +7,7 @@ log() {
usage() {
cat <<'EOF'
Usage: ./customize.sh <output-rootfs> [--size <size>] [--base-rootfs <path>] [--kernel <path>] [--initrd <path>] [--docker] [--modules <dir>]
Usage: ./customize.sh <base-rootfs> [--out <path>] [--size <size>] [--kernel <path>] [--initrd <path>] [--docker] [--modules <dir>]
Creates a copy of rootfs.ext4, optionally resizes it, boots a VM using the
copy as a writable rootfs, then applies base configuration and packages.
@ -46,18 +46,19 @@ BR_IP="172.16.0.1"
CIDR="24"
DNS_SERVER="1.1.1.1"
BASE_ROOTFS=""
OUT_ROOTFS=""
SIZE_SPEC=""
INSTALL_DOCKER=0
MODULES_DIR="$DIR/wtf/root/lib/modules/6.8.0-94-generic"
while [[ $# -gt 0 ]]; do
case "$1" in
--size)
SIZE_SPEC="${2:-}"
--out)
OUT_ROOTFS="${2:-}"
shift 2
;;
--base-rootfs)
BASE_ROOTFS="${2:-}"
--size)
SIZE_SPEC="${2:-}"
shift 2
;;
--kernel)
@ -81,8 +82,8 @@ while [[ $# -gt 0 ]]; do
exit 0
;;
*)
if [[ -z "$OUT_ROOTFS" ]]; then
OUT_ROOTFS="$1"
if [[ -z "$BASE_ROOTFS" ]]; then
BASE_ROOTFS="$1"
shift
else
log "unknown option: $1"
@ -93,7 +94,7 @@ while [[ $# -gt 0 ]]; do
esac
done
if [[ -z "$OUT_ROOTFS" ]]; then
if [[ -z "$BASE_ROOTFS" ]]; then
usage
exit 1
fi
@ -102,6 +103,12 @@ if [[ ! -f "$BASE_ROOTFS" ]]; then
log "base rootfs not found: $BASE_ROOTFS"
exit 1
fi
if [[ -z "$OUT_ROOTFS" ]]; then
base_dir="$(dirname "$BASE_ROOTFS")"
base_name="$(basename "$BASE_ROOTFS")"
OUT_ROOTFS="${base_dir}/docker-${base_name}"
fi
if [[ ! -f "$KERNEL" ]]; then
log "kernel not found: $KERNEL"
exit 1

View file

@ -62,8 +62,8 @@ if [[ -z "$BASE_ROOTFS" ]]; then
fi
fi
log "building $OUT_ROOTFS from $BASE_ROOTFS"
exec "$DIR/customize.sh" "$OUT_ROOTFS" \
--size "$SIZE_SPEC" \
--base-rootfs "$BASE_ROOTFS" \
--docker
log "building $OUT_ROOTFS from $BASE_ROOTFS"
exec "$DIR/customize.sh" "$BASE_ROOTFS" \
--out "$OUT_ROOTFS" \
--size "$SIZE_SPEC" \
--docker