mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-26 06:59:28 +02:00
Add qemu command
This commit is contained in:
parent
7f6a0c0a0f
commit
91215703bf
14
src/args.rs
14
src/args.rs
@ -19,6 +19,9 @@ pub enum Command {
|
||||
|
||||
#[structopt(name = "chroot", about = "Chroot into exiting Live USB")]
|
||||
Chroot(ChrootCommand),
|
||||
|
||||
#[structopt(name = "qemu", about = "Boot the USB with Qemu")]
|
||||
Qemu(QemuCommand),
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
@ -54,3 +57,14 @@ pub struct ChrootCommand {
|
||||
#[structopt()]
|
||||
pub command: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(StructOpt)]
|
||||
pub struct QemuCommand {
|
||||
/// Path starting with /dev/disk/by-id for the USB drive
|
||||
#[structopt(parse(from_os_str))]
|
||||
pub block_device: PathBuf,
|
||||
|
||||
/// Arguments to pass to qemu
|
||||
#[structopt()]
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
@ -70,6 +70,9 @@ pub enum ErrorKind {
|
||||
|
||||
#[fail(display = "Error setting the locale")]
|
||||
Locale,
|
||||
|
||||
#[fail(display = "Failed launching Qemu")]
|
||||
Qemu,
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
|
33
src/main.rs
33
src/main.rs
@ -15,6 +15,7 @@ use nix::sys::signal;
|
||||
use simplelog::*;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::os::unix::process::CommandExt as UnixCommandExt;
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
use std::thread;
|
||||
@ -299,6 +300,37 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn qemu(command: QemuCommand) -> Result<(), Error> {
|
||||
let qemu = Tool::find("qemu-system-x86_64")?;
|
||||
|
||||
let err = qemu
|
||||
.execute()
|
||||
.args(&[
|
||||
"-enable-kvm",
|
||||
"-cpu",
|
||||
"host",
|
||||
"-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)
|
||||
.exec();
|
||||
|
||||
Err(err).context(ErrorKind::Qemu)?
|
||||
}
|
||||
|
||||
extern "C" fn handle_sigint(_: i32) {
|
||||
warn!("Interrupted");
|
||||
}
|
||||
@ -327,6 +359,7 @@ fn main() {
|
||||
let result = match app.cmd {
|
||||
Command::Create(command) => create(command),
|
||||
Command::Chroot(command) => chroot(command),
|
||||
Command::Qemu(command) => qemu(command),
|
||||
};
|
||||
|
||||
match result {
|
||||
|
Loading…
x
Reference in New Issue
Block a user