1use std::os::unix::process::CommandExt; 2use std::path::Path; 3use std::process::Command; 4 5pub fn command(disk: &Path, shares: &[(&str, &Path, bool)]) -> Command { 6 let cpus = std::thread::available_parallelism().map_or(2, |n| n.get().min(4)); 7 let mut cmd = Command::new("qemu-system-x86_64"); 8 unsafe { 9 cmd.pre_exec(|| { 10 libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL); 11 Ok(()) 12 }); 13 } 14 cmd.args([ 15 "-enable-kvm", 16 "-cpu", 17 "host", 18 "-m", 19 "8192", 20 "-smp", 21 &cpus.to_string(), 22 ]) 23 .args(["-display", "none", "-vga", "virtio", "-no-reboot"]) 24 .arg("-drive") 25 .arg(format!("file={},if=virtio,format=qcow2", disk.display())); 26 for (tag, path, readonly) in shares { 27 let ro = if *readonly { ",readonly=on" } else { "" }; 28 cmd.arg("-virtfs").arg(format!( 29 "local,path={},mount_tag={tag},security_model=none,id={tag}{ro}", 30 path.display() 31 )); 32 } 33 cmd 34}