From 306412c99593c27e7524effe0ee54750bdf46897 Mon Sep 17 00:00:00 2001 From: Thales Maciel Date: Fri, 30 Jan 2026 11:08:10 -0300 Subject: [PATCH] Add rootfs/kernel overrides --- README.md | 5 +++++ customize.sh | 1 + run.sh | 26 ++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f68665f..8574b7a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Minimal Firecracker launcher. - `--name`: must be unique and match `[a-z0-9][a-z0-9_-]{0,63}`. - `--vcpu`: defaults to 2, max 16. - `--ram`: MiB, defaults to 1024, max 32768. +- `--rootfs`: path to the base rootfs image (default: `./rootfs.ext4`). +- `--kernel`: path to the kernel image (default: `./vmlinux`). - `--home-size`: M/G suffixes supported (default: 2G). ## Storage Layout @@ -59,8 +61,11 @@ reboot ## VM Info File Each VM writes a metadata file at `state/vms//info` with the following fields: - `id`: unique identifier for the VM instance. +- `name`: VM name. - `pid`: Firecracker process ID. - `created_at`: timestamp when the VM was launched. +- `rootfs`: root filesystem image path used to launch the VM. +- `kernel`: kernel image path used to launch the VM. - `guest_ip`: IP address assigned to the guest. - `tap`: host TAP interface name attached to the bridge. - `api_sock`: path to the Firecracker API socket (stored under `$XDG_RUNTIME_DIR/banger/` when available). diff --git a/customize.sh b/customize.sh index 626853b..d9f6ee0 100755 --- a/customize.sh +++ b/customize.sh @@ -36,6 +36,7 @@ mkdir -p "$VM_ROOT" BASE_ROOTFS="$DIR/rootfs.ext4" FC_BIN="$DIR/firecracker" + KERNEL="$DIR/vmlinux" SSH_KEY="$DIR/id_ed25519" diff --git a/run.sh b/run.sh index a4f96cf..171635f 100755 --- a/run.sh +++ b/run.sh @@ -13,6 +13,8 @@ Options: --name VM name (lowercase letters, digits, -, _) --vcpu vCPU count (default: 2) --ram RAM in MiB (default: 1024) + --rootfs Root filesystem image (default: ./rootfs.ext4) + --kernel Kernel image (default: ./vmlinux) --home-size Home disk size (e.g. 4G, 10240M) -h, --help Show this help EOF @@ -26,8 +28,8 @@ VM_ROOT="$STATE/vms" mkdir -p "$VM_ROOT" FC_BIN="$DIR/firecracker" -KERNEL="$DIR/vmlinux" -ROOTFS="$DIR/rootfs.ext4" +DEFAULT_KERNEL="$DIR/vmlinux" +DEFAULT_ROOTFS="$DIR/rootfs.ext4" SSH_KEY="$DIR/id_ed25519" NAMEGEN="$DIR/namegen" @@ -48,6 +50,8 @@ DNS_SERVER="1.1.1.1" VCPU_COUNT="$DEFAULT_VCPU" RAM_MIB="$DEFAULT_RAM" HOME_SIZE="$DEFAULT_HOME_SIZE" +KERNEL="$DEFAULT_KERNEL" +ROOTFS="$DEFAULT_ROOTFS" VM_NAME="" shopt -s nullglob @@ -93,6 +97,14 @@ while [[ $# -gt 0 ]]; do RAM_MIB="${2:-}" shift 2 ;; + --rootfs) + ROOTFS="${2:-}" + shift 2 + ;; + --kernel) + KERNEL="${2:-}" + shift 2 + ;; --home-size) HOME_SIZE="${2:-}" shift 2 @@ -159,6 +171,14 @@ if ! [[ "$VM_NAME" =~ ^[a-z0-9][a-z0-9_-]{0,63}$ ]]; then log "invalid --name value: $VM_NAME" exit 1 fi +if [[ ! -f "$ROOTFS" ]]; then + log "rootfs not found: $ROOTFS" + exit 1 +fi +if [[ ! -f "$KERNEL" ]]; then + log "kernel not found: $KERNEL" + exit 1 +fi if name_taken "$VM_NAME"; then log "name already in use: $VM_NAME" exit 1 @@ -365,6 +385,8 @@ id=$VM_ID name=$VM_NAME pid=$FC_PID created_at=$(date -Iseconds) +rootfs=$ROOTFS +kernel=$KERNEL guest_ip=$GUEST_IP tap=$TAP_DEV api_sock=$API_SOCK