Progress
CI / build (push) Successful in 14s

This commit is contained in:
2026-09-04 17:01:46 +02:00
parent 286def05c1
commit 7dd818db68
7 changed files with 170 additions and 24 deletions
+26 -3
View File
@@ -3,9 +3,10 @@
use anyhow::{Context, Result, bail};
use clap::Args;
use std::process::Command;
use std::{fmt::Write as _, process::Command};
use crate::{
forward::PortForward,
meta::Meta,
registry::{registry_base_dir, registry_dir},
};
@@ -18,9 +19,19 @@ pub struct RunCmd {
/// Amount of memory to give the VM, in qemu's format.
#[clap(short, long, default_value = "1024M")]
memory: String,
/// Forward ports from host to guest. Example: `tcp:0.0.0.0:80-:8080`
#[clap(long)]
forward: Vec<PortForward>,
}
pub(crate) fn run(RunCmd { name, memory }: RunCmd) -> Result<()> {
pub(crate) fn run(
RunCmd {
name,
memory,
forward,
}: RunCmd,
) -> Result<()> {
let reg_dir = registry_dir(&name)?;
let vmlinuz_path = registry_base_dir()?.join("vmlinuz");
let initrd_path = reg_dir.join("initrd");
@@ -41,6 +52,7 @@ pub(crate) fn run(RunCmd { name, memory }: RunCmd) -> Result<()> {
"earlyprintk=serial",
"nokaslr",
&init_arg,
"devtmpfs.mount=1", // Automatically mount /dev at boot
];
let qcow2_arg = format!("file={},format=qcow2,if=virtio", qcow2_path.display());
@@ -63,15 +75,26 @@ pub(crate) fn run(RunCmd { name, memory }: RunCmd) -> Result<()> {
let cmdline = cmdline.join(" ");
// add NIC and forward any user specified ports
let mut network = "user,model=virtio-net-pci".to_string();
for forward in &forward {
_ = write!(&mut network, ",hostfwd={forward}");
}
let mut command = Command::new("qemu-system-x86_64");
// TODO: make a lot of this configurable. especially -cpus
command
.args(["-accel", "kvm"])
.args(["-cpu", "host", "-smp", "cpus=8"])
.args(["-m", &memory])
.arg("-kernel")
.arg(vmlinuz_path.as_os_str())
.args(fs_args)
.args(["-snapshot"])
.args(["-append", &cmdline])
.args(["-nographic"])
.args(["-nic", "user,model=virtio-net-pci"]);
.args(["-nic", &network]);
println!("{command:?}");