Files
volt-vmm/rootfs/build-initramfs.sh
Karl Clinger 40ed108dd5 Volt VMM (Neutron Stardust): source-available under AGPSL v5.0
KVM-based microVMM for the Volt platform:
- Sub-second VM boot times
- Minimal memory footprint
- Landlock LSM + seccomp security
- Virtio device support
- Custom kernel management

Copyright (c) Armored Gates LLC. All rights reserved.
Licensed under AGPSL v5.0
2026-03-21 01:04:35 -05:00

93 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Build the Volt custom initramfs (no Alpine, no BusyBox)
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
BINARY="$PROJECT_DIR/target/x86_64-unknown-linux-musl/release/volt-init"
OUTPUT="$SCRIPT_DIR/initramfs.cpio.gz"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${CYAN}=== Building Volt Initramfs ===${NC}"
# Build volt-init if needed
if [ ! -f "$BINARY" ] || [ "$1" = "--rebuild" ]; then
echo -e "${CYAN}Building volt-init...${NC}"
cd "$PROJECT_DIR"
source ~/.cargo/env
RUSTFLAGS="-C target-feature=+crt-static -C relocation-model=static -C target-cpu=x86-64" \
cargo build --release --target x86_64-unknown-linux-musl -p volt-init
fi
if [ ! -f "$BINARY" ]; then
echo -e "${RED}ERROR: volt-init binary not found at $BINARY${NC}"
echo "Run: cd rootfs/volt-init && cargo build --release --target x86_64-unknown-linux-musl"
exit 1
fi
echo -e "${GREEN}Binary: $(ls -lh "$BINARY" | awk '{print $5}')${NC}"
# Create rootfs structure
WORK=$(mktemp -d)
trap "rm -rf $WORK" EXIT
mkdir -p "$WORK"/{bin,dev,proc,sys,etc,tmp,run,var/log}
# Our init binary — the ONLY binary in the entire rootfs
cp "$BINARY" "$WORK/init"
chmod 755 "$WORK/init"
# Create /dev/console node (required for kernel to set up stdin/stdout/stderr)
# console = char device, major 5, minor 1
sudo mknod "$WORK/dev/console" c 5 1
sudo chmod 600 "$WORK/dev/console"
# Create /dev/ttyS0 for serial console
sudo mknod "$WORK/dev/ttyS0" c 4 64
sudo chmod 660 "$WORK/dev/ttyS0"
# Create /dev/null
sudo mknod "$WORK/dev/null" c 1 3
sudo chmod 666 "$WORK/dev/null"
# Minimal /etc
echo "volt-vmm" > "$WORK/etc/hostname"
cat > "$WORK/etc/os-release" << 'EOF'
NAME="Volt"
ID=volt-vmm
VERSION="0.1.0"
PRETTY_NAME="Volt VM (Custom Rust Userspace)"
HOME_URL="https://github.com/volt-vmm/volt-vmm"
EOF
# Build cpio archive (need root to preserve device nodes)
cd "$WORK"
sudo find . -print0 | sudo cpio --null -o -H newc --quiet 2>/dev/null | gzip -9 > "$OUTPUT"
# Report
SIZE=$(stat -c %s "$OUTPUT" 2>/dev/null || stat -f %z "$OUTPUT")
SIZE_KB=$((SIZE / 1024))
echo -e "${GREEN}=== Initramfs Built ===${NC}"
echo -e " Output: $OUTPUT"
echo -e " Size: ${SIZE_KB}KB ($(ls -lh "$OUTPUT" | awk '{print $5}'))"
echo -e " Binary: $(ls -lh "$BINARY" | awk '{print $5}') (static musl)"
echo -e " Contents: $(find . | wc -l) files"
# Check goals
if [ "$SIZE_KB" -lt 500 ]; then
echo -e " ${GREEN}✓ Under 500KB goal${NC}"
else
echo -e " ${RED}✗ Over 500KB goal (${SIZE_KB}KB)${NC}"
fi
echo ""
echo "Test with:"
echo " ./target/release/volt-vmm --kernel kernels/vmlinux --initrd rootfs/initramfs.cpio.gz -m 128M --cmdline \"console=ttyS0 reboot=k panic=1\""