From aa4bc0401b0e1e14cbc7a034d41e49a297b9a187 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Tue, 20 Oct 2026 14:45:14 +0200 Subject: [PATCH] Move vmlinuz out of `registry` dir. --- src/qemu.rs | 21 ++++++++------------- src/registry.rs | 6 ++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/qemu.rs b/src/qemu.rs index a9dab63..f48c1e1 100644 --- a/src/qemu.rs +++ b/src/qemu.rs @@ -1,13 +1,4 @@ -//! QEMU: boot a registry entry with qemu-system-x86_64 using direct kernel -//! boot (-kernel/-initrd or -drive). The kernel is shared across all VMs -//! at $XDG_DATA_HOME/boco/registry/vmlinuz. A universal /boco/init script (injected -//! at build time) handles VM bootstrap; /boco/exec runs the container's -//! CMD/ENTRYPOINT. Runtime overrides are delivered as `boco.cmd=` -//! on the kernel cmdline. Host directories are shared into the guest via -//! virtio-fs: one virtiofsd daemon (under `podman unshare` for rootless -//! UID mapping) per `--mount`, plus a `-chardev socket` + `-device -//! vhost-user-fs-pci` pair on the QEMU side. The guest mounts each share -//! with `mount -t virtiofs ` (see `boco.mount=` cmdline). +//! See [`boot`] use anyhow::{Context, Result, bail}; use base64::Engine; @@ -16,7 +7,7 @@ use std::{fmt::Write as _, process::Command}; use crate::{ forward::PortForward, - registry::{registry_base_dir, registry_dir}, + registry::{registry_dir, vmlinuz_path}, virtiofs::{self, VirtiofsShare}, }; @@ -46,6 +37,10 @@ pub struct BootCmd { mount: Vec, } +/// Invoke `qemu` to boot a boco image. See [`BootCmd`] for options +/// +/// This uses qemu's direct-kernel-boot with `-kernel`, so it does not require a bootloader. +/// The boco image is just an ext4 rootfs. pub(crate) fn boot( BootCmd { name, @@ -56,13 +51,13 @@ pub(crate) fn boot( }: BootCmd, ) -> Result<()> { let reg_dir = registry_dir(&name)?; - let vmlinuz_path = registry_base_dir()?.join("vmlinuz"); + let vmlinuz_path = vmlinuz_path()?; let initrd_path = reg_dir.join("initrd"); let qcow2_path = reg_dir.join("image.qcow2"); if !vmlinuz_path.exists() { // TODO: guide user in how to set up a kernel bail!( - "No kernel available. Place a vmlinuz at {}", + "No kernel available. Expected vmlinuz at {}", vmlinuz_path.display() ); } diff --git a/src/registry.rs b/src/registry.rs index 8caf92e..1e2636b 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -26,6 +26,12 @@ pub(crate) fn validate_image_name(name: &str) -> Result<()> { Ok(()) } +pub(crate) fn vmlinuz_path() -> Result { + let base = xdg::BaseDirectories::with_prefix("boco"); + base.place_data_file("vmlinuz") + .context("Failed to create XDG_DATA_HOME subdirectory") +} + pub(crate) fn registry_base_dir() -> Result { let base = xdg::BaseDirectories::with_prefix("boco"); base.create_data_directory("registry")