Inject universal /slim/init instead of requiring container-specific setup
CI / build (pull_request) Successful in 12s

slim now works with any Containerfile by injecting distro-agnostic scripts
at build time:

- /slim/init: mounts special filesystems, configures networking (static
  QEMU slirp), sets up cgroup2, timezone, and rootless container prereqs.
  Parses slim.cmd=<base64> from the kernel cmdline for runtime overrides,
  otherwise execs /slim/exec.

- /slim/exec: generated from the image's CMD/ENTRYPOINT (via podman image
  inspect), overridable via --cmd at build and run time.

Changes:
- New src/inject.rs: inspect image config, infer command, generate
  /slim/exec script, inject /slim/ into mounted rootfs
- New src/scripts/slim-init.sh: the universal init script (include_str!)
- build.rs: rename --init to --cmd, inject scripts before packing,
  drop Meta::save, restructure to ensure unmount always runs
- qemu.rs: hardcode init=/slim/init, add --cmd (base64 on cmdline),
  drop Meta::load, add -no-reboot
- Remove src/meta.rs and meta.toml (no longer needed)
- Cargo.toml: add serde_json + base64, remove unused walkdir + cpio + toml
- Example Containerfiles simplified to plain FROM + CMD
- New example/test.sh for manual verification
- README updated for new workflow
This commit is contained in:
2026-09-08 09:21:12 +02:00
parent 506213ed9a
commit 589afef4f5
14 changed files with 494 additions and 274 deletions
+16 -4
View File
@@ -2,19 +2,31 @@
Turning containers into bootable VMs
## Example - Minimal Alpine Busybox
## Example
```sh
# Build the container
podman build ./example/alpine -t slim-alpine
# Make the container bootable by extracing initrd (initial ramdisk)
slim build qcow2 slim-alpine --init=/init
# Make the container bootable. slim injects /slim/init and /slim/exec,
# then packs the rootfs as a qcow2 disk.
slim build qcow2 slim-alpine
# Boot the image using QEMU, `./example/alpine/init` will drop you into an interactive shell.
# Boot the image using QEMU. The container's CMD runs automatically.
slim run slim-alpine
# Override the command at runtime (base64-encoded on the kernel cmdline):
slim run slim-alpine --cmd '/bin/sh'
# Override the command at build time (baked into /slim/exec):
slim build qcow2 slim-alpine --cmd '/bin/sh'
# Cleanup
slim image rm slim-alpine
podman image rm slim-alpine
```
## Kernel
slim boots VMs using a shared kernel at `$XDG_DATA_HOME/slim-rs/vmlinuz`.
Place a suitable x86 bzImage there before running `slim run`.