Last updated:
genpack is the main command of the genpack toolchain. It reads genpack.json5 (or genpack.json) in the current directory and executes processing according to the subcommand.
genpack [global options] <subcommand>
Options common to all subcommands.
| Option | Type | Default | Description |
|---|---|---|---|
--debug | Flag | false | Display DEBUG level logs |
--overlay-override <DIR> | Path | (none) | Local override directory for genpack-overlay |
--independent-binpkgs | Flag | false | Use artifact-specific binary package cache |
--deep-depclean | Flag | false | Perform deep cleanup including build dependencies |
--compression <ALG> | Choice | (follows config) | SquashFS compression: gzip, xz, lzo, none |
--devel | Flag | false | Generate development image |
--variant <NAME> | String | (follows config) | Variant name to use |
Overrides the genpack-overlay repository (normally auto-fetched from GitHub) with a local directory. Used when developing genpack-overlay itself.
By default, a shared binary package cache at ~/.cache/genpack/{arch}/binpkgs/ is used, but specifying this option uses an independent cache per artifact. Use this to avoid interference between artifacts with significantly different USE flags.
Executes the full build pipeline (lower → upper → pack).
genpack build
This is the default behavior when the subcommand is omitted. Executes the following 3 phases in order:
On first run, automatically generates .gitignore and .vscode/settings.json if they don't exist.
Builds the lower layer (build environment).
genpack lower
Processing flow:
work/{arch}/ directorylower.img)genpack.json5 (USE flags, keywords, licenses, masks)circulardep_breaker exists)lower.files)Whether rebuilding the lower layer is needed is determined by timestamps of genpack.json5 and Portage-related subdirectories (savedconfig/, patches/, kernel/, env/, overlay/).
Builds the upper layer (runtime environment).
genpack upper
Prerequisite: lower execution must be completed.
Processing flow:
upper.img)lower.files from lower layerfiles/ directory to rootfiles/build.d/setup_commandsGenerate SquashFS image from upper layer.
genpack pack
Prerequisite: Both lower and upper execution must be completed.
Processing:
build.d/, log files, and temporary filesOutput files:
| File | Condition |
|---|---|
{name}-{arch}.squashfs | Always generated |
{name}-{arch}.img | If EFI bootloader is included |
Compression methods details:
| Method | mksquashfs options | Characteristics |
|---|---|---|
gzip | -Xcompression-level 1 | Default. Fast |
xz | -comp xz -b 1M | Smallest size. Time-consuming |
lzo | -comp lzo | Fast. Lower compression than gzip |
none | -no-compression | No compression |
Opens an interactive debug shell or runs a specified command in the lower layer.
genpack bash [command...]
When no command is given, launches a bash shell inside a systemd-nspawn container, allowing direct manipulation and inspection of lower layer filesystem. Used for verifying package installation status and debugging.
When a command is given, it is executed non-interactively inside the lower layer's nspawn container. The process exits with an error if the command fails.
Opens interactive debug shell overlaid on upper layer.
genpack upper-bash
Prerequisite: upper execution must be completed.
Used to inspect and debug the contents of the final image.
Creates a distribution archive of artifact definition.
genpack archive
Generates genpack-{name}.tar.gz containing genpack.json5 and all subdirectories (files/, savedconfig/, patches/, kernel/, env/, overlay/).
genpack places build artifacts and cache under the work/ directory.
stage3 and Portage snapshots are cached under work/. Validated by HTTP headers (Last-Modified, ETag, Content-Length), and not re-downloaded if unchanged.
By default, binary packages are stored in ~/.cache/genpack/{arch}/binpkgs/ as a shared cache. Compiled packages can be reused across different artifacts of the same architecture.
When --independent-binpkgs is specified, an independent cache per artifact is used instead of this shared cache.
The genpack-overlay git repository is cached in ~/.cache/genpack/overlay/.
genpack itself does not reference any environment variables, but the following environment variables are set within the container during the build process:
| Variable | Set When | Value |
|---|---|---|
ARTIFACT | Upper layer build | name from genpack.json5 |
VARIANT | Upper layer build | Variant name (only when specified) |
| Setting | Value |
|---|---|
| Lower layer image size | 128 GiB |
| Upper layer image size | 20 GiB |
| genpack-overlay repository | https://github.com/wbrxcorp/genpack-overlay.git |
| Gentoo mirror | http://ftp.iij.ad.jp/pub/linux/gentoo/ |
| Default compression | gzip |
# Full build
genpack build
# Full build (xz compression)
genpack --compression xz build
# Build with variant specified
genpack --variant cuda build
# Step-by-step build
genpack lower
genpack upper
genpack pack
# Debug (lower layer shell)
genpack bash
# Run a command in the lower layer
genpack bash emerge --info
# Debug (upper layer shell)
genpack upper-bash
# Debug (verbose logs)
genpack --debug build
# Build with local genpack-overlay version
genpack --overlay-override ~/projects/genpack-overlay build
# Create archive
genpack archive
This document was written based on the following repository snapshots: