Add --mount flag for 9p host directory sharing
CI / build (push) Successful in 13s

Add support for sharing host directories into the VM via QEMU 9p
(virtio-9p).

The --mount flag can be repeated.

The format is `<host-path>` or `<host-path>:<guest-path>`

Relative guest paths are relative to the configured WORKDIR.

Design:
- QEMU: each --mount gets a short 9p tag (slim0, slim1, …) via
  -virtfs local,path=…,mount_tag=slimN,security_model=mapped-xattr.
  Tags are kept short because 9p mount_tag has a ~31-byte limit.
- Kernel cmdline: the full destination path is passed as
  slim.mount=<tag>:<base64(path)> so the init script knows where to
  mount each tag.  Base64 avoids issues with spaces/special chars.
- slim-init.sh: after networking, parse slim.mount= entries, mkdir -p
  the destination, and mount -t 9p <tag> <dest> -o trans=virtio,version=9p2000.L

Tests verify: 9p share detection via sysfs mount_tag, 9p entry in
mount output, file content accessible at the expected path, and clean
VM exit.
This commit is contained in:
2026-09-11 09:39:34 +02:00
committed by hulthe
parent 6111bbeb8d
commit 3a99da196d
5 changed files with 192 additions and 7 deletions
+6 -1
View File
@@ -78,7 +78,12 @@ fn build_inner(
let command = cmd.unwrap_or_else(|| inject::infer_command(&config));
let exec_script =
inject::build_exec_script(&command, &config.env, config.working_dir.as_deref());
inject::inject(mount_path, &exec_script, config.user.as_deref())?;
inject::inject(
mount_path,
&exec_script,
config.user.as_deref(),
config.working_dir.as_deref(),
)?;
println!("Injected /slim/ (init + exec)");
match kind {