mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-27 07:29:28 +02:00
43 lines
987 B
Rust
43 lines
987 B
Rust
use super::Tool;
|
|
use crate::args;
|
|
use anyhow::Context;
|
|
use log::debug;
|
|
|
|
use std::os::unix::process::CommandExt as UnixCommandExt;
|
|
use std::path::PathBuf;
|
|
|
|
/// Loads given block device in qemu
|
|
/// Uses kvm if it is enabled
|
|
pub fn qemu(command: args::QemuCommand) -> anyhow::Result<()> {
|
|
let qemu = Tool::find("qemu-system-x86_64")?;
|
|
|
|
let mut run = qemu.execute();
|
|
run.args(&[
|
|
"-m",
|
|
"4G",
|
|
"-netdev",
|
|
"user,id=user.0",
|
|
"-device",
|
|
"virtio-net-pci,netdev=user.0",
|
|
"-device",
|
|
"qemu-xhci,id=xhci",
|
|
"-device",
|
|
"usb-tablet,bus=xhci.0",
|
|
"-drive",
|
|
])
|
|
.arg(format!(
|
|
"file={},if=virtio,format=raw",
|
|
command.block_device.display()
|
|
))
|
|
.args(command.args);
|
|
|
|
if PathBuf::from("/dev/kvm").exists() {
|
|
debug!("KVM is enabled");
|
|
run.args(&["-enable-kvm", "-cpu", "host"]);
|
|
}
|
|
|
|
let err = run.exec();
|
|
|
|
Err(err).context("Failed launching Qemu")?
|
|
}
|