💽 Build Bespoke OS Images
2,001
stars
6,484
commits
Python
primary language
Sep 8, 2026
updated
A fancy wrapper around dnf --installroot, apt, pacman
and zypper that generates customized disk images with a number of
bells and whistles.
For a longer description and available features and options, see the man
page or run mkosi documentation. When
getting started see the EXAMPLES section.
You can install mkosi from your distribution using its package manager
or install the development version from git. If you install mkosi using
your distribution's package manager, make sure it installs at least
mkosi v16 or newer (Use mkosi --version to check). If your
distribution only packages an older version of mkosi, it is recommended
to install mkosi using one of the alternative installation methods
listed below instead.
To run mkosi straight from its git repository, you can invoke the shim
bin/mkosi. The MKOSI_INTERPRETER environment variable can be set
when using the bin/mkosi shim to configure the python interpreter used
to execute mkosi. The shim can be symlinked to e.g. ~/.local/bin to
make it accessible from the PATH. Note that to make this work you
might have to add ~/.local/bin to your user's PATH.
git clone https://github.com/systemd/mkosi
ln -s $PWD/mkosi/bin/mkosi ~/.local/bin/mkosi
mkosi --version
mkosi also provides other companion tools that can be enabled in a similar manner.
ln -s $PWD/mkosi/bin/mkosi-addon ~/.local/bin/mkosi-addon
ln -s $PWD/mkosi/bin/mkosi-initrd ~/.local/bin/mkosi-initrd
ln -s $PWD/mkosi/bin/mkosi-sandbox ~/.local/bin/mkosi-sandbox
mkosi can also be installed straight from the git repository url using
pipx:
pipx install git+https://github.com/systemd/mkosi.git
mkosi --version
which will transparently install mkosi into a Python virtual environment
and a mkosi binary to ~/.local/bin. This is, up to the path of the
virtual environment and the mkosi binary, equivalent to
python3 -m venv mkosivenv
mkosivenv/bin/pip install git+https://github.com/systemd/mkosi.git
mkosivenv/bin/mkosi --version
You can also package mkosi as a
zipapp that you can
deploy anywhere in your PATH. Running this will leave a mkosi binary
in builddir/
git clone https://github.com/systemd/mkosi
cd mkosi
tools/generate-zipapp.sh
builddir/mkosi --version
Besides the mkosi binary, you can also call mkosi via
python3 -m mkosi
when not installed as a zipapp.
Please note, that the python module exists solely for the usage of the mkosi binary and is not to be considered a public API.
mkosi packages for Debian, Ubuntu, Fedora and SUSE are built from latest main and published as repositories for the respective distributions on OBS. Follow these instructions to enable the appropriate repository.
mkosi can also be used as a kernel-install plugin to build initrds and addons. It is recommended to use only one of these two plugins at a given time.
To enable this feature, install kernel-install/50-mkosi.install
into /usr/lib/kernel/install.d. Extra distro configuration for the
initrd can be configured in /usr/lib/mkosi-initrd. Users can add their
own customizations in /etc/mkosi-initrd. A full self-contained UKI will
be built and installed.
Once installed, the mkosi plugin can be enabled by writing
initrd_generator=mkosi-initrd and layout=uki to /usr/lib/kernel/install.conf
or to /etc/kernel/install.conf.
To enable this feature, install kernel-install/51-mkosi-addon.install into
/usr/lib/kernel/install.d. Extra distro configuration for the addon can be
configured in /usr/lib/mkosi-addon. Users can add their own customizations in
/etc/mkosi-addon and /run/mkosi-addon. Note that unless at least one of the
last two directories are present, the plugin will not operate.
This plugin is useful to enhance a vendor-provided UKI with local-only modifications.
To hack on mkosi itself, you can run the full test suite locally, just like CI does. The tests include linting, type checking, and unit tests, all runnable via pytest.
All linters such as ruff or mypy are run inside mkosi box
(i.e. from inside mkosi.tools/) for a consistent environment. Build that with:
bin/mkosi -f box -- true
Then run the full test suite inside the tools tree:
bin/mkosi box -- pytest
You can use pytest options to only run a subset, for example only run the linters:
bin/mkosi box -- pytest -k test_linters
Installation tests (venv, editable and zipapp installs) are marked with the
install marker and are skipped by default, as they create virtual
environments and install packages from the network. Run them explicitly with:
bin/mkosi box -- pytest -m install
When a tool that mkosi runs inside its sandbox fails, see Debugging failing sandboxed commands for how to replay the command by hand.
Integration tests build and boot full images. They are marked with the
integration marker, and are skipped by default. They need a tools tree and an
image to be built first. tools/integration-test-setup.sh writes a local
configuration for the given image and tools tree distribution and builds both:
tools/integration-test-setup.sh $DISTRIBUTION $TOOLS_TREE_DISTRIBUTION
For example, to test an Arch image built with a Fedora tools tree, then run a single integration test:
tools/integration-test-setup.sh arch fedora
bin/mkosi box -- pytest -m integration --distribution arch --capture=no --verbose \
'tests/test_boot.py::test_bootloader[systemd-boot]'
The integration tests require KVM and are skipped (or very slow) without
/dev/kvm.
Find us on Matrix at #mkosi:matrix.org.
(top 30 of 203)
Python
97.1%
Shell
2.8%
💽 Build Bespoke OS Images
2,001
stars
6,484
commits
Python
primary language
Sep 8, 2026
updated
A fancy wrapper around dnf --installroot, apt, pacman
and zypper that generates customized disk images with a number of
bells and whistles.
For a longer description and available features and options, see the man
page or run mkosi documentation. When
getting started see the EXAMPLES section.
You can install mkosi from your distribution using its package manager
or install the development version from git. If you install mkosi using
your distribution's package manager, make sure it installs at least
mkosi v16 or newer (Use mkosi --version to check). If your
distribution only packages an older version of mkosi, it is recommended
to install mkosi using one of the alternative installation methods
listed below instead.
To run mkosi straight from its git repository, you can invoke the shim
bin/mkosi. The MKOSI_INTERPRETER environment variable can be set
when using the bin/mkosi shim to configure the python interpreter used
to execute mkosi. The shim can be symlinked to e.g. ~/.local/bin to
make it accessible from the PATH. Note that to make this work you
might have to add ~/.local/bin to your user's PATH.
git clone https://github.com/systemd/mkosi
ln -s $PWD/mkosi/bin/mkosi ~/.local/bin/mkosi
mkosi --version
mkosi also provides other companion tools that can be enabled in a similar manner.
ln -s $PWD/mkosi/bin/mkosi-addon ~/.local/bin/mkosi-addon
ln -s $PWD/mkosi/bin/mkosi-initrd ~/.local/bin/mkosi-initrd
ln -s $PWD/mkosi/bin/mkosi-sandbox ~/.local/bin/mkosi-sandbox
mkosi can also be installed straight from the git repository url using
pipx:
pipx install git+https://github.com/systemd/mkosi.git
mkosi --version
which will transparently install mkosi into a Python virtual environment
and a mkosi binary to ~/.local/bin. This is, up to the path of the
virtual environment and the mkosi binary, equivalent to
python3 -m venv mkosivenv
mkosivenv/bin/pip install git+https://github.com/systemd/mkosi.git
mkosivenv/bin/mkosi --version
You can also package mkosi as a
zipapp that you can
deploy anywhere in your PATH. Running this will leave a mkosi binary
in builddir/
git clone https://github.com/systemd/mkosi
cd mkosi
tools/generate-zipapp.sh
builddir/mkosi --version
Besides the mkosi binary, you can also call mkosi via
python3 -m mkosi
when not installed as a zipapp.
Please note, that the python module exists solely for the usage of the mkosi binary and is not to be considered a public API.
mkosi packages for Debian, Ubuntu, Fedora and SUSE are built from latest main and published as repositories for the respective distributions on OBS. Follow these instructions to enable the appropriate repository.
mkosi can also be used as a kernel-install plugin to build initrds and addons. It is recommended to use only one of these two plugins at a given time.
To enable this feature, install kernel-install/50-mkosi.install
into /usr/lib/kernel/install.d. Extra distro configuration for the
initrd can be configured in /usr/lib/mkosi-initrd. Users can add their
own customizations in /etc/mkosi-initrd. A full self-contained UKI will
be built and installed.
Once installed, the mkosi plugin can be enabled by writing
initrd_generator=mkosi-initrd and layout=uki to /usr/lib/kernel/install.conf
or to /etc/kernel/install.conf.
To enable this feature, install kernel-install/51-mkosi-addon.install into
/usr/lib/kernel/install.d. Extra distro configuration for the addon can be
configured in /usr/lib/mkosi-addon. Users can add their own customizations in
/etc/mkosi-addon and /run/mkosi-addon. Note that unless at least one of the
last two directories are present, the plugin will not operate.
This plugin is useful to enhance a vendor-provided UKI with local-only modifications.
To hack on mkosi itself, you can run the full test suite locally, just like CI does. The tests include linting, type checking, and unit tests, all runnable via pytest.
All linters such as ruff or mypy are run inside mkosi box
(i.e. from inside mkosi.tools/) for a consistent environment. Build that with:
bin/mkosi -f box -- true
Then run the full test suite inside the tools tree:
bin/mkosi box -- pytest
You can use pytest options to only run a subset, for example only run the linters:
bin/mkosi box -- pytest -k test_linters
Installation tests (venv, editable and zipapp installs) are marked with the
install marker and are skipped by default, as they create virtual
environments and install packages from the network. Run them explicitly with:
bin/mkosi box -- pytest -m install
When a tool that mkosi runs inside its sandbox fails, see Debugging failing sandboxed commands for how to replay the command by hand.
Integration tests build and boot full images. They are marked with the
integration marker, and are skipped by default. They need a tools tree and an
image to be built first. tools/integration-test-setup.sh writes a local
configuration for the given image and tools tree distribution and builds both:
tools/integration-test-setup.sh $DISTRIBUTION $TOOLS_TREE_DISTRIBUTION
For example, to test an Arch image built with a Fedora tools tree, then run a single integration test:
tools/integration-test-setup.sh arch fedora
bin/mkosi box -- pytest -m integration --distribution arch --capture=no --verbose \
'tests/test_boot.py::test_bootloader[systemd-boot]'
The integration tests require KVM and are skipped (or very slow) without
/dev/kvm.
Find us on Matrix at #mkosi:matrix.org.
(top 30 of 203)
Python
97.1%
Shell
2.8%