+5
-8
@@ -6,7 +6,7 @@ mod registry;
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::image::ImageCmd;
|
||||
use crate::{image::ImageCmd, qemu::RunCmd};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(about = "Build bootable initrd VMs from container images")]
|
||||
@@ -25,11 +25,8 @@ enum Commands {
|
||||
#[arg(short = 's', long, default_value = "512")]
|
||||
_size: String,
|
||||
},
|
||||
/// Launch the VM via QEMU using registry artifacts
|
||||
Run {
|
||||
/// Image tag / registry subdir name
|
||||
name: String,
|
||||
},
|
||||
/// Launch a previously built VM via QEMU.
|
||||
Run(RunCmd),
|
||||
/// List slim images in the registry
|
||||
#[command(subcommand)]
|
||||
Image(ImageCmd),
|
||||
@@ -41,8 +38,8 @@ fn main() -> Result<()> {
|
||||
Commands::Build { image, _size: _ } => {
|
||||
build::build(&image)?;
|
||||
}
|
||||
Commands::Run { name } => {
|
||||
qemu::run(&name)?;
|
||||
Commands::Run(cmd) => {
|
||||
qemu::run(cmd)?;
|
||||
}
|
||||
Commands::Image(cmd) => {
|
||||
image::run(cmd)?;
|
||||
|
||||
+15
-4
@@ -2,12 +2,23 @@
|
||||
//! boot (-kernel/-initrd).
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use clap::Args;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::registry::registry_dir;
|
||||
|
||||
pub(crate) fn run(name: &str) -> Result<()> {
|
||||
let reg_dir = registry_dir(name)?;
|
||||
#[derive(Args, Debug)]
|
||||
pub struct RunCmd {
|
||||
/// Image tag / registry subdir name
|
||||
name: String,
|
||||
|
||||
/// Amount of memory to give the VM, in qemu's format.
|
||||
#[clap(short, long, default_value = "1024M")]
|
||||
memory: String,
|
||||
}
|
||||
|
||||
pub(crate) fn run(RunCmd { name, memory }: RunCmd) -> Result<()> {
|
||||
let reg_dir = registry_dir(&name)?;
|
||||
let vmlinuz_path = reg_dir.join("vmlinuz");
|
||||
let initrd_path = reg_dir.join("initrd");
|
||||
if !vmlinuz_path.exists() || !initrd_path.exists() {
|
||||
@@ -16,7 +27,7 @@ pub(crate) fn run(name: &str) -> Result<()> {
|
||||
name
|
||||
);
|
||||
}
|
||||
println!("Booting {} from registry: {}", name, reg_dir.display());
|
||||
println!("Booting {name} from registry: {}", reg_dir.display());
|
||||
println!(
|
||||
" qemu-system-x86_64 -m 256 -nographic -kernel {} -initrd {} -append 'console=ttyS0'",
|
||||
vmlinuz_path.display(),
|
||||
@@ -35,7 +46,7 @@ pub(crate) fn run(name: &str) -> Result<()> {
|
||||
|
||||
let mut command = Command::new("qemu-system-x86_64");
|
||||
command
|
||||
.args(["-m", "1024M"])
|
||||
.args(["-m", &memory])
|
||||
.arg("-kernel")
|
||||
.arg(vmlinuz_path.as_os_str())
|
||||
.arg("-initrd")
|
||||
|
||||
Reference in New Issue
Block a user