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) ## Customize Rootfs (Docker + Kernel Modules)
Use `customize.sh` to build a writable rootfs with Docker and 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: Options:
@ -80,6 +82,7 @@ Options:
- `--initrd`: initrd path (default: `./wtf/root/boot/initrd.img-6.8.0-94-generic`). - `--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`). - `--modules`: kernel modules directory (default: `./wtf/root/lib/modules/6.8.0-94-generic`).
- `--docker`: install Docker packages into the image. - `--docker`: install Docker packages into the image.
- `--out`: output rootfs path (default: `docker-<base filename>`).
After boot, enable NAT and validate Docker: After boot, enable NAT and validate Docker:
``` ```

View file

@ -7,7 +7,7 @@ log() {
usage() { usage() {
cat <<'EOF' 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 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. copy as a writable rootfs, then applies base configuration and packages.
@ -46,18 +46,19 @@ BR_IP="172.16.0.1"
CIDR="24" CIDR="24"
DNS_SERVER="1.1.1.1" DNS_SERVER="1.1.1.1"
BASE_ROOTFS=""
OUT_ROOTFS="" OUT_ROOTFS=""
SIZE_SPEC="" SIZE_SPEC=""
INSTALL_DOCKER=0 INSTALL_DOCKER=0
MODULES_DIR="$DIR/wtf/root/lib/modules/6.8.0-94-generic" MODULES_DIR="$DIR/wtf/root/lib/modules/6.8.0-94-generic"
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--size) --out)
SIZE_SPEC="${2:-}" OUT_ROOTFS="${2:-}"
shift 2 shift 2
;; ;;
--base-rootfs) --size)
BASE_ROOTFS="${2:-}" SIZE_SPEC="${2:-}"
shift 2 shift 2
;; ;;
--kernel) --kernel)
@ -81,8 +82,8 @@ while [[ $# -gt 0 ]]; do
exit 0 exit 0
;; ;;
*) *)
if [[ -z "$OUT_ROOTFS" ]]; then if [[ -z "$BASE_ROOTFS" ]]; then
OUT_ROOTFS="$1" BASE_ROOTFS="$1"
shift shift
else else
log "unknown option: $1" log "unknown option: $1"
@ -93,7 +94,7 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
if [[ -z "$OUT_ROOTFS" ]]; then if [[ -z "$BASE_ROOTFS" ]]; then
usage usage
exit 1 exit 1
fi fi
@ -102,6 +103,12 @@ if [[ ! -f "$BASE_ROOTFS" ]]; then
log "base rootfs not found: $BASE_ROOTFS" log "base rootfs not found: $BASE_ROOTFS"
exit 1 exit 1
fi 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 if [[ ! -f "$KERNEL" ]]; then
log "kernel not found: $KERNEL" log "kernel not found: $KERNEL"
exit 1 exit 1

View file

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