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

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