Inject universal /slim/init instead of requiring container-specific setup #6

Merged
hulthe merged 1 commits from feature/universal-init into master 2026-09-08 22:14:13 +02:00
Collaborator

Summary

slim now works with any Containerfile — no more slim-specific init scripts, kernel installs, busybox, or DHCP clients in the Containerfile.

How it works

slim build injects distro-agnostic scripts into the image at /slim/:

  • /slim/init — mounts special filesystems (proc, sys, devpts, cgroup2, tmpfs), configures networking (static QEMU slirp: 10.0.2.15/24, gw 10.0.2.2, dns 10.0.2.3), sets timezone, and rootless container prereqs (newuidmap/newgidmap setuid, rshared /). 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 both build and run time.

Changes

  • New src/inject.rs: inspect image config, infer command, generate /slim/exec, inject /slim/ into mounted rootfs
  • New src/scripts/slim-init.sh: universal init script (embedded via include_str!)
  • build.rs: --init--cmd, inject before packing, drop Meta::save, restructure to always unmount
  • 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 (needs KVM)
  • README updated

Verification

cargo check      ✓
cargo clippy -- -D warnings  ✓
cargo test       ✓ (3 passed)
cargo fmt -- --check  ✓
``

The `example/test.sh` script tests CMD inference, `slim run --cmd` override, and `slim build --cmd` override for both Alpine and Archlinux (requires podman + QEMU + KVM).
## Summary slim now works with **any Containerfile** — no more slim-specific init scripts, kernel installs, busybox, or DHCP clients in the Containerfile. ### How it works `slim build` injects distro-agnostic scripts into the image at `/slim/`: - **`/slim/init`** — mounts special filesystems (proc, sys, devpts, cgroup2, tmpfs), configures networking (static QEMU slirp: 10.0.2.15/24, gw 10.0.2.2, dns 10.0.2.3), sets timezone, and rootless container prereqs (newuidmap/newgidmap setuid, rshared /). 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 both build and run time. ### Changes - New `src/inject.rs`: inspect image config, infer command, generate `/slim/exec`, inject `/slim/` into mounted rootfs - New `src/scripts/slim-init.sh`: universal init script (embedded via `include_str!`) - `build.rs`: `--init` → `--cmd`, inject before packing, drop `Meta::save`, restructure to always unmount - `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 (needs KVM) - README updated ### Verification ``` cargo check ✓ cargo clippy -- -D warnings ✓ cargo test ✓ (3 passed) cargo fmt -- --check ✓ `` The `example/test.sh` script tests CMD inference, `slim run --cmd` override, and `slim build --cmd` override for both Alpine and Archlinux (requires podman + QEMU + KVM).
marvin force-pushed feature/universal-init from 25efbd5f5c to 8fdac31160 2026-09-08 09:16:34 +02:00 Compare
marvin force-pushed feature/universal-init from 8fdac31160 to 589afef4f5 2026-09-08 09:21:15 +02:00 Compare
marvin force-pushed feature/universal-init from 589afef4f5 to d52a17fd53 2026-09-08 09:32:52 +02:00 Compare
marvin force-pushed feature/universal-init from d52a17fd53 to d528b55473 2026-09-08 09:36:18 +02:00 Compare
marvin force-pushed feature/universal-init from d528b55473 to cc2cbd0fb4 2026-09-08 09:41:35 +02:00 Compare
marvin force-pushed feature/universal-init from cc2cbd0fb4 to 1eed382172 2026-09-08 21:43:42 +02:00 Compare
marvin force-pushed feature/universal-init from 1eed382172 to 8d01d7d337 2026-09-08 21:43:59 +02:00 Compare
marvin added 1 commit 2026-09-08 21:58:04 +02:00
Inject universal /slim/init instead of requiring container-specific setup
CI / build (pull_request) Successful in 36s
CI / build (push) Successful in 13s
c2a9f00fc0
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
marvin force-pushed feature/universal-init from 8d01d7d337 to c2a9f00fc0 2026-09-08 21:58:04 +02:00 Compare
hulthe merged commit c2a9f00fc0 into master 2026-09-08 22:14:13 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hulthe/boco#6