Add rootfs/kernel overrides

This commit is contained in:
Thales Maciel 2026-01-30 11:08:10 -03:00
parent f7e372d8db
commit 306412c995
No known key found for this signature in database
GPG key ID: 33112E6833C34679
3 changed files with 30 additions and 2 deletions

View file

@ -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/<id>/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).

View file

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

26
run.sh
View file

@ -13,6 +13,8 @@ Options:
--name <name> VM name (lowercase letters, digits, -, _)
--vcpu <count> vCPU count (default: 2)
--ram <mib> RAM in MiB (default: 1024)
--rootfs <path> Root filesystem image (default: ./rootfs.ext4)
--kernel <path> Kernel image (default: ./vmlinux)
--home-size <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