mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-26 23:19:29 +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")]
|
#[structopt(name = "chroot", about = "Chroot into exiting Live USB")]
|
||||||
Chroot(ChrootCommand),
|
Chroot(ChrootCommand),
|
||||||
|
|
||||||
|
#[structopt(name = "qemu", about = "Boot the USB with Qemu")]
|
||||||
|
Qemu(QemuCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
#[derive(StructOpt)]
|
||||||
@ -54,3 +57,14 @@ pub struct ChrootCommand {
|
|||||||
#[structopt()]
|
#[structopt()]
|
||||||
pub command: Vec<String>,
|
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")]
|
#[fail(display = "Error setting the locale")]
|
||||||
Locale,
|
Locale,
|
||||||
|
|
||||||
|
#[fail(display = "Failed launching Qemu")]
|
||||||
|
Qemu,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail for Error {
|
impl Fail for Error {
|
||||||
|
33
src/main.rs
33
src/main.rs
@ -15,6 +15,7 @@ use nix::sys::signal;
|
|||||||
use simplelog::*;
|
use simplelog::*;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::os::unix::process::CommandExt as UnixCommandExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
@ -299,6 +300,37 @@ fn chroot(command: ChrootCommand) -> Result<(), Error> {
|
|||||||
Ok(())
|
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) {
|
extern "C" fn handle_sigint(_: i32) {
|
||||||
warn!("Interrupted");
|
warn!("Interrupted");
|
||||||
}
|
}
|
||||||
@ -327,6 +359,7 @@ fn main() {
|
|||||||
let result = match app.cmd {
|
let result = match app.cmd {
|
||||||
Command::Create(command) => create(command),
|
Command::Create(command) => create(command),
|
||||||
Command::Chroot(command) => chroot(command),
|
Command::Chroot(command) => chroot(command),
|
||||||
|
Command::Qemu(command) => qemu(command),
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user