How nvidia/enroot works
Project type and purpose
• Enroot is a CLI‐based, unprivileged “container” tool written in C (under bin/) and Bash (under src/).
• It imports container images (e.g., Docker), creates sandboxed root filesystems (squashfs/overlay), sets up user & mount namespaces, and launches processes without requiring root privileges.
File structure
• bin/ (C sources): core engine for namespace setup (enroot‐nsenter), mounting (enroot‐mount), rootfs conversion (enroot‐mksquashovlfs, enroot‐aufs2ovlfs), switching root (enroot‐switchroot).
• src/ (shell scripts): high‐level commands & workflows (bundle.sh, docker.sh, runtime.sh, common.sh).
• conf/: system‐wide & per‐user configuration files (enroot.conf.d, mounts, environ) and hook scripts (conf/hooks).
• deps/: bundled third‐party code (libbsd, musl, linux‐headers, makeself).
• pkg/: packaging logic (deb, rpm).
• doc/: user & developer documentation for commands, configuration, image format.
README for additional insights
• Emphasis on a KISS, daemon-less approach using Linux user/mount namespaces.
• Key workflow stages: import → create → start.
• Extensibility via standard hooks and a simple image format (squashfs).
Main components & relationships
a. CLI Front-End
• src/*.sh scripts parse user commands (import, create, start, exec).
b. Image Importer
• docker.sh fetches layers from a registry; enroot‐mksquashovlfs (or aufs2ovlfs) converts layers into a single squashfs.
c. Configuration & Hook Subsystem
• conf/enroot.conf.d and conf/hooks/*.sh are loaded at each lifecycle stage. Hooks run in the namespace to customize mounts, environment, or GPU support (e.g., 98‐nvidia.sh).
d. Container Runtime Core
• bin/enroot-mount mounts the squashfs (and overlay if needed).
• bin/enroot-nsenter + bin/enroot-switchroot enter user & mount namespaces, pivot root, and launch the target process.
e. Environment Scripts
• runtime.sh applies environment variables (conf/environ/*), executes hooks, then execs the user’s command.
f. Kernel Interfaces
• Uses unprivileged user namespace, mount namespace, pivot_root, mount(), etc.
g. Optional Libraries
• Bundled libbsd for portability; integration with libnvidia-container via hooks for GPU.
Architectural patterns & design principles
• Modular pipeline: import → conversion → mount → namespace entry → run.
• Separation of concerns: C code for syscalls & performance; shell scripts for orchestration & configuration.
• Extensible via hook scripts and a flat config directory.