Debian Codegraph @

upstream/opensuse-leap-16-1/man1/mkosi.1.md

raw
1 % mkosi(1)
2 %
3 %
4
5 # NAME
6
7 mkosi — Build Bespoke OS Images
8
9 # SYNOPSIS
10
11 `mkosi [options…] summary`
12
13 `mkosi [options…] cat-config`
14
15 `mkosi [options…] build [command line…]`
16
17 `mkosi [options…] shell [command line…]`
18
19 `mkosi [options…] boot [nspawn settings…]`
20
21 `mkosi [options…] vm [vmm parameters…]`
22
23 `mkosi [options…] ssh [command line…]`
24
25 `mkosi [options…] journalctl [command line…]`
26
27 `mkosi [options…] coredumpctl [command line…]`
28
29 `mkosi [options…] sysupdate [command line…]`
30
31 `mkosi [options…] sandbox [command line …]`
32
33 `mkosi [options…] clean`
34
35 `mkosi [options…] serve`
36
37 `mkosi [options…] burn <device>`
38
39 `mkosi [options…] bump`
40
41 `mkosi [options…] genkey`
42
43 `mkosi [options…] documentation [manual]`
44
45 `mkosi [options…] completion [shell]`
46
47 `mkosi [options…] dependencies`
48
49 `mkosi [options…] help`
50
51 # DESCRIPTION
52
53 **mkosi** is a tool for easily building customized OS images. It's a fancy wrapper around **dnf**, **apt**,
54 **pacman** and **zypper** that may generate disk images with a number of bells and whistles.
55
56 ## Command Line Verbs
57
58 The following command line verbs are known:
59
60 `summary`
61 : Show a human-readable summary of all options used for building the images.
62 This will parse the command line and configuration files, but only print
63 what it is configured for and not actually build or run anything.
64
65 `cat-config`
66 : Output the names and contents of all loaded configuration files. **mkosi**
67 loads a bunch of files from different locations and this command makes
68 it easier to figure out what is configured where.
69
70 `build`
71 : Build the image-based on the settings passed on the command line and in the
72 configuration files. This command is the default if no verb is specified.
73 Any command line arguments specified after the verb will be passed directly
74 to the build script, if one is defined.
75
76 `shell`
77 : This builds the image if it is not built yet, and then invokes
78 **systemd-nspawn** to run an interactive shell in the image. This doesn't
79 require booting the system, it's like a better chroot. An optional command
80 line may be specified after the `shell` verb, to be invoked in place of the
81 shell in the container. Use `-f` in order to rebuild the image
82 unconditionally before acquiring the shell, see below. This command must be
83 executed as `root`.
84
85 `boot`
86 : Similar to `shell`, but instead of spawning a shell, it boots systemd in the
87 image using **systemd-nspawn**. An optional command line may be specified after
88 the `boot` verb, which can contain extra nspawn options as well as arguments
89 which are passed as the *kernel command line* to the init system in the image.
90
91 `vm`
92 : Similar to `boot`, but uses the configured virtual machine monitor (by
93 default `qemu`) to boot up the image, i.e. instead of container
94 virtualization, virtual machine virtualization is used. How extra
95 command line arguments are interpreted depends on the configured
96 virtual machine monitor. See `VirtualMachineMonitor=` for more
97 information.
98
99 `ssh`
100 : When the image is built with the `Ssh=yes` option, this command
101 connects to a booted virtual machine via SSH. Make sure to run `mkosi ssh`
102 with the same config as `mkosi build` so that it has
103 the necessary information available to connect to the running virtual
104 machine via SSH. Specifically, the SSH private key from the `SshKey=`
105 setting is used to connect to the virtual machine. Use `mkosi genkey`
106 to automatically generate a key and certificate that will be picked up
107 by **mkosi**. Any arguments passed after the `ssh` verb are passed as
108 arguments to the **ssh** invocation. To connect to a container, use
109 `machinectl login` or `machinectl shell`.
110
111 The `Machine=` option can be used to give the machine a custom
112 hostname when booting it which can later be used to **ssh** into the image
113 (e.g. `mkosi --machine=mymachine vm` followed by
114 `mkosi --machine=mymachine ssh`).
115
116 `journalctl`
117 : Uses **journalctl** to inspect the journal inside the image.
118 Any arguments specified after the **journalctl** verb are appended to the
119 **journalctl** invocation.
120
121 `coredumpctl`
122 : Uses **coredumpctl** to look for coredumps inside the image.
123 Any arguments specified after the **coredumpctl** verb are appended to the
124 **coredumpctl** invocation.
125
126 `sysupdate`
127 : Invokes **systemd-sysupdate** with the `--transfer-source=` option set
128 to the output directory and the `--definitions=` option set to the
129 directory configured with `SysupdateDirectory=`. Any arguments
130 specified after the `sysupdate` verb are passed directly to
131 **systemd-sysupdate** invocation.
132
133 `sandbox`
134 : Run arbitrary commands inside of the same sandbox used to execute
135 other verbs such as `boot`, `shell`, `vm` and more. This means
136 `/usr` will be replaced by `/usr` from the tools tree if one is used
137 while everything else will remain in place. If no command is provided,
138 `$SHELL` will be executed or **bash** if `$SHELL` is not set.
139
140 `clean`
141 : Remove build artifacts generated on a previous build. If combined
142 with `-f`, also removes incremental build cache images. If `-f` is
143 specified twice, also removes any package cache.
144
145 `serve`
146 : This builds the image if it is not built yet, and then serves the
147 output directory (i.e. usually `mkosi.output/`, see below) via a
148 small embedded HTTP server, listening on port 8081. Combine with
149 `-f` in order to rebuild the image unconditionally before serving
150 it. This command is useful for testing network-based acquisition of
151 OS images, for example via `machinectl pull-raw …` and `machinectl
152 pull-tar …`.
153
154 `burn <device>`
155 : This builds the image if it is not built yet, and then writes it to the
156 specified block device. The partition contents are written as-is, but the GPT
157 partition table is corrected to match sector and disk size of the specified
158 medium.
159
160 `bump`
161 : Bumps the image version from `mkosi.version` and writes the resulting
162 version string to `mkosi.version`. This is useful for implementing a
163 simple versioning scheme: each time this verb is called the version is
164 bumped in preparation for the subsequent build. Note that
165 `--auto-bump`/`-B` may be used to automatically bump the version
166 after each successful build.
167
168 `genkey`
169 : Generate a pair of SecureBoot keys for usage with the
170 `SecureBootKey=`/`--secure-boot-key=` and
171 `SecureBootCertificate=`/`--secure-boot-certificate=` options.
172
173 `documentation`
174 : Show **mkosi**'s documentation. If no argument is given, the **mkosi** man page is shown, but the arguments
175 `mkosi`, `mkosi-initrd`, `initrd`, `mkosi-sandbox`, `sandbox`, `mkosi.news` and `news` are supported and
176 respectively show the man pages for **mkosi**, **mkosi-initrd**, **mkosi-sandbox** and **mkosi**'s NEWS file.
177
178 By default this verb will try several ways to output the documentation, but a specific option can be
179 chosen with the `--doc-format` option. Distro packagers are encouraged to add a file `mkosi.1` into the
180 `mkosi/resources` directory of the Python package, if it is missing, as well as to install it in the
181 appropriate search path for man pages. The man page can be generated from the markdown file
182 `mkosi/resources/man/mkosi.1.md` e.g via `pandoc -t man -s -o mkosi.1 mkosi.1.md`.
183
184 `completion`
185 : Generate shell completion for the shell given as argument and print it to stdout. The arguments `bash`,
186 `fish`, and `zsh` are understood.
187
188 `dependencies`
189 : Output the list of packages required by **mkosi** to build and boot
190 images.
191
192 This list can be piped directly to a package manager to install the
193 packages. For example, if the host system uses the **dnf** package
194 manager, the packages could be installed as follows:
195
196 ```sh
197 mkosi dependencies | xargs -d '\n' dnf install
198 ```
199
200 `help`
201 : This verb is equivalent to the `--help` switch documented below: it
202 shows a brief usage explanation.
203
204 ## Commandline-only Options
205
206 Those settings cannot be configured in the configuration files.
207
208 `--force`, `-f`
209 : Replace the output file if it already exists, when building an
210 image. By default when building an image and an output artifact
211 already exists **mkosi** will refuse operation. Specify this option
212 once to delete all build artifacts from a previous run before
213 re-building the image. If incremental builds are enabled,
214 specifying this option twice will ensure the intermediary
215 cache files are removed, too, before the re-build is initiated. If a
216 package cache is used (also see the **Files** section below),
217 specifying this option thrice will ensure the package cache is
218 removed too, before the re-build is initiated. For the `clean`
219 operation this option has a slightly different effect: by default
220 the verb will only remove build artifacts from a previous run, when
221 specified once the incremental cache files are deleted too, and when
222 specified twice the package cache is also removed.
223
224 `--directory=`, `-C`
225 : Takes a path to a directory. **mkosi** switches to this directory before
226 doing anything. Note that the various configuration files are searched
227 for in this directory, hence using this option is an effective way to
228 build a project located in a specific directory.
229
230 `--debug`
231 : Enable additional debugging output.
232
233 `--debug-shell`
234 : When executing a command in the image fails, **mkosi** will start an interactive
235 shell in the image allowing further debugging.
236
237 `--debug-workspace`
238 : When specified, the workspace directory will not be deleted and its
239 location will be logged when **mkosi** exits.
240
241 `--debug-sandbox`
242 : Run **mkosi-sandbox** with **strace**.
243
244 `--version`
245 : Show package version.
246
247 `--help`, `-h`
248 : Show brief usage information.
249
250 `--genkey-common-name=`
251 : Common name to be used when generating keys via **mkosi**'s `genkey` command. Defaults to `mkosi of %u`, where
252 `%u` expands to the username of the user invoking **mkosi**.
253
254 `--genkey-valid-days=`
255 : Number of days that the keys should remain valid when generating keys via **mkosi**'s `genkey` command.
256 Defaults to two years (730 days).
257
258 `--auto-bump=`, `-B`
259 : If specified, after each successful build the version is bumped in a
260 fashion equivalent to the `bump` verb, in preparation for the next
261 build. This is useful for simple, linear version management: each
262 build in a series will have a version number one higher then the
263 previous one.
264
265 `--doc-format`
266 : The format to show the documentation in. Supports the values `markdown`,
267 `man`, `pandoc`, `system` and `auto`. In the case of `markdown` the
268 documentation is shown in the original Markdown format. `man` shows the
269 documentation in man page format, if it is available. **pandoc** will generate
270 the man page format on the fly, if **pandoc** is available. `system` will show
271 the system-wide man page for **mkosi**, which may or may not correspond to the
272 version you are using, depending on how you installed **mkosi**. `auto`, which is
273 the default, will try all methods in the order `man`, `pandoc`, `markdown`,
274 `system`.
275
276 `--json`
277 : Show the summary output as JSON-SEQ.
278
279 `--wipe-build-dir`, `-w`
280 : Wipe the build directory if one is configured before building the image.
281
282 ## Supported output formats
283
284 The following output formats are supported:
285
286 * Raw *GPT* disk image, created using **systemd-repart** (*disk*)
287 * Plain directory, containing the OS tree (*directory*)
288 * Tar archive (*tar*)
289 * CPIO archive (*cpio*)
290
291 The output format may also be set to *none* to have **mkosi** produce no
292 image at all. This can be useful if you only want to use the image to
293 produce another output in the build scripts (e.g. build an RPM).
294
295 When a *GPT* disk image is created, repart partition definition files
296 may be placed in `mkosi.repart/` to configure the generated disk image.
297
298 It is highly recommended to run **mkosi** on a file system that supports reflinks
299 such as XFS and btrfs and to keep all related directories on the same file
300 system. This allows **mkosi** to create images very quickly by using reflinks to
301 perform copying via copy-on-write operations.
302
303 ## Configuration Settings
304
305 The following settings can be set through configuration files (the
306 syntax with `SomeSetting=value`) and on the command line (the syntax
307 with `--some-setting=value`). For some command line parameters, a
308 single-letter shortcut is also allowed. In the configuration files,
309 the setting must be in the appropriate section, so the settings are
310 grouped by section below.
311
312 Configuration is parsed in the following order:
313
314 * The command line arguments are parsed.
315 * `mkosi.local.conf` or `mkosi.local` is parsed if it exists. This file or
316 directory should be in `.gitignore` (or equivalent) and is intended for local
317 configuration.
318 * Any default paths (depending on the option) are configured if the
319 corresponding path exists.
320 * `mkosi.conf` is parsed if it exists in the directory configured with
321 `--directory=` or the current working directory if `--directory=` is
322 not used.
323 * `mkosi.conf.d/` is parsed in the same directory if it exists. Each
324 directory and each file with the `.conf` extension in `mkosi.conf.d/`
325 is parsed. Any directory in `mkosi.conf.d` is parsed as if it were
326 a regular top level directory.
327 * If any profiles are configured, their configuration is parsed from the
328 `mkosi.profiles/` directory.
329 * Subimages are parsed from the `mkosi.images` directory if it exists.
330
331 Note that settings configured via the command line always override
332 settings configured via configuration files. If the same setting is
333 configured more than once via configuration files, later assignments
334 override earlier assignments except for settings that take a collection
335 of values. Also, settings read from `mkosi.local` or `mkosi.local.conf` will
336 override settings from configuration files that are parsed later, but not
337 settings specified on the CLI.
338
339 For settings that take a single value, the empty assignment (`SomeSetting=` or
340 `--some-setting=`) can be used to override a previous setting and reset to the
341 default.
342
343 Settings that take a collection of values are merged by appending the
344 new values to the previously configured values. Assigning the empty
345 string to such a setting removes all previously assigned values, and
346 overrides any configured default values as well. The values specified
347 on the CLI are appended after all the values from configuration files.
348
349 To conditionally include configuration files, the `[Match]` section can
350 be used. A `[Match]` section consists of individual conditions.
351 Conditions can use a pipe symbol (`|`) after the equals sign (`…=|…`),
352 which causes the condition to become a triggering condition. The config
353 file will be included if the logical AND of all non-triggering
354 conditions and the logical OR of all triggering conditions is satisfied.
355 To negate the result of a condition, prefix the argument with an
356 exclamation mark. If an argument is prefixed with the pipe symbol and an
357 exclamation mark, the pipe symbol must be passed first, and the
358 exclamation second.
359
360 Note that `[Match]` conditions compare against the current values of
361 specific settings, and do not take into account changes made to the
362 setting in configuration files that have not been parsed yet (settings
363 specified on the CLI are taken into account). Also note that matching
364 against a setting and then changing its value afterwards in a different
365 config file may lead to unexpected results.
366
367 The `[Match]` section of a `mkosi.conf` file in a directory applies to
368 the entire directory. If the conditions are not satisfied, the entire
369 directory is skipped. The `[Match]` sections of files in `mkosi.conf.d/`
370 and `mkosi.local.conf` only apply to the file itself.
371
372 If there are multiple `[Match]` sections in the same configuration file,
373 each of them has to be satisfied in order for the configuration file to
374 be included. Specifically, triggering conditions only apply to the
375 current `[Match]` section and are reset between multiple `[Match]`
376 sections. As an example, the following will only match if the output
377 format is one of `disk` or `directory` and the architecture is one of
378 `x86-64` or `arm64`:
379
380 ```ini
381 [Match]
382 Format=|disk
383 Format=|directory
384
385 [Match]
386 Architecture=|x86-64
387 Architecture=|arm64
388 ```
389
390 The `[TriggerMatch]` section can be used to indicate triggering match
391 sections. These are identical to triggering conditions except they apply
392 to the entire match section instead of just a single condition. As an
393 example, the following will match if the distribution is `debian` and
394 the release is `bookworm` or if the distribution is `ubuntu` and the
395 release is `noble`.
396
397 ```ini
398 [TriggerMatch]
399 Distribution=debian
400 Release=bookworm
401
402 [TriggerMatch]
403 Distribution=ubuntu
404 Release=noble
405 ```
406
407 The semantics of conditions in `[TriggerMatch]` sections is the same as
408 in `[Match]`, i.e. all normal conditions are joined by a logical AND and
409 all triggering conditions are joined by a logical OR. When mixing
410 `[Match]` and `[TriggerMatch]` sections, a match is achieved when all
411 `[Match]` sections match and at least one `[TriggerMatch]` section
412 matches. The absence of match sections is valued as true. Logically this means:
413
414 ```
415 (⋀ᵢ Matchᵢ) ∧ (⋁ᵢ TriggerMatchᵢ)
416 ```
417
418 Command line options that take no argument are shown without `=` in
419 their long version. In the config files, they should be specified with a
420 boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
421 `false` to disable.
422
423 ### [Distribution] Section
424
425 `Distribution=`, `--distribution=`, `-d`
426 : The distribution to install in the image. Takes one of the following
427 arguments: `fedora`, `debian`, `kali`, `ubuntu`, `arch`, `opensuse`,
428 `mageia`, `centos`, `rhel`, `rhel-ubi`, `openmandriva`, `rocky`, `alma`,
429 `azure` or `custom`. If not specified, defaults to the distribution of
430 the host or `custom` if the distribution of the host is not a supported
431 distribution.
432
433 `Release=`, `--release=`, `-r`
434 : The release of the distribution to install in the image. The precise
435 syntax of the argument this takes depends on the distribution used,
436 and is either a numeric string (in case of Fedora Linux, CentOS, …,
437 e.g. `29`), or a distribution version name (in case of Debian, Kali,
438 Ubuntu, …, e.g. `artful`). Defaults to a recent version of the chosen
439 distribution, or the version of the distribution running on the host
440 if it matches the configured distribution.
441
442 `Architecture=`, `--architecture=`
443 : The architecture to build the image for. The architectures that are
444 actually supported depends on the distribution used and whether a
445 bootable image is requested or not. When building for a foreign
446 architecture, you'll also need to install and register a user mode
447 emulator for that architecture.
448
449 One of the following architectures can be specified per image built:
450 `alpha`, `arc`, `arm`, `arm64`, `ia64`, `loongarch64`, `mips64-le`,
451 `mips-le`, `parisc`, `ppc`, `ppc64`, `ppc64-le`, `riscv32`, `riscv64`,
452 `s390`, `s390x`, `tilegx`, `x86`, `x86-64`.
453
454 `Mirror=`, `--mirror=`, `-m`
455 : The mirror to use for downloading the distribution packages. Expects
456 a mirror URL as argument. If not provided, the default mirror for the
457 distribution is used.
458
459 The default mirrors for each distribution are as follows (unless
460 specified, the same mirror is used for all architectures):
461
462 | | x86-64 | aarch64 |
463 |----------------|-----------------------------------|--------------------------------|
464 | `debian` | http://deb.debian.org/debian | |
465 | `arch` | https://geo.mirror.pkgbuild.com | http://mirror.archlinuxarm.org |
466 | `opensuse` | http://download.opensuse.org | |
467 | `kali` | http://http.kali.org/kali | |
468 | `ubuntu` | http://archive.ubuntu.com | http://ports.ubuntu.com |
469 | `centos` | https://mirrors.centos.org | |
470 | `rocky` | https://mirrors.rockylinux.org | |
471 | `alma` | https://mirrors.almalinux.org | |
472 | `fedora` | https://mirrors.fedoraproject.org | |
473 | `rhel-ubi` | https://cdn-ubi.redhat.com | |
474 | `mageia` | https://www.mageia.org | |
475 | `openmandriva` | http://mirrors.openmandriva.org | |
476 | `azure` | https://packages.microsoft.com/ | |
477
478 `LocalMirror=`, `--local-mirror=`
479 : The mirror will be used as a local, plain and direct mirror instead
480 of using it as a prefix for the full set of repositories normally supported
481 by distributions. Useful for fully offline builds with a single repository.
482 Supported on **deb**-, **rpm**-, and **pacman**-based distributions. Overrides `--mirror=` but only
483 for the local **mkosi** build, it will not be configured inside the final image,
484 `--mirror=` (or the default repository) will be configured inside the final
485 image instead.
486
487 `RepositoryKeyCheck=`, `--repository-key-check=`
488 : Controls signature/key checks when using repositories, enabled by default.
489 Useful to disable checks when combined with `--local-mirror=` and using only
490 a repository from a local filesystem.
491
492 `RepositoryKeyFetch=`, `--repository-key-fetch=`
493 : Controls whether **mkosi** will fetch distribution GPG keys remotely. Enabled by
494 default on Ubuntu when not using a tools tree or when using Ubuntu tools trees to build
495 Arch Linux or RPM-based distributions. Disabled by default on all other distributions.
496 When disabled, the distribution GPG keys for the target distribution have to be installed
497 locally on the host system alongside the package manager for that distribution.
498
499 This setting is only implemented for distributions using **dnf**, **pacman** or **zypper**
500 as their package manager. For other distributions the distribution GPG keys are always looked
501 up locally regardless of the value of this setting. To make the distribution GPG keys
502 for distributions available without enabling this setting, the corresponding package
503 has to be installed on the host. This is usually one of `archlinux-keyring`,
504 `debian-keyring`, `kali-archive-keyring`, `ubuntu-keyring` or `distribution-gpg-keys`
505 (for RPM-based distributions).
506
507 `Repositories=`, `--repositories=`
508 : Enable package repositories that are disabled by default. This can be used to enable the EPEL repos for
509 CentOS or different components of the Debian/Kali/Ubuntu repositories.
510
511 ### [Output] Section
512
513 `Format=`, `--format=`, `-t`
514 : The image format type to generate. One of `directory` (for generating
515 an OS image directly in a local directory), `tar` (similar, but a
516 tarball of the OS image is generated), `cpio` (similar, but a cpio
517 archive is generated), `disk` (a block device OS image with a GPT
518 partition table), `uki` (a unified kernel image with the OS image in
519 the `.initrd` PE section), `esp` (`uki` but wrapped in a disk image
520 with only an ESP partition), `oci` (a directory compatible with the
521 OCI image specification), `sysext`, `confext`, `portable`,
522 `addon` or `none` (the OS image is solely intended as a build
523 image to produce another artifact).
524
525 If the `disk` output format is used, the disk image is generated using
526 **systemd-repart**. The repart partition definition files to use can be
527 configured using the `RepartDirectories=` setting or via
528 `mkosi.repart/`. When verity partitions are configured using
529 **systemd-repart**'s `Verity=` setting, **mkosi** will automatically parse the
530 verity hash partition's roothash from **systemd-repart**'s JSON output and
531 include it in the kernel command line of every unified kernel image
532 built by **mkosi**.
533
534 If the `none` output format is used, the outputs from a previous
535 build are not removed, but clean scripts (see `CleanScripts=`) are
536 still executed. This allows rerunning a build script
537 (see `BuildScripts=`) without removing the results of a previous
538 build.
539
540 `ManifestFormat=`, `--manifest-format=`
541 : The manifest format type or types to generate. A comma-delimited
542 list consisting of `json` (the standard JSON output format that
543 describes the packages installed), `changelog` (a human-readable
544 text format designed for diffing). By default no manifest is
545 generated.
546
547 `Output=`, `--output=`, `-o`
548 : Name to use for the generated output image file or directory. Defaults
549 to `image` or, if `ImageId=` is specified, it is used as the default
550 output name, optionally suffixed with the version set with
551 `ImageVersion=` or if a specific image is built from `mkosi.images`, the
552 name of the image is preferred over `ImageId`. Note that this option does
553 not allow configuring the output directory, use `OutputDirectory=` for that.
554
555 Note that this only specifies the output prefix, depending on the
556 specific output format, compression and image version used, the full
557 output name might be `image_7.8.raw.xz`.
558
559 `CompressOutput=`, `--compress-output=`
560 : Configure compression for the resulting image or archive. The argument can be
561 either a boolean or a compression algorithm (**xz**, **zstd**). **zstd**
562 compression is used by default, except CentOS and derivatives up to version
563 8, which default to **xz**, and OCI images, which default to **gzip**.
564 Note that when applied to block device image types,
565 compression means the image cannot be started directly but needs to be
566 decompressed first. This also means that the `shell`, `boot`, `vm` verbs
567 are not available when this option is used. Implied for `tar`, `cpio`, `uki`,
568 `esp`, `oci` and `addon`.
569
570 `CompressLevel=`, `--compress-level=`
571 : Configure the compression level to use. Takes an integer. The possible
572 values depend on the compression being used.
573
574 `OutputDirectory=`, `--output-directory=`, `-O`
575 : Path to a directory where to place all generated artifacts. If this is
576 not specified and the directory `mkosi.output/` exists in the local
577 directory, it is automatically used for this purpose.
578
579 `OutputMode=`, `--output-mode=`
580 : File system access mode used when creating the output image file. Takes an
581 access mode in octal notation. If not set, uses the current system defaults.
582
583 `ImageVersion=`, `--image-version=`
584 : Configure the image version. This accepts any string, but it is
585 recommended to specify a series of dot separated components. The
586 version may also be configured by reading a `mkosi.version` file (in
587 which case it may be conveniently managed via the `bump` verb or the
588 `--auto-bump` option) or by reading stdout if it is executable (see
589 the **Scripts** section below). When specified the image version is
590 included in the default output file name, i.e. instead of `image.raw`
591 the default will be `image_0.1.raw` for version `0.1` of the image,
592 and similar. The version is also passed via the `$IMAGE_VERSION` to
593 any build scripts invoked (which may be useful to patch it into
594 `/usr/lib/os-release` or similar, in particular the `IMAGE_VERSION=`
595 field of it).
596
597 `ImageId=`, `--image-id=`
598 : Configure the image identifier. This accepts a freeform string that
599 shall be used to identify the image with. If set the default output
600 file will be named after it (possibly suffixed with the version). The
601 identifier is also passed via the `$IMAGE_ID` to any build scripts
602 invoked. The image ID is automatically added to `/usr/lib/os-release`.
603
604 `SplitArtifacts=`, `--split-artifacts`
605 : The artifact types to split out of the final image. A comma-delimited
606 list consisting of `uki`, `kernel`, `initrd` and `partitions`. When
607 building a bootable image `kernel` and `initrd` correspond to their
608 artifact found in the image (or in the UKI), while `uki` copies out the
609 entire UKI.
610
611 When building a disk image and `partitions` is specified,
612 pass `--split=yes` to **systemd-repart** to have it write out split partition
613 files for each configured partition. Read the
614 [man](https://www.freedesktop.org/software/systemd/man/systemd-repart.html#--split=BOOL)
615 page for more information. This is useful in A/B update scenarios where
616 an existing disk image shall be augmented with a new version of a
617 root or `/usr` partition along with its Verity partition and unified
618 kernel. By default `uki`, `kernel` and `initrd` are split out.
619
620 `RepartDirectories=`, `--repart-directory=`
621 : Paths to directories containing **systemd-repart** partition definition
622 files that are used when **mkosi** invokes **systemd-repart** when building a
623 disk image. If `mkosi.repart/` exists in the local directory, it will
624 be used for this purpose as well. Note that **mkosi** invokes repart with
625 `--root=` set to the root of the image root, so any `CopyFiles=`
626 source paths in partition definition files will be relative to the
627 image root directory.
628
629 `SectorSize=`, `--sector-size=`
630 : Override the default sector size that **systemd-repart** uses when building a disk
631 image.
632
633 `Overlay=`, `--overlay`
634 : When used together with `BaseTrees=`, the output will consist only out of
635 changes to the specified base trees. Each base tree is attached as a lower
636 layer in an overlayfs structure, and the output becomes the upper layer,
637 initially empty. Thus files that are not modified compared to the base trees
638 will not be present in the final output.
639
640 This option may be used to create [systemd *system extensions* or
641 *portable services*](https://uapi-group.org/specifications/specs/extension_image).
642
643 `Seed=`, `--seed=`
644 : Takes a UUID as argument or the special value `random`.
645 Overrides the seed that **systemd-repart**
646 uses when building a disk image. This is useful to achieve reproducible
647 builds, where deterministic UUIDs and other partition metadata should be
648 derived on each build. If not specified explicitly and the file `mkosi.seed`
649 exists in the local directory, the UUID to use is read from it. Otherwise,
650 a random UUID is used.
651
652 `CleanScripts=`, `--clean-script=`
653 : Takes a comma-separated list of paths to executables that are used as
654 the clean scripts for this image. See the **Scripts** section for
655 more information.
656
657 ### [Content] Section
658
659 `Packages=`, `--package=`, `-p`
660 : Install the specified distribution packages (i.e. RPM, deb, …) in the
661 image. Takes a comma-separated list of package specifications. This
662 option may be used multiple times in which case the specified package
663 lists are combined. Use `BuildPackages=` to specify packages that
664 shall only be installed in an overlay that is mounted when the prepare
665 scripts are executed with the `build` argument and when the build scripts
666 are executed.
667
668 The types and syntax of *package specifications* that are allowed
669 depend on the package installer (e.g. **dnf** for RPM-based distros or
670 **apt** for deb-based distros), but may include package names, package
671 names with version and/or architecture, package name globs, package
672 groups, and virtual provides, including file paths.
673
674 See `PackageDirectories=` for information on how to make local
675 packages available for installation with `Packages=`.
676
677 **Example**: when using a distro that uses **dnf**, the following configuration
678 would install the **meson** package (in the latest version), the 32-bit version
679 of the `libfdisk-devel` package, all available packages that start with the
680 `git-` prefix, a **systemd** RPM from the local file system, one of the
681 packages that provides `/usr/bin/ld`, the packages in the *Development Tools*
682 group, and the package that contains the `mypy` python module.
683
684 ```ini
685 Packages=meson
686 libfdisk-devel.i686
687 git-*
688 /usr/bin/ld
689 @development-tools
690 python3dist(mypy)
691 ```
692
693 `BuildPackages=`, `--build-package=`
694 : Similar to `Packages=`, but configures packages to install only in an
695 overlay that is made available on top of the image to the prepare
696 scripts when executed with the `build` argument and the build scripts.
697 This option should be used to list packages containing header files,
698 compilers, build systems, linkers and other build tools the
699 `mkosi.build` scripts require to operate. Note that packages listed
700 here will be absent in the final image.
701
702 `VolatilePackages=`, `--volatile-package=`
703 : Similar to `Packages=`, but packages configured with this setting are
704 not cached when `Incremental=` is enabled and are installed after
705 executing any build scripts.
706
707 Specifically, this setting can be used to install packages that change
708 often or which are built by a build script.
709
710 `PackageDirectories=`, `--package-directory=`
711 : Specify directories containing extra packages to be made available during
712 the build. **mkosi** will create a local repository containing all
713 packages in these directories and make it available when installing packages or
714 running scripts. If the `mkosi.packages/` directory is found in the local
715 directory it is also used for this purpose.
716
717 `VolatilePackageDirectories=`, `--volatile-package-directory=`
718
719 : Like `PackageDirectories=`, but any changes to the packages in these
720 directories will not invalidate the cached images if `Incremental=`
721 is enabled.
722
723 Additionally, build scripts can add more packages to the local
724 repository by placing the built packages in `$PACKAGEDIR`. The
725 packages placed in `$PACKAGEDIR` are shared between all image builds
726 and thus available for installation in all images using
727 `VolatilePackages=`.
728
729 `WithRecommends=`, `--with-recommends=`
730 : Configures whether to install recommended or weak dependencies,
731 depending on how they are named by the used package manager, or not.
732 By default, recommended packages are not installed. This is only used
733 for package managers that support the concept, which are currently
734 **apt**, **dnf** and **zypper**.
735
736 `WithDocs=`, `--with-docs`
737 : Include documentation in the image. Enabled by default. When disabled,
738 if the underlying distribution package manager supports it
739 documentation is not included in the image. The `$WITH_DOCS`
740 environment variable passed to the `mkosi.build` scripts is set to `0`
741 or `1` depending on whether this option is enabled or disabled.
742
743 `BaseTrees=`, `--base-tree=`
744 : Takes a comma-separated list of paths to use as base trees. When used,
745 these base trees are each copied into the OS tree and form the base
746 distribution instead of installing the distribution from scratch. Only
747 extra packages are installed on top of the ones already installed in
748 the base trees. Note that for this to work properly, the base image
749 still needs to contain the package manager metadata by setting
750 `CleanPackageMetadata=no` (see `CleanPackageMetadata=`).
751
752 Instead of a directory, a tar file or a disk image may be provided. In
753 this case it is unpacked into the OS tree. This mode of operation
754 allows setting permissions and file ownership explicitly, in
755 particular for projects stored in a version control system such as
756 **git** which retain full file ownership and access mode metadata for
757 committed files.
758
759 `SkeletonTrees=`, `--skeleton-tree=`
760 : Takes a comma-separated list of colon-separated path pairs. The first
761 path of each pair refers to a directory to copy into the OS tree
762 before invoking the package manager. The second path of each pair
763 refers to the target directory inside the image. If the second path is
764 not provided, the directory is copied on top of the root directory of
765 the image. The second path is always interpreted as an absolute path.
766 Use this to insert files and directories into the OS tree before the
767 package manager installs any packages. If the `mkosi.skeleton/`
768 directory is found in the local directory it is also used for this
769 purpose with the root directory as target (also see the **Files**
770 section below).
771
772 Note that skeleton trees are cached and any changes to skeleton trees
773 after a cached image has been built (when using `Incremental=`) are
774 only applied when the cached image is rebuilt (by using `-ff` or
775 running `mkosi -f clean`).
776
777 As with the base tree logic above, instead of a directory, a tar
778 file may be provided too. `mkosi.skeleton.tar` will be automatically
779 used if found in the local directory.
780
781 To add extra package manager configuration files such as extra
782 repositories, use `SandboxTrees=` as **mkosi** invokes the package
783 managers from outside the image and not inside so any package
784 manager configuration files provided via `SkeletonTrees=` won't
785 take effect when **mkosi** invokes a package manager to install
786 packages.
787
788 `ExtraTrees=`, `--extra-tree=`
789 : Takes a comma-separated list of colon-separated path pairs. The first
790 path of each pair refers to a directory to copy from the host into the
791 image. The second path of each pair refers to the target directory
792 inside the image. If the second path is not provided, the directory is
793 copied on top of the root directory of the image. The second path is
794 always interpreted as an absolute path. Use this to override any
795 default configuration files shipped with the distribution. If the
796 `mkosi.extra/` directory is found in the local directory it is also
797 used for this purpose with the root directory as target (also see the
798 **Files** section below).
799
800 As with the base tree logic above, instead of a directory, a tar
801 file may be provided too. `mkosi.extra.tar` will be automatically
802 used if found in the local directory.
803
804 `RemovePackages=`, `--remove-package=`
805 : Takes a comma-separated list of package specifications for removal, in
806 the same format as `Packages=`. The removal will be performed as one
807 of the last steps. This step is skipped if `CleanPackageMetadata=no`
808 is used.
809
810 `RemoveFiles=`, `--remove-files=`
811 : Takes a comma-separated list of globs. Files in the image matching
812 the globs will be purged at the end.
813
814 `CleanPackageMetadata=`, `--clean-package-metadata=`
815 : Enable/disable removal of package manager databases and repository
816 metadata at the end of installation. Can be specified as `true`,
817 `false`, or `auto` (the default). With `auto`, package manager
818 databases and repository metadata will be removed if the respective
819 package manager executable is *not* present at the end of the
820 installation.
821
822 `SourceDateEpoch=`, `--source-date-epoch=`
823 : Takes a timestamp in seconds since the UNIX epoch as argument.
824 File modification times of all files will be clamped to this value.
825 The variable is also propagated to **systemd-repart** and
826 scripts executed by **mkosi**. If not set explicitly, `SOURCE_DATE_EPOCH` from
827 `--environment` and from the host environment are tried in that order.
828 This is useful to make builds reproducible. See
829 [SOURCE_DATE_EPOCH](https://reproducible-builds.org/specs/source-date-epoch/)
830 for more information.
831
832 `SyncScripts=`, `--sync-script=`
833 : Takes a comma-separated list of paths to executables that are used as
834 the sync scripts for this image. See the **Scripts** section for
835 more information.
836
837 `PrepareScripts=`, `--prepare-script=`
838 : Takes a comma-separated list of paths to executables that are used as
839 the prepare scripts for this image. See the **Scripts** section for
840 more information.
841
842 `BuildScripts=`, `--build-script=`
843 : Takes a comma-separated list of paths to executables that are used as
844 the build scripts for this image. See the **Scripts** section for more
845 information.
846
847 `PostInstallationScripts=`, `--postinst-script=`
848 : Takes a comma-separated list of paths to executables that are used as
849 the post-installation scripts for this image. See the **Scripts** section
850 for more information.
851
852 `FinalizeScripts=`, `--finalize-script=`
853 : Takes a comma-separated list of paths to executables that are used as
854 the finalize scripts for this image. See the **Scripts** section for more
855 information.
856
857 `PostOutputScripts=`, `--postoutput-script`
858 : Takes a comma-separated list of paths to executables that are used as
859 the post output scripts for this image. See the **Scripts** section for more
860 information.
861
862 `Bootable=`, `--bootable=`
863 : Takes a boolean or `auto`. Enables or disables generation of a
864 bootable image. If enabled, **mkosi** will install an EFI bootloader, and
865 add an ESP partition when the disk image output is used. If the
866 selected EFI bootloader (see `Bootloader=`) is not installed or no
867 kernel images can be found, the build will fail. `auto` behaves as if
868 the option was enabled, but the build won't fail if either no kernel
869 images or the selected EFI bootloader can't be found. If disabled, no
870 bootloader will be installed even if found inside the image, no
871 unified kernel images will be generated and no ESP partition will be
872 added to the image if the disk output format is used.
873
874 `Bootloader=`, `--bootloader=`
875 : Takes one of `none`, `systemd-boot`, `uki`, `grub`,
876 `systemd-boot-signed`, `uki-signed` or `grub-signed`. Defaults to
877 `systemd-boot`. If set to `none`, no EFI bootloader will be installed
878 into the image. If set to `systemd-boot`, **systemd-boot** will be
879 installed and for each installed kernel, a UKI will be generated and
880 stored in `EFI/Linux` in the ESP. If set to `uki`, a single UKI will
881 be generated for the latest installed kernel (the one with the highest
882 version) which is installed to `EFI/BOOT/BOOTX64.EFI` in the ESP. If
883 set to `grub`, for each installed kernel, a UKI will be generated and
884 stored in `EFI/Linux` in the ESP. For each generated UKI, a menu entry
885 is appended to the grub configuration in `grub/grub.cfg` in the ESP
886 which chainloads into the UKI. A shim grub.cfg is also written to
887 `EFI/<distribution>/grub.cfg` in the ESP which loads `grub/grub.cfg`
888 in the ESP for compatibility with signed versions of grub which load
889 the grub configuration from this location.
890
891 The `signed` variants will only install pre-signed EFI binaries
892 shipped by the distribution.
893
894 Kernels need to be placed into the root filesystem (for example using
895 `ExtraTrees=`) under `/usr/lib/modules/$version`, named `vmlinux` or
896 `vmlinuz`. The `$version` is as produced by Kbuild's `kernelversion` make
897 target.
898
899 `BiosBootloader=`, `--bios-bootloader=`
900 : Takes one of `none` or `grub`. Defaults to `none`. If set to `none`,
901 no BIOS bootloader will be installed. If set to `grub`, grub is
902 installed as the BIOS boot loader if a bootable image is requested
903 with the `Bootable=` option. If no repart partition definition files
904 are configured, **mkosi** will add a grub BIOS boot partition and an EFI
905 system partition to the default partition definition files.
906
907 Note that this option is not mutually exclusive with `Bootloader=`. It
908 is possible to have an image that is both bootable on UEFI and BIOS by
909 configuring both `Bootloader=` and `BiosBootloader=`.
910
911 The grub BIOS boot partition should have UUID
912 `21686148-6449-6e6f-744e-656564454649` and should be at least 1MB.
913
914 Even if no EFI bootloader is installed, we still need an ESP for BIOS
915 boot as that's where we store the kernel, initrd and grub modules.
916
917 `ShimBootloader=`, `--shim-bootloader=`
918 : Takes one of `none`, `unsigned`, or `signed`. Defaults to `none`. If
919 set to `none`, shim and MokManager will not be installed to the ESP.
920 If set to `unsigned`, **mkosi** will search for unsigned shim and
921 MokManager EFI binaries and install them. If `SecureBoot=` is enabled,
922 **mkosi** will sign the unsigned EFI binaries before installing them. If
923 set to `signed`, **mkosi** will search for signed EFI binaries and install
924 those. Even if `SecureBoot=` is enabled, **mkosi** won't sign these
925 binaries again.
926
927 Note that this option only takes effect when an image that is bootable
928 on UEFI firmware is requested using other options
929 (`Bootable=`, `Bootloader=`).
930
931 Note that when this option is enabled, **mkosi** will only install already
932 signed bootloader binaries, kernel image files and unified kernel
933 images as self-signed binaries would not be accepted by the signed
934 version of shim.
935
936 `UnifiedKernelImages=`, `--unified-kernel-images=`
937 : Specifies whether to use unified kernel images or not when
938 `Bootloader=` is set to `systemd-boot` or `grub`. Takes a boolean
939 value or `auto`. Defaults to `auto`. If enabled, unified kernel images
940 are always used and the build will fail if any components required to
941 build unified kernel images are missing. If set to `auto`, unified
942 kernel images will be used if all necessary components are available.
943 Otherwise Type 1 entries as defined by the Boot Loader Specification
944 will be used instead. If disabled, Type 1 entries will always be used.
945
946 `UnifiedKernelImageFormat=`, `--unified-kernel-image-format=`
947 : Takes a filename without any path components to specify the format that
948 unified kernel images should be installed as. This may include both the
949 regular specifiers (see **Specifiers**) and special delayed specifiers, that
950 are expanded during the installation of the files, which are described below.
951 The default format for this parameter is `&e-&k` with `-&h` being appended
952 if `roothash=` or `usrhash=` is found on the kernel command line and `+&c`
953 if `/etc/kernel/tries` is found in the image.
954
955 The following specifiers may be used:
956
957 | Specifier | Value |
958 |-----------|----------------------------------------------------|
959 | `&&` | `&` character |
960 | `&e` | Entry Token |
961 | `&k` | Kernel version |
962 | `&h` | `roothash=` or `usrhash=` value of kernel argument |
963 | `&c` | Number of tries used for boot attempt counting |
964
965 `UnifiedKernelImageProfiles=`, `--uki-profile=`
966 : Build additional UKI profiles. Takes a comma-separated list of paths
967 to UKI profile config files. This option may be used multiple times in
968 which case each config gets built into a corresponding UKI profile.
969 Config files in the `mkosi.uki-profiles/` directory are
970 automatically picked up. All configured UKI profiles are added as
971 additional UKI profiles to each UKI built by **mkosi**.
972
973 See the documentation for the `UKIProfile` section for information
974 on which settings can be configured in UKI profile config files.
975
976 `Initrds=`, `--initrd`
977 : Use user-provided initrd(s). Takes a comma-separated list of paths to initrd
978 files. This option may be used multiple times in which case the initrd lists
979 are combined. If no initrds are specified and a bootable image is requested,
980 **mkosi** will look for initrds in a subdirectory `io.mkosi.initrd` of the
981 artifact directory (see `$ARTIFACTDIR` in the section **ENVIRONMENT
982 VARIABLES**), if none are found there **mkosi** will automatically build a
983 default initrd.
984
985 `InitrdPackages=`, `--initrd-package=`
986 : Extra packages to install into the default initrd. Takes a comma
987 separated list of package specifications. This option may be used
988 multiple times in which case the specified package lists are combined.
989
990 `InitrdVolatilePackages=`, `--initrd-volatile-package=`
991 : Similar to `VolatilePackages=`, except it applies to the default
992 initrd.
993
994 `Devicetree=`, `--devicetree=`
995 : When set, specifies a Devicetree blob to be used by the booting system,
996 instead of the one provided by firmware. **mkosi** will search for the
997 specified file relative to common paths where Linux distributions install
998 Devicetree files. It should typically have the format `<vendor>/<board>.dtb`.
999
1000 `MicrocodeHost=`, `--microcode-host=`
1001 : When set to true only include microcode for the host's CPU in the image.
1002
1003 `KernelCommandLine=`, `--kernel-command-line=`
1004 : Use the specified kernel command line when building images.
1005
1006 If the root or usr partition are created with verity enabled,
1007 `roothash=` or `usrhash=` respectively are automatically added to the
1008 kernel command line and `root=` or `mount.usr=` should not be added.
1009 Otherwise, if the value of this setting contains the literals
1010 `root=PARTUUID` or `mount.usr=PARTUUID`, these are replaced with the
1011 partition UUID of the root or usr partition respectively. For
1012 example, `root=PARTUUID` would be replaced with
1013 `root=PARTUUID=58c7d0b2-d224-4834-a16f-e036322e88f7` where
1014 `58c7d0b2-d224-4834-a16f-e036322e88f7` is the partition UUID of the
1015 root partition.
1016
1017 `KernelModulesInclude=`, `--kernel-modules-include=`
1018 : Takes a list of regex patterns that specify kernel modules to include in the image. Patterns should be
1019 relative to `/usr/lib/modules/<kver>/<subdir>` paths. **mkosi** checks for a match anywhere in the module path
1020 (e.g. `i915` will match against `drivers/gpu/drm/i915.ko`). All modules that match any of the specified
1021 patterns are included in the image. All module and firmware dependencies of the matched modules are included
1022 in the image as well.
1023
1024 If the special value `default` is used, the default kernel modules
1025 defined in the **mkosi-initrd** configuration are included as well.
1026
1027 If the special value `host` is used, the currently loaded modules on
1028 the host system are included as well.
1029
1030 This setting takes priority over `KernelModulesExclude=` and only makes
1031 sense when used in combination with it because all kernel modules are included in the image by default.
1032
1033 `KernelModulesExclude=`, `--kernel-modules-exclude=`
1034 : Takes a list of regex patterns that specify modules to exclude from the image. Behaves the same as
1035 `KernelModulesInclude=` except that all modules that match any of the specified patterns are excluded from
1036 the image.
1037
1038 `KernelModulesInitrd=`, `--kernel-modules-initrd=`
1039 : Boolean value, enabled (true) by default. If enabled, when building a bootable image, **mkosi** will generate
1040 an extra initrd for each unified kernel image it assembles. This initrd contains only modules for
1041 the specific kernel version, and will be appended to the prebuilt initrd. This allows generating kernel
1042 independent initrds which are augmented with the necessary modules when the UKI is assembled.
1043
1044 `KernelModulesInitrdInclude=`, `--kernel-modules-initrd-include=`
1045 : Like `KernelModulesInclude=`, but applies to the kernel modules included in the kernel modules initrd.
1046
1047 `KernelModulesInitrdExclude=`, `--kernel-modules-initrd-exclude=`
1048 : Like `KernelModulesExclude=`, but applies to the kernel modules included in the kernel modules initrd.
1049
1050 `Locale=`, `--locale=`, `LocaleMessages=`, `--locale-messages=`, `Keymap=`, `--keymap=`, `Timezone=`, `--timezone=`, `Hostname=`, `--hostname=`, `RootShell=`, `--root-shell=`
1051 : The settings `Locale=`, `--locale=`, `LocaleMessages=`, `--locale-messages=`,
1052 `Keymap=`, `--keymap=`, `Timezone=`, `--timezone=`, `Hostname=`,
1053 `--hostname=`, `RootShell=`, `--root-shell=` correspond to the identically
1054 named systemd-firstboot options. See **systemd-firstboot**(1)
1055 for more information. Additionally, where applicable, the corresponding
1056 systemd credentials for these settings are written to `/usr/lib/credstore`,
1057 so that they apply even if only `/usr` is shipped in the image.
1058
1059 `RootPassword=`, `--root-password=`,
1060 : Set the system root password. If this option is not used, but a `mkosi.rootpw` file is found in the local
1061 directory, the password is automatically read from it or if the file is executable it is run as a script
1062 and stdout is read instead (see the **Scripts** section below). If the password starts with `hashed:`, it is
1063 treated as an already hashed root password. The root password is also stored in `/usr/lib/credstore` under
1064 the appropriate systemd credential so that it applies even if only `/usr` is shipped in the image. To create
1065 an unlocked account without any password use `hashed:` without a hash.
1066
1067 `Autologin=`, `--autologin`
1068 : Enable autologin for the `root` user on `/dev/pts/0` (nspawn),
1069 `/dev/tty1` and `/dev/hvc0`.
1070
1071 `MakeInitrd=`, `--make-initrd`
1072 : Add `/etc/initrd-release` and `/init` to the image so that it can be
1073 used as an initramfs.
1074
1075 `Ssh=`, `--ssh`
1076 : If specified, an **sshd** socket unit and matching service are installed
1077 in the final image that expose SSH over VSock. When building with this
1078 option and running the image using `mkosi vm`, the `mkosi ssh`
1079 command can be used to connect to the container/VM via SSH. Note that
1080 you still have to make sure openssh is installed in the image to make
1081 this option behave correctly. Run `mkosi genkey` to automatically
1082 generate an X.509 certificate and private key to be used by **mkosi** to
1083 enable SSH access to any virtual machines via `mkosi ssh`. To access
1084 images booted using `mkosi boot`, use **machinectl**.
1085
1086 `SELinuxRelabel=`, `--selinux-relabel=`
1087 : Specifies whether to relabel files to match the image's SELinux
1088 policy. Takes a boolean value or `auto`. Defaults to `auto`. If
1089 disabled, files will not relabeled. If enabled, an SELinux policy has
1090 to be installed in the image and **setfiles** has to be available to
1091 relabel files. If any errors occur during **setfiles**, the build will
1092 fail. If set to `auto`, files will be relabeled if an SELinux policy
1093 is installed in the image and if **setfiles** is available. Any errors
1094 occurred during **setfiles** will be ignored.
1095
1096 Note that when running unprivileged, **setfiles** will fail to set any
1097 labels that are not in the host's SELinux policy. To ensure **setfiles**
1098 succeeds without errors, make sure to run **mkosi** as root or build from
1099 a host system with the same SELinux policy as the image you're
1100 building.
1101
1102 `MachineId=`, `--machine-id=`
1103
1104 : Takes a UUID or the special value `random`. Sets the machine ID of the
1105 image to the specified UUID. If set to `random`, a random UUID will be
1106 written to `/etc/machine-id`. If not specified explicitly and the file
1107 `mkosi.machine-id` exists in the local directory, the UUID to use is
1108 read from it. Otherwise, `uninitialized` will be written to `/etc/machine-id`.
1109
1110 ### [Validation] Section
1111
1112 `SecureBoot=`, `--secure-boot`
1113 : Sign **systemd-boot** (if it is not signed yet) and any generated
1114 unified kernel images for UEFI SecureBoot.
1115
1116 `SecureBootAutoEnroll=`, `--secure-boot-auto-enroll=`
1117 : Set up automatic enrollment of the secure boot keys in virtual machines as
1118 documented in **systemd-boot**(7) if `SecureBoot=` is used.
1119 Note that **systemd-boot** will only do automatic secure boot key
1120 enrollment in virtual machines starting from systemd v253. To do auto
1121 enrollment on systemd v252 or on bare metal machines, write a
1122 **systemd-boot** configuration file to `/efi/loader/loader.conf` using an
1123 extra tree with `secure-boot-enroll force` or
1124 `secure-boot-enroll manual` in it. Auto enrollment is not supported on
1125 systemd versions older than v252. Defaults to `yes`.
1126
1127 `SecureBootKey=`, `--secure-boot-key=`
1128 : Path to the PEM file containing the secret key for signing the
1129 UEFI kernel image if `SecureBoot=` is used and PCR signatures when
1130 `SignExpectedPcr=` is also used. When `SecureBootKeySource=` is specified,
1131 the input type depends on the source.
1132
1133 `SecureBootCertificate=`, `--secure-boot-certificate=`
1134 : Path to the X.509 file containing the certificate for the signed
1135 UEFI kernel image, if `SecureBoot=` is used.
1136
1137 `SecureBootSignTool=`, `--secure-boot-sign-tool`
1138 : Tool to use to sign secure boot PE binaries. Takes one of `systemd-sbsign`, `sbsign` or `auto`.
1139 Defaults to `auto`. If set to `auto`, either **systemd-sbsign** or **sbsign** are used if
1140 available, with **systemd-sbsign** being preferred.
1141
1142 `Verity=`, `--verity=`
1143 : Whether to enforce or disable signed verity for extension images.
1144 Takes a boolean value or `auto`. If enabled, a verity key and
1145 certificate must be present and the build will fail if we don't
1146 detect any verity partitions in the disk image produced by
1147 **systemd-repart**. If disabled, verity partitions will be excluded from
1148 the extension images produced by **systemd-repart**. If set to `auto` and
1149 a verity key and certificate are present, **mkosi** will pass them to systemd-repart
1150 and expects the generated disk image to contain verity partitions,
1151 but the build won't fail if no verity partitions are found in the
1152 disk image produced by **systemd-repart**.
1153
1154 Note that explicitly disabling signed verity is not yet implemented
1155 for the `disk` output and only works for extension images at the
1156 moment.
1157
1158 `VerityKey=`, `--verity-key=`
1159 : Path to the PEM file containing the secret key for signing the verity signature, if a verity signature
1160 partition is added with **systemd-repart**. When `VerityKeySource=` is specified, the input type depends on
1161 the source.
1162
1163 `VerityCertificate=`, `--verity-certificate=`
1164 : Path to the X.509 file containing the certificate for signing the verity signature, if a verity signature
1165 partition is added with **systemd-repart**.
1166
1167 `SignExpectedPcr=`, `--sign-expected-pcr`
1168 : Measure the components of the unified kernel image (UKI) using
1169 **systemd-measure** and embed the PCR signature into the unified kernel
1170 image. This option takes a boolean value or the special value `auto`,
1171 which is the default, which is equal to a true value if the
1172 **systemd-measure** binary is in `PATH`. Depends on `SecureBoot=`
1173 being enabled and key from `SecureBootKey=`.
1174
1175 `SignExpectedPcrKey=`, `--sign-expected-pcr-key=`
1176 : Path to the PEM file containing the secret key for signing the expected PCR signatures.
1177 When `SignExpectedPcrKeySource=` is specified, the input type depends on
1178 the source.
1179
1180 `SignExpectedPcrCertificate=`, `--sign-expected-pcr-certificate=`
1181 : Path to the X.509 file containing the certificate for signing the expected PCR signatures.
1182
1183 `SecureBootKeySource=`, `--secure-boot-key-source=`, `VerityKeySource=`, `--verity-key-source=`, `SignExpectedPcrKeySource=`, `--sign-expected-key-source=`
1184 : The source of the corresponding private key, to support OpenSSL engines and providers,
1185 e.g. `--secure-boot-key-source=engine:pkcs11` or `--secure-boot-key-source=provider:pkcs11`.
1186
1187 `SecureBootCertificateSource=`, `--secure-boot-certificate-source=`, `VerityCertificateSource=`, `--verity-certificate-source=`, `SignExpectedPcrCertificateSource=`, `--sign-expected-certificate-source=`
1188 : The source of the corresponding certificate, to support OpenSSL providers,
1189 e.g. `--secure-boot-certificate-source=provider:pkcs11`. Note that engines are not supported.
1190
1191 `Passphrase=`, `--passphrase`
1192 : Specify the path to a file containing the passphrase to use for LUKS
1193 encryption. It should contain the passphrase literally, and not end in
1194 a newline character (i.e. in the same format as **cryptsetup** and
1195 `/etc/crypttab` expect the passphrase files). The file must have an
1196 access mode of 0600 or less.
1197
1198 `Checksum=`, `--checksum`
1199 : Generate a `<output>.SHA256SUMS` file of all generated artifacts
1200 after the build is complete.
1201
1202 `Sign=`, `--sign`
1203 : Sign the generated `SHA256SUMS` using **gpg** after completion.
1204
1205 `OpenPGPTool=`, `--openpgp-tool`
1206 : OpenPGP implementation to use for signing. `gpg` is the default.
1207 Selecting a value different than the default will use the given Stateless
1208 OpenPGP (SOP) tool for signing the `SHA256SUMS` file.
1209
1210 Exemplary choices are `sqop` and `rsop`, but any implementation from
1211 https://www.openpgp.org/about/sop/ that can be installed locally will work.
1212
1213 `Key=`, `--key=`
1214 : Select the **gpg** key to use for signing `SHA256SUMS`. This key must
1215 be already present in the **gpg** keyring.
1216
1217 ### [Build] Section
1218
1219 `ToolsTree=`, `--tools-tree=`
1220 : If specified, programs executed by **mkosi** to build and boot an image
1221 are looked up inside the given tree instead of in the host system. Use
1222 this option to make image builds more reproducible by always using the
1223 same versions of programs to build the final image instead of whatever
1224 version is installed on the host system. If this option is not used,
1225 but the `mkosi.tools/` directory is found in the local directory it is
1226 automatically used for this purpose with the root directory as target.
1227
1228 Note that binaries found in any of the paths configured with
1229 `ExtraSearchPaths=` will be executed with `/usr/` from the tools
1230 tree instead of from the host. If the host distribution or release
1231 does not match the tools tree distribution or release respectively,
1232 this might result in failures when trying to execute binaries from
1233 any of the extra search paths.
1234
1235 If set to `default`, **mkosi** will automatically add an extra tools tree
1236 image and use it as the tools tree.
1237
1238 The following table shows for which distributions default tools tree
1239 packages are defined and which packages are included in those default
1240 tools trees:
1241
1242 | | Fedora | CentOS | Debian | Kali | Ubuntu | Arch | openSUSE |
1243 |-------------------------|:------:|:------:|:------:|:----:|:------:|:----:|:--------:|
1244 | `acl` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1245 | `apt` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1246 | `archlinux-keyring` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1247 | `attr` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1248 | `bash` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1249 | `btrfs-progs` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1250 | `ca-certificates` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1251 | `coreutils` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1252 | `cpio` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1253 | `createrepo_c` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1254 | `curl` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1255 | `debian-keyring` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1256 | `diffutils` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1257 | `distribution-gpg-keys` | ✓ | ✓ | ✓ | ✓ | | ✓ | ✓ |
1258 | `dnf` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1259 | `dosfstools` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1260 | `e2fsprogs` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1261 | `edk2-ovmf` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1262 | `erofs-utils` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1263 | `findutils` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1264 | `git` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1265 | `grep` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1266 | `grub-tools` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1267 | `jq` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1268 | `kali-archive-keyring` | | | | ✓ | | | |
1269 | `kmod` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1270 | `less` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1271 | `mtools` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1272 | `nano` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1273 | `opensc` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1274 | `openssh` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1275 | `openssl` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1276 | `pkcs11-provider` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1277 | `perf` | ✓ | ✓ | ✓ | ✓ | | ✓ | ✓ |
1278 | `sed` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1279 | `pacman` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1280 | `policycoreutils` | ✓ | ✓ | ✓ | ✓ | ✓ | | ✓ |
1281 | `qemu` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1282 | `sbsigntools` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1283 | `socat` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1284 | `squashfs-tools` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1285 | `strace` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1286 | `swtpm` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1287 | `systemd` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1288 | `ukify` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1289 | `tar` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1290 | `ubuntu-keyring` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1291 | `util-linux` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1292 | `virtiofsd` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1293 | `virt-firmware` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1294 | `xfsprogs` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1295 | `xz` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1296 | `zstd` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1297 | `zypper` | ✓ | | ✓ | ✓ | ✓ | | ✓ |
1298
1299 `ToolsTreeDistribution=`, `--tools-tree-distribution=`
1300 : Set the distribution to use for the default tools tree. Defaults to the host distribution except for
1301 Ubuntu, which defaults to Debian, and RHEL, CentOS, Alma and Rocky, which default to Fedora, or `custom`
1302 if the distribution of the host is not a supported distribution.
1303
1304 `ToolsTreeRelease=`, `--tools-tree-release=`
1305 : Set the distribution release to use for the default tools tree. By
1306 default, the hardcoded default release in **mkosi** for the distribution
1307 is used.
1308
1309 `ToolsTreeMirror=`, `--tools-tree-mirror=`
1310 : Set the mirror to use for the default tools tree. By default, the
1311 default mirror for the tools tree distribution is used.
1312
1313 `ToolsTreeRepositories=`, `--tools-tree-repository`
1314 : Same as `Repositories=` but for the default tools tree.
1315
1316 `ToolsTreeSandboxTrees=`, `--tools-tree-sandbox-tree`
1317 : Same as `SandboxTrees=` but for the default tools tree.
1318
1319 `ToolsTreePackages=`, `--tools-tree-package=`
1320 : Extra packages to install into the default tools tree. Takes a comma
1321 separated list of package specifications. This option may be used
1322 multiple times in which case the specified package lists are combined.
1323
1324 `ToolsTreePackageDirectories=`, `--tools-tree-package-directory=`
1325 : Same as `PackageDirectories=`, but for the default tools tree.
1326
1327 `ToolsTreeCertificates=`, `--tools-tree-certificates=`
1328 : Specify whether to use certificates and keys from the tools tree.
1329 Enabled by default. If enabled, `/etc/pki`, `/etc/ssl`,
1330 `/etc/ca-certificates`, and `/var/lib/ca-certificates` from the
1331 tools tree are used. Otherwise, these directories are picked up from
1332 the host.
1333
1334 `ExtraSearchPaths=`, `--extra-search-path=`
1335 : List of colon-separated paths to look for tools in, before using the
1336 regular `$PATH` search path.
1337
1338 `Incremental=`, `--incremental=`, `-i`
1339 : Takes either `strict` or a boolean value as its argument. Enables
1340 incremental build mode. In this mode, a copy of the OS image is created
1341 immediately after all OS packages are installed and the prepare scripts
1342 have executed but before the `mkosi.build` scripts are invoked (or
1343 anything that happens after it). On subsequent invocations of **mkosi**
1344 with the `-i` switch this cached image may be used to skip the OS package
1345 installation, thus drastically speeding up repetitive build times. Note
1346 that while there is some rudimentary cache invalidation, it is definitely
1347 not perfect. In order to force a rebuild of the cached image, combine
1348 `-i` with `-ff` to ensure the cached image is first removed and then
1349 re-created.
1350
1351 If set to `strict`, the build fails if previously built cached image does
1352 not exist.
1353
1354 `CacheOnly=`, `--cache-only=`
1355 : Takes one of `auto`, `metadata`, `always` or `never`. Defaults to
1356 `auto`. If `always`, the package manager is instructed not to contact
1357 the network. This provides a minimal level of reproducibility, as long
1358 as the package cache is already fully populated. If set to `metadata`,
1359 the package manager can still download packages, but we won't sync the
1360 repository metadata. If set to `auto`, the repository metadata is
1361 synced unless we have a cached image (see `Incremental=`) and packages
1362 can be downloaded during the build. If set to `never`, repository
1363 metadata is always synced and packages can be downloaded during
1364 the build.
1365
1366 `SandboxTrees=`, `--sandbox-tree=`
1367 : Takes a comma-separated list of colon-separated path pairs. The first
1368 path of each pair refers to a directory to copy into the mkosi
1369 sandbox before executing a tool. If the `mkosi.sandbox/` directory
1370 is found in the local directory it is used for this purpose with the
1371 root directory as target (also see the **Files** section below).
1372
1373 **mkosi** will look for the package manager configuration and related
1374 files in the configured sandbox trees. Unless specified otherwise,
1375 it will use the configuration files from their canonical locations
1376 in `/usr` or `/etc` in the sandbox trees. For example, it will look
1377 for `/etc/dnf/dnf.conf` in the sandbox trees if **dnf** is used to
1378 install packages.
1379
1380 `WorkspaceDirectory=`, `--workspace-directory=`
1381 : Path to a directory where to store data required temporarily while
1382 building the image. This directory should have enough space to store
1383 the full OS image, though in most modes the actually used disk space
1384 is smaller. If not specified, a subdirectory of `$XDG_CACHE_HOME` (if
1385 set), `$HOME/.cache` (if set) or `/var/tmp` is used.
1386
1387 The data in this directory is removed automatically after each
1388 build. It's safe to manually remove the contents of this directory
1389 should an **mkosi** invocation be aborted abnormally (for example, due
1390 to reboot/power failure).
1391
1392 `CacheDirectory=`, `--cache-directory=`
1393 : Takes a path to a directory to use as the incremental cache directory
1394 for the incremental images produced when the `Incremental=` option is
1395 enabled. If this option is not used, but a `mkosi.cache/` directory is
1396 found in the local directory it is automatically used for this
1397 purpose.
1398
1399 `PackageCacheDirectory=`, `--package-cache-dir`
1400 : Takes a path to a directory to use as the package cache directory for the distribution package manager
1401 used. If unset, but a `mkosi.pkgcache/` directory is found in the local directory it is automatically
1402 used for this purpose, otherwise a suitable directory in the user's home directory or system is used.
1403
1404 `BuildDirectory=`, `--build-directory=`
1405 : Takes a path to a directory to use as the build directory for build
1406 systems that support out-of-tree builds (such as Meson). The directory
1407 used this way is shared between repeated builds, and allows the build
1408 system to reuse artifacts (such as object files, executable, …)
1409 generated on previous invocations. The build scripts can find the path
1410 to this directory in the `$BUILDDIR` environment variable. This
1411 directory is mounted into the image's root directory when
1412 **mkosi-chroot** is invoked during execution of the build scripts. If
1413 this option is not specified, but a directory `mkosi.builddir/` exists
1414 in the local directory it is automatically used for this purpose (also
1415 see the **Files** section below).
1416
1417 `UseSubvolumes=`, `--use-subvolumes=`
1418 : Takes a boolean or `auto`. Enables or disables use of btrfs subvolumes for
1419 directory tree outputs. If enabled, **mkosi** will create the root directory as
1420 a btrfs subvolume and use btrfs subvolume snapshots where possible to copy
1421 base or cached trees which is much faster than doing a recursive copy. If
1422 explicitly enabled and `btrfs` is not installed or subvolumes cannot be
1423 created, an error is raised. If `auto`, missing **btrfs** or failures to
1424 create subvolumes are ignored.
1425
1426 `RepartOffline=`, `--repart-offline=`
1427 : Specifies whether to build disk images using loopback devices. Enabled
1428 by default. When enabled, **systemd-repart** will not use loopback
1429 devices to build disk images. When disabled, **systemd-repart** will
1430 always use loopback devices to build disk images.
1431
1432 Note that when using `RepartOffline=no`**mkosi** cannot run unprivileged and
1433 the image build has to be done as the root user outside of any
1434 containers and with loopback devices available on the host system.
1435
1436 There are currently two known scenarios where `RepartOffline=no` has to be
1437 used. The first is when using `Subvolumes=` in a repart partition
1438 definition file, as subvolumes cannot be created without using
1439 loopback devices. The second is when creating a system with SELinux
1440 and an XFS root partition. Because **mkfs.xfs** does not support
1441 populating an XFS filesystem with extended attributes, loopback
1442 devices have to be used to ensure the SELinux extended attributes end
1443 up in the generated XFS filesystem.
1444
1445 `History=`, `--history=`
1446 : Takes a boolean. If enabled, **mkosi** will write information about the
1447 latest build to the `.mkosi-private` subdirectory in the directory
1448 from which it was invoked. This information is then used to restore
1449 the config of the latest build when running any verb that needs a
1450 build without specifying `--force`.
1451
1452 To give an example of why this is useful, if you run
1453 `mkosi -O my-custom-output-dir -f` followed by `mkosi vm`, **mkosi**
1454 will fail saying the image hasn't been built yet. If you run
1455 `mkosi -O my-custom-output-dir --history=yes -f` followed by
1456 `mkosi vm`, it will boot the image built in the previous step as
1457 expected.
1458
1459 `BuildSources=`, `--build-sources=`
1460 : Takes a comma-separated list of colon-separated path pairs. The first
1461 path of each pair refers to a directory to mount from the host. The
1462 second path of each pair refers to the directory where the source
1463 directory should be mounted when running scripts. Every target path is
1464 prefixed with `/work/src` and all build sources are sorted
1465 lexicographically by their target before mounting, so that top level
1466 paths are mounted first. If not configured explicitly, the current
1467 working directory is mounted to `/work/src`.
1468
1469 `BuildSourcesEphemeral=`, `--build-sources-ephemeral=`
1470 : Takes a boolean or the special value `buildcache`. Disabled by default. Configures whether changes to
1471 source directories, the working directory and configured using `BuildSources=`, are persisted. If
1472 enabled, all source directories will be reset to their original state every time after running all
1473 scripts of a specific type (except sync scripts).
1474
1475 💥💣💥 If set to `buildcache` the overlay is not discarded when running build scripts, but saved to the
1476 build directory, configured via `BuildDirectory=`, and will be reused on subsequent runs. The overlay is
1477 still discarded for all other scripts. This option can be used to implement more advanced caching of
1478 builds, but can lead to unexpected states of the source directory. When using this option, a build
1479 directory must be configured. 💥💣💥
1480
1481 `Environment=`, `--environment=`
1482 : Adds variables to the environment that package managers and the
1483 prepare/build/postinstall/finalize scripts are executed with. Takes
1484 a space-separated list of variable assignments or just variable
1485 names. In the latter case, the values of those variables will be
1486 passed through from the environment in which **mkosi** was invoked.
1487 This option may be specified more than once, in which case all
1488 listed variables will be set. If the same variable is set twice, the
1489 later setting overrides the earlier one.
1490
1491 `EnvironmentFiles=`, `--env-file=`
1492 : Takes a comma-separated list of paths to files that contain environment
1493 variable definitions to be added to the scripting environment. Uses
1494 `mkosi.env` if it is found in the local directory. The variables are
1495 first read from `mkosi.env` if it exists, then from the given list of
1496 files and then from the `Environment=` settings.
1497
1498 `WithTests=`, `--without-tests`, `-T`
1499 : If set to false (or when the command-line option is used), the
1500 `$WITH_TESTS` environment variable is set to `0` when the
1501 `mkosi.build` scripts are invoked. This is supposed to be used by the
1502 build scripts to bypass any unit or integration tests that are
1503 normally run during the source build process. Note that this option
1504 has no effect unless the `mkosi.build` build scripts honor it.
1505
1506 `WithNetwork=`, `--with-network=`
1507 : When true, enables network connectivity while the build scripts
1508 `mkosi.build` are invoked. By default, the build scripts run with
1509 networking turned off. The `$WITH_NETWORK` environment variable is
1510 passed to the `mkosi.build` build scripts indicating whether the
1511 build is done with or without network.
1512
1513 `ProxyUrl=`, `--proxy-url=`
1514 : Configure a proxy to be used for all outgoing network connections.
1515 Various tools that **mkosi** invokes and for which the proxy can be
1516 configured are configured to use this proxy. **mkosi** also sets various
1517 well-known environment variables to specify the proxy to use for any
1518 programs it invokes that may need internet access.
1519
1520 `ProxyExclude=`, `--proxy-exclude=`
1521 : Configure hostnames for which requests should not go through the
1522 proxy. Takes a comma-separated list of hostnames.
1523
1524 `ProxyPeerCertificate=`, `--proxy-peer-certificate=`
1525 : Configure a file containing certificates used to verify the proxy.
1526 Defaults to the system-wide certificate store.
1527
1528 Currently, setting a proxy peer certificate is only supported when
1529 **dnf** or **dnf5** is used to build the image.
1530
1531 `ProxyClientCertificate=`, `--proxy-client-certificate=`
1532 : Configure a file containing the certificate used to authenticate the
1533 client with the proxy.
1534
1535 Currently, setting a proxy client certificate is only supported when
1536 **dnf** or **dnf5** is used to build the image.
1537
1538 `ProxyClientKey=`, `--proxy-client-key=`
1539 : Configure a file containing the private key used to authenticate the
1540 client with the proxy. Defaults to the proxy client certificate if one
1541 is provided.
1542
1543 Currently, setting a proxy client key is only supported when **dnf** or
1544 **dnf5** is used to build the image.
1545
1546 ### [Runtime] Section (previously known as the [Host] section)
1547
1548 `NSpawnSettings=`, `--settings=`
1549 : Specifies a `.nspawn` settings file for **systemd-nspawn** to use in
1550 the `boot` and `shell` verbs, and to place next to the generated
1551 image file. This is useful to configure the **systemd-nspawn**
1552 environment when the image is run. If this setting is not used but
1553 an `mkosi.nspawn` file found in the local directory it is
1554 automatically used for this purpose.
1555
1556 `VirtualMachineMonitor=`, `--vmm=`
1557 : Configures the virtual machine monitor to use. Takes one of `qemu` or
1558 `vmspawn`. Defaults to `qemu`.
1559
1560 When set to `qemu`, the image is booted with **qemu**. Most output
1561 formats can be booted in **qemu**. Any arguments specified after the
1562 verb are appended to the **qemu** invocation and are interpreted as
1563 extra **qemu** command line arguments.
1564
1565 When set to `vmspawn`, **systemd-vmspawn** is used to boot up the image,
1566 `vmspawn` only supports disk and directory type images. Any arguments
1567 specified after the verb are appended to the **systemd-vmspawn**
1568 invocation and are interpreted as extra vmspawn options and extra
1569 kernel command line arguments.
1570
1571 `Console=`, `--console=`
1572 : Configures how to set up the console of the VM. Takes one of `interactive`, `read-only`, `native`, or
1573 `gui`. Defaults to `interactive`. `interactive` provides an interactive terminal interface to the VM.
1574 `read-only` is similar, but is strictly read-only, i.e. does not accept any input from the user.
1575 `native` also provides a TTY-based interface, but uses **qemu**'s native implementation (which means the **qemu**
1576 monitor is available). `gui` shows the **qemu** graphical UI.
1577
1578 `CPUs=`, `--cpus=`
1579 : Configures the number of CPU cores to assign to the guest when booting a virtual machine.
1580 Defaults to `2`.
1581
1582 When set to `0`, the number of CPUs available to the **mkosi** process
1583 will be used.
1584
1585 `RAM=`, `--ram=`
1586 : Configures the amount of RAM assigned to the guest when booting a virtual machine. Defaults to `2G`.
1587
1588 `KVM=`, `--kvm=`
1589 : Configures whether KVM acceleration should be used when booting a virtual machine. Takes a
1590 boolean value or `auto`. Defaults to `auto`.
1591
1592 `Vsock=`, `--vsock=`
1593 : Configures whether to provision a vsock when booting a virtual machine. Takes
1594 a boolean value or `auto`. Defaults to `auto`.
1595
1596 `VsockConnectionId=`, `vsock-cid=`
1597 : Configures the vsock connection ID to use when booting a virtual machine.
1598 Takes a number in the interval `[3, 0xFFFFFFFF)` or `hash` or `auto`.
1599 Defaults to `auto`. When set to `hash`, the connection ID will be derived
1600 from the full path to the image. When set to `auto`, **mkosi** will try to
1601 find a free connection ID automatically. Otherwise, the provided number will
1602 be used as is.
1603
1604 `TPM=`, `--tpm=`
1605 : Configure whether to use a virtual TPM when booting a virtual machine.
1606 Takes a boolean value or `auto`. Defaults to `auto`.
1607
1608 `CDROM=`, `--cdrom=`
1609 : Configures whether to attach the image as a CD-ROM device when booting a
1610 virtual machine. Takes a boolean. Defaults to `no`.
1611
1612 `Removable=`, `--removable=`
1613 : Configures whether to attach the image as a removable device when booting
1614 a virtual machine. Takes a boolean. Defaults to `no`.
1615
1616 `Firmware=`, `--firmware=`
1617 : Configures the virtual machine firmware to use. Takes one of `uefi`,
1618 `uefi-secure-boot`, `bios`, `linux`, or `auto`. Defaults to `auto`.
1619 When set to `uefi`, the OVMF firmware without secure boot support
1620 is used. When set to `uefi-secure-boot`, the OVMF firmware with
1621 secure boot support is used. When set to `bios`, the default SeaBIOS
1622 firmware is used. When set to `linux`, direct kernel boot is used.
1623 See the `Linux=` option for more details on which kernel image is
1624 used with direct kernel boot. When set to `auto`, `uefi-secure-boot`
1625 is used if possible and `linux` otherwise.
1626
1627 `FirmwareVariables=`, `--firmware-variables=`
1628 : Configures the path to the the virtual machine firmware variables file
1629 to use. Currently, this option is only taken into account when the `uefi`
1630 or `uefi-secure-boot` firmware is used. If not specified, **mkosi** will search
1631 for the default variables file and use that instead.
1632
1633 When set to `microsoft`, a firmware variables file with the Microsoft
1634 secure boot certificates already enrolled will be used.
1635
1636 When set to `microsoft-mok`, a firmware variables file with the
1637 Microsoft secure boot certificates already enrolled will be extended
1638 with a `MokList` variable containing the secure boot certificate
1639 from `SecureBootCertificate=`. This is intended to be used together
1640 with shim binaries signed by the distribution and locally signed EFI
1641 binaries.
1642
1643 When set to `custom`, the secure boot certificate from
1644 `SecureBootCertificate=` will be enrolled into the default firmware
1645 variables file.
1646
1647 `virt-fw-vars` from the
1648 [virt-firmware](https://gitlab.com/kraxel/virt-firmware) project can
1649 be used to customize OVMF variable files.
1650
1651 `Linux=`, `--linux=`
1652 : Set the kernel image to use for **qemu** direct kernel boot. If not
1653 specified, **mkosi** will use the kernel provided via the command line
1654 (`-kernel` option) or latest the kernel that was installed into
1655 the image (or fail if no kernel was installed into the image).
1656
1657 Note that when the `cpio` output format is used, direct kernel boot is
1658 used regardless of the configured firmware. Depending on the
1659 configured firmware, **qemu** might boot the kernel itself or using the
1660 configured firmware.
1661
1662 `Drives=`, `--drive=`
1663 : Add a drive. Takes a colon-delimited string of format
1664 `<id>:<size>[:<directory>[:<options>[:<file-id>]]]`. `id` specifies
1665 the ID assigned to the drive. This can be used as the `drive=`
1666 property in various **qemu** devices. `size` specifies the size of the
1667 drive. This takes a size in bytes. Additionally, the suffixes `K`, `M`
1668 and `G` can be used to specify a size in kilobytes, megabytes and
1669 gigabytes respectively. `directory` optionally specifies the directory
1670 in which to create the file backing the drive. `options` optionally
1671 specifies extra comma-delimited properties which are passed verbatim
1672 to **qemu**'s `-drive` option. `file-id` specifies the ID of the file
1673 backing the drive. Drives with the same file ID will share the
1674 backing file. The directory and size of the file will be determined
1675 from the first drive with a given file ID.
1676
1677 **Example usage:**
1678
1679 ```ini
1680 [Runtime]
1681 Drives=btrfs:10G
1682 ext4:20G
1683 QemuArgs=-device nvme,serial=btrfs,drive=btrfs
1684 -device nvme,serial=ext4,drive=ext4
1685 ```
1686
1687 `QemuArgs=`
1688 : Space-delimited list of additional arguments to pass when invoking
1689 **qemu**.
1690
1691 `Ephemeral=`, `--ephemeral`
1692 : When used with the `shell`, `boot`, or `vm` verbs, this option runs the specified verb on a temporary
1693 snapshot of the output image that is removed immediately when the container terminates. Taking the
1694 temporary snapshot is more efficient on file systems that support reflinks natively (**btrfs** or **xfs**)
1695 than on more traditional file systems that do not (ext4).
1696
1697 `Credentials=`, `--credential=`
1698 : Set credentials to be passed to **systemd-nspawn** or the virtual machine respectively
1699 when `mkosi shell/boot` or `mkosi vm` are used. This option takes a
1700 space separated list of values which can be either key=value pairs or
1701 paths. If a path is provided, if it is a file, the credential name
1702 will be the name of the file. If the file is executable, the
1703 credential value will be the output of executing the file. Otherwise,
1704 the credential value will be the contents of the file. If the path is
1705 a directory, the same logic applies to each file in the directory.
1706
1707 Note that values will only be treated as paths if they do not contain
1708 the delimiter (`=`).
1709
1710 `KernelCommandLineExtra=`, `--kernel-command-line-extra=`
1711 : Set extra kernel command line entries that are appended to the kernel command
1712 line at runtime when booting the image. When booting in a container, these are
1713 passed as extra arguments to systemd. When booting in a VM, these are appended
1714 to the kernel command line via the SMBIOS io.systemd.stub.kernel-cmdline-extra
1715 OEM string. This will only be picked up by **systemd-boot** and **systemd-stub** versions
1716 newer than or equal to v254.
1717
1718 `RuntimeTrees=`, `--runtime-tree=`
1719 : Takes a colon-separated pair of paths. The first path refers to a
1720 directory to mount into any machine (container or VM) started by
1721 mkosi. The second path refers to the target directory inside the
1722 machine. If the second path is not provided, the directory is mounted
1723 at `/root/src` in the machine. If the second path is relative, it
1724 is interpreted relative to `/root/src` in the machine.
1725
1726 For each mounted directory, the uid and gid of the user running mkosi
1727 are mapped to the root user in the machine. This means that all the
1728 files and directories will appear as if they're owned by root in the
1729 machine, and all new files and directories created by root in the
1730 machine in these directories will be owned by the user running mkosi
1731 on the host.
1732
1733 Note that when using `mkosi vm` with this feature systemd v254 or
1734 newer has to be installed in the image.
1735
1736 `RuntimeSize=`, `--runtime-size=`
1737 : If specified, disk images are grown to the specified size when
1738 they're booted with `mkosi boot` or `mkosi vm`. Takes a size in
1739 bytes. Additionally, the suffixes `K`, `M` and `G` can be used to
1740 specify a size in kilobytes, megabytes and gigabytes respectively.
1741
1742 `RuntimeScratch=`, `--runtime-scratch=`
1743 : Takes a boolean value or `auto`. Specifies whether to mount extra
1744 scratch space to `/var/tmp`. If enabled, practically unlimited scratch
1745 space is made available under `/var/tmp` when booting the image with
1746 `mkosi vm`, `mkosi boot` or `mkosi shell`.
1747
1748 Note that using this feature with `mkosi vm` requires systemd v254
1749 or newer in the guest.
1750
1751 `RuntimeNetwork=`, `--runtime-network=`
1752 : Takes one of `user`, `interface` or `none`. Defaults to `user`.
1753 Specifies the networking to set up when booting the image. `user` sets
1754 up usermode networking. `interface` sets up a virtual network
1755 connection between the host and the image. This translates to a veth
1756 interface for `mkosi shell` and `mkosi boot` and a tap interface for
1757 `mkosi vm` and `mkosi vmspawn`.
1758
1759 Note that when using `interface`, **mkosi** does not automatically
1760 configure the host interface. It is expected that a recent version of
1761 **systemd-networkd** is running on the host which will automatically
1762 configure the host interface of the link.
1763
1764 `RuntimeBuildSources=`, `--runtime-build-sources=`
1765 : Mount the build sources configured with `BuildSources=` and the build
1766 directory (if one is configured) to the same locations in `/work` that
1767 they were mounted to when running the build script when using `mkosi
1768 boot` or `mkosi vm`.
1769
1770 `RuntimeHome=`, `--runtime-home=`
1771 : Mount the current home directory from which **mkosi** is running to
1772 `/root` when using `mkosi boot` or `mkosi vm`.
1773
1774 `UnitProperties=`, `--unit-property=`
1775 : Configure systemd unit properties to add to the systemd scopes
1776 allocated when using `mkosi boot` or `mkosi vm`. These are passed
1777 directly to the `--property` options of **systemd-nspawn** and
1778 **systemd-run** respectively.
1779
1780 `SshKey=`, `--ssh-key=`
1781 : Path to the X.509 private key in PEM format to use to connect to a
1782 virtual machine started with `mkosi vm` and built with the `Ssh=`
1783 option enabled via the `mkosi ssh` command. If not configured and
1784 `mkosi.key` exists in the working directory, it will automatically be
1785 used for this purpose. Run `mkosi genkey` to automatically generate
1786 a key in `mkosi.key`.
1787
1788 `SshCertificate=`, `--ssh-certificate=`
1789 : Path to the X.509 certificate in PEM format to provision as the SSH
1790 public key in virtual machines started with `mkosi vm`. If not
1791 configured and `mkosi.crt` exists in the working directory, it will
1792 automatically be used for this purpose. Run `mkosi genkey` to
1793 automatically generate a certificate in `mkosi.crt`.
1794
1795 `Machine=`, `--machine=`
1796 : Specify the machine name to use when booting the image. Can also be
1797 used to refer to a specific image when SSH-ing into an image (e.g.
1798 `mkosi --image=myimage ssh`).
1799
1800 Note that `Ephemeral=` has to be enabled to start multiple instances
1801 of the same image.
1802
1803 `Register=`, `--register=`
1804 : Takes a boolean value or `auto`. Specifies whether to register the
1805 vm/container with systemd-machined. If enabled, mkosi will fail if
1806 it can't register the vm/container with systemd-machined. If
1807 disabled, mkosi will not register the vm/container with
1808 systemd-machined. If `auto`, mkosi will register the vm/container
1809 with systemd-machined if it is available. Defaults to `auto`.
1810
1811 `ForwardJournal=`, `--forward-journal=`
1812 : Specify the path to which journal logs from containers and virtual
1813 machines should be forwarded. If the path has the `.journal`
1814 extension, it is interpreted as a file to which the journal should be
1815 written. Otherwise, the path is interpreted as a directory to which
1816 the journal should be written.
1817
1818 Note that systemd v256 or newer is required in the virtual machine for
1819 log forwarding to work.
1820
1821 Note that if a path with the `.journal` extension is given, the
1822 journal size is limited to `4G`. Configure an output directory instead
1823 of file if your workload produces more than `4G` worth of journal
1824 data.
1825
1826 `SysupdateDirectory=`, `--sysupdate-directory=`
1827 : Path to a directory containing systemd-sysupdate transfer definition
1828 files that are used by `mkosi sysupdate`. If `mkosi.sysupdate/`
1829 exists in the local directory, it will be used for this purpose as
1830 well.
1831
1832 Note that `mkosi sysupdate` invokes `systemd-sysupdate` with
1833 `--transfer-source=` set to the **mkosi** output directory. To make use
1834 of this in a transfer definition file, set `PathRelativeTo=explicit`
1835 to have the `Path=` setting for the transfer source be interpreted
1836 relative to the **mkosi** output directory. Generally, configuring
1837 `PathRelativeTo=explicit` and `Path=/` for the transfer source is
1838 sufficient for the match pattern to be interpreted relative to the
1839 **mkosi** output directory.
1840
1841 ### [Match] Section
1842
1843 `Profiles=`
1844 : Matches against the configured profiles.
1845
1846 `Distribution=`
1847 : Matches against the configured distribution.
1848
1849 `Release=`
1850 : Matches against the configured distribution release. If this condition is used and no distribution has been
1851 explicitly configured yet, the host distribution and release are used.
1852
1853 `Architecture=`
1854 : Matches against the configured architecture. If this condition is used
1855 and no architecture has been explicitly configured yet, the host
1856 architecture is used.
1857
1858 `Repositories=`
1859 : Matches against repositories enabled with the `Repositories=` setting.
1860 Takes a single repository name.
1861
1862 `PathExists=`
1863 : This condition is satisfied if the given path exists. Relative paths are interpreted relative to the parent
1864 directory of the config file that the condition is read from.
1865
1866 `ImageId=`
1867 : Matches against the configured image ID, supporting globs. If this condition is used and no image ID has
1868 been explicitly configured yet, this condition fails.
1869
1870 `ImageVersion=`
1871 : Matches against the configured image version. Image versions can be prepended by the operators `==`, `!=`,
1872 `>=`, `<=`, `<`, `>` for rich version comparisons according to the UAPI group version format specification.
1873 If no operator is prepended, the equality operator is assumed by default. If this condition is used and no
1874 image version has been explicitly configured yet, this condition fails.
1875
1876 `Bootable=`
1877 : Matches against the configured value for the `Bootable=` feature. Takes a boolean value or `auto`.
1878
1879 `Format=`
1880 : Matches against the configured value for the `Format=` option. Takes
1881 an output format (see the `Format=` option).
1882
1883 `SystemdVersion=`
1884 : Matches against the systemd version on the host (as reported by
1885 `systemctl --version`). Values can be prepended by the operators `==`,
1886 `!=`, `>=`, `<=`, `<`, `>` for rich version comparisons according to
1887 the UAPI group version format specification. If no operator is
1888 prepended, the equality operator is assumed by default.
1889
1890 `BuildSources=`
1891 : Takes a build source target path (see `BuildSources=`). This match is
1892 satisfied if any of the configured build sources uses this target
1893 path. For example, if we have a `mkosi.conf` file containing:
1894
1895 ```ini
1896 [Build]
1897 BuildSources=../abc/qed:kernel
1898 ```
1899
1900 and a drop-in containing:
1901
1902 ```ini
1903 [Match]
1904 BuildSources=kernel
1905 ```
1906
1907 The drop-in will be included.
1908
1909 Any absolute paths passed to this setting are interpreted relative to
1910 the current working directory.
1911
1912 `HostArchitecture=`
1913 : Matches against the host's native architecture. See the
1914 `Architecture=` setting for a list of possible values.
1915
1916 `ToolsTreeDistribution=`
1917 : Matches against the configured tools tree distribution.
1918
1919 `ToolsTreeRelease=`
1920 : Matches against the configured tools tree release.
1921
1922 `Environment=`
1923 : Matches against a specific key/value pair configured with
1924 `Environment=`. If no value is provided, check if the given key is in
1925 the environment regardless of which value it has.
1926
1927 This table shows which matchers support globs, rich comparisons and the default
1928 value that is matched against if no value has been configured at the time the
1929 config file is read:
1930
1931 | Matcher | Globs | Rich Comparisons | Default |
1932 |--------------------------|-------|------------------|----------------------------------------------------------------------------------------|
1933 | `Profiles=` | no | no | match fails |
1934 | `Distribution=` | no | no | match host distribution |
1935 | `Release=` | no | no | match host release |
1936 | `Architecture=` | no | no | match host architecture |
1937 | `PathExists=` | no | no | n/a |
1938 | `ImageId=` | yes | no | match fails |
1939 | `ImageVersion=` | no | yes | match fails |
1940 | `Bootable=` | no | no | match auto feature |
1941 | `Format=` | no | no | match default format |
1942 | `SystemdVersion=` | no | yes | n/a |
1943 | `BuildSources=` | no | no | match fails |
1944 | `HostArchitecture=` | no | no | n/a |
1945 | `ToolsTreeDistribution=` | no | no | match the fallback tools tree distribution (see `ToolsTreeDistribution=` in `[Build]`) |
1946 | `ToolsTreeRelease=` | no | no | match default tools tree release |
1947 | `Environment=` | no | no | n/a |
1948
1949 ### [Include]
1950
1951 `Include=`, `--include=`, `-I`
1952 : Include extra configuration from the given file or directory. The
1953 extra configuration is included immediately after parsing the setting,
1954 except when used on the command line, in which case the extra
1955 configuration is included after parsing all command line arguments.
1956
1957 Note that each path containing extra configuration is only parsed
1958 once, even if included more than once with `Include=`.
1959
1960 The builtin configs for the **mkosi** default initrd, default tools tree
1961 and default virtual machine image can be included by including the
1962 literal value `mkosi-initrd`, `mkosi-tools` or `mkosi-vm`
1963 respectively.
1964
1965 Note: Include names starting with either of the literals `mkosi-` or
1966 `contrib-` are reserved for use by **mkosi** itself.
1967
1968 ### [Config] Section
1969
1970 `Profiles=`, `--profile=`
1971 : Select the given profiles. A profile is a configuration file or
1972 directory in the `mkosi.profiles/` directory. The configuration files
1973 and directories of each profile are included after parsing the
1974 `mkosi.conf.d/*.conf` drop in configuration.
1975
1976 `Dependencies=`, `--dependency=`
1977 : The images that this image depends on specified as a comma-separated
1978 list. All images configured in this option will be built before this
1979 image.
1980
1981 When this setting is specified for the "main" image, it specifies
1982 which subimages should be built. See the
1983 **Building multiple images** section for more information.
1984
1985 `MinimumVersion=`, `--minimum-version=`
1986 : The minimum **mkosi** version required to build this configuration. If
1987 specified multiple times, the highest specified version is used.
1988
1989 `ConfigureScripts=`, `--configure-script=`
1990 : Takes a comma-separated list of paths to executables that are used as
1991 the configure scripts for this image. See the **Scripts** section for
1992 more information.
1993
1994 `PassEnvironment=`, `--pass-environment=`
1995 : Takes a list of environment variable names separated by spaces. When
1996 building multiple images, pass the listed environment variables to
1997 each individual subimage as if they were "universal" settings. See
1998 the **Building multiple images** section for more information.
1999
2000 ### [UKIProfile] Section
2001
2002 The `UKIProfile` section can be used in UKI profile config files which
2003 are passed to the `UnifiedKernelImageProfiles=` setting. The following
2004 settings can be specified in the `UKIProfile` section:
2005
2006 `Profile=`
2007 : The contents of the `.profile` section of the UKI profile. Takes a
2008 list of key/value pairs separated by `=`. The `ID=` key must be
2009 specified. See the UKI [specification](https://uapi-group.org/specifications/specs/unified_kernel_image/#multi-profile-ukis)
2010 for a full list of possible keys.
2011
2012 `Cmdline=`
2013 : Extra kernel command line options for the UKI profile. Takes a space
2014 delimited list of extra kernel command line arguments. Note that
2015 the final `.cmdline` section will the combination of the base
2016 `.cmdline` section and the extra kernel command line arguments
2017 specified with this setting.
2018
2019 ## Specifiers
2020
2021 The current value of various settings can be accessed when parsing
2022 configuration files by using specifiers. To write a literal `%`
2023 character in a configuration file without treating it as a specifier,
2024 use `%%`. The following specifiers are understood:
2025
2026 | Setting | Specifier |
2027 |--------------------|-----------|
2028 | `Distribution=` | `%d` |
2029 | `Release=` | `%r` |
2030 | `Architecture=` | `%a` |
2031 | `Format=` | `%t` |
2032 | `Output=` | `%o` |
2033 | `OutputDirectory=` | `%O` |
2034 | `ImageId=` | `%i` |
2035 | `ImageVersion=` | `%v` |
2036
2037 There are also specifiers that are independent of settings:
2038
2039 | Specifier | Value |
2040 |-----------|------------------------------------------------|
2041 | `%C` | Parent directory of current config file |
2042 | `%P` | Current working directory |
2043 | `%D` | Directory that **mkosi** was invoked in |
2044 | `%I` | Name of the current subimage in `mkosi.images` |
2045
2046 Finally, there are specifiers that are derived from a setting:
2047
2048 | Specifier | Value |
2049 |-----------|-------------------------------------------------------|
2050 | `%F` | The default filesystem of the configured distribution |
2051
2052 Note that the current working directory changes as **mkosi** parses its
2053 configuration. Specifically, each time **mkosi** parses a directory
2054 containing a `mkosi.conf` file, **mkosi** changes its working directory to
2055 that directory.
2056
2057 Note that the directory that **mkosi** was invoked in is influenced by the
2058 `--directory=` command line argument.
2059
2060 The following table shows example values for the directory specifiers
2061 listed above:
2062
2063 | | `$D/mkosi.conf` | `$D/mkosi.conf.d/abc/abc.conf` | `$D/mkosi.conf.d/abc/mkosi.conf` |
2064 |------|-----------------|--------------------------------|----------------------------------|
2065 | `%C` | `$D` | `$D/mkosi.conf.d` | `$D/mkosi.conf.d/abc` |
2066 | `%P` | `$D` | `$D` | `$D/mkosi.conf.d/abc` |
2067 | `%D` | `$D` | `$D` | `$D` |
2068
2069 ## Supported distributions
2070
2071 Images may be created containing installations of the following
2072 distributions:
2073
2074 * *Fedora Linux*
2075
2076 * *Debian*
2077
2078 * *Kali Linux*
2079
2080 * *Ubuntu*
2081
2082 * *Arch Linux*
2083
2084 * *openSUSE*
2085
2086 * *Mageia*
2087
2088 * *CentOS*
2089
2090 * *RHEL*
2091
2092 * *RHEL UBI*
2093
2094 * *OpenMandriva*
2095
2096 * *Rocky Linux*
2097
2098 * *Alma Linux*
2099
2100 * *Azure Linux*
2101
2102 * *None* (**Requires the user to provide a pre-built rootfs**)
2103
2104 In theory, any distribution may be used on the host for building images
2105 containing any other distribution, as long as the necessary tools are
2106 available.
2107 Specifically,
2108 any distribution that packages **apt** may be used to build *Debian*, *Kali* or *Ubuntu* images.
2109 Any distribution that packages **dnf** may be used to build images for any of the RPM-based distributions.
2110 Any distro that packages **pacman** may be used to build *Arch Linux* images.
2111 Any distribution that packages **zypper** may be used to build *openSUSE* images.
2112 Other distributions and build automation tools for embedded Linux
2113 systems such as Buildroot, OpenEmbedded and Yocto Project may be used by
2114 selecting the `custom` distribution, and populating the rootfs via a
2115 combination of base trees, skeleton trees, and prepare scripts.
2116
2117 Currently, *Fedora Linux* packages all relevant tools as of Fedora 28.
2118
2119 Note that when not using a custom mirror, `RHEL` images can only be
2120 built from a host system with a `RHEL` subscription (established using
2121 e.g. `subscription-manager`).
2122
2123 # Execution Flow
2124
2125 Execution flow for `mkosi build`. Default values/calls are shown in parentheses.
2126 When building with `--incremental` **mkosi** creates a cache of the distribution
2127 installation if not already existing and replaces the distribution installation
2128 in consecutive runs with data from the cached one.
2129
2130 1. Parse CLI options
2131 1. Parse configuration files
2132 1. Run configure scripts (`mkosi.configure`)
2133 1. If we're not running as root, unshare the user namespace and map the
2134 subuid range configured in `/etc/subuid` and `/etc/subgid` into it.
2135 1. Unshare the mount namespace
2136 1. Remount the following directories read-only if they exist:
2137 - `/usr`
2138 - `/etc`
2139 - `/opt`
2140 - `/srv`
2141 - `/boot`
2142 - `/efi`
2143 - `/media`
2144 - `/mnt`
2145
2146 Then, for each image, we execute the following steps:
2147
2148 1. Copy sandbox trees into the workspace
2149 1. Sync the package manager repository metadata
2150 1. Run sync scripts (`mkosi.sync`)
2151 1. Copy base trees (`--base-tree=`) into the image
2152 1. Reuse a cached image if one is available
2153 1. Copy a snapshot of the package manager repository metadata into the
2154 image
2155 1. Copy skeleton trees (`mkosi.skeleton`) into image
2156 1. Install distribution and packages into image
2157 1. Run prepare scripts on image with the `final` argument (`mkosi.prepare`)
2158 1. Install build packages in overlay if any build scripts are configured
2159 1. Run prepare scripts on overlay with the `build` argument if any build
2160 scripts are configured (`mkosi.prepare`)
2161 1. Cache the image if configured (`--incremental`)
2162 1. Run build scripts on image + overlay if any build scripts are configured (`mkosi.build`)
2163 1. Finalize the build if the output format `none` is configured
2164 1. Copy the build scripts outputs into the image
2165 1. Copy the extra trees into the image (`mkosi.extra`)
2166 1. Run post-install scripts (`mkosi.postinst`)
2167 1. Write config files required for `Ssh=`, `Autologin=` and `MakeInitrd=`
2168 1. Install systemd-boot and configure secure boot if configured (`--secure-boot`)
2169 1. Run **systemd-sysusers**
2170 1. Run **systemd-tmpfiles**
2171 1. Run `systemctl preset-all`
2172 1. Run **depmod**
2173 1. Run **systemd-firstboot**
2174 1. Run **systemd-hwdb**
2175 1. Remove packages and files (`RemovePackages=`, `RemoveFiles=`)
2176 1. Run SELinux relabel is a SELinux policy is installed
2177 1. Run finalize scripts (`mkosi.finalize`)
2178 1. Generate unified kernel image if configured to do so
2179 1. Generate final output format
2180 1. Run post-output scripts (`mkosi.postoutput`)
2181
2182 # Scripts
2183
2184 To allow for image customization that cannot be implemented using
2185 **mkosi**'s builtin features, **mkosi** supports running scripts at various
2186 points during the image build process that can customize the image as
2187 needed. Scripts are executed on the host system as root (either real
2188 root or root within the user namespace that **mkosi** created when running
2189 unprivileged) with a customized environment to simplify modifying the
2190 image. For each script, the configured build sources (`BuildSources=`)
2191 are mounted into the current working directory before running the script
2192 in the current working directory. `$SRCDIR` is set to point to the
2193 current working directory. The following scripts are supported:
2194
2195 * If **`mkosi.configure`** (`ConfigureScripts=`) exists, it is executed
2196 before building the image. This script may be used to dynamically
2197 modify the configuration. It receives the configuration serialized as
2198 JSON on stdin and should output the modified configuration serialized
2199 as JSON on stdout. Note that this script only runs when building or
2200 booting the image (`build`, `vm`, `boot` and `shell` verbs). If a
2201 default tools tree is configured, it will be built before running the
2202 configure scripts and the configure scripts will run with the tools
2203 tree available. This also means that the modifications made by
2204 configure scripts will not be visible in the `summary` output.
2205
2206 * If **`mkosi.sync`** (`SyncScripts=`) exists, it is executed before the
2207 image is built. This script may be used to update various sources that
2208 are used to build the image. One use case is to run `git pull` on
2209 various source repositories before building the image. Specifically,
2210 the `BuildSourcesEphemeral=` setting does not apply to sync scripts,
2211 which means sync scripts can be used to update build sources even if
2212 `BuildSourcesEphemeral=` is enabled.
2213
2214 * If **`mkosi.prepare`** (`PrepareScripts=`) exists, it is first called
2215 with the `final` argument, right after the software packages are
2216 installed. It is called a second time with the `build` command line
2217 parameter, right after the build packages are installed and the build
2218 overlay mounted on top of the image's root directory . This script has
2219 network access and may be used to install packages from other sources
2220 than the distro's package manager (e.g. **pip**, **npm**, ...), after all
2221 software packages are installed but before the image is cached (if
2222 incremental mode is enabled). In contrast to a general purpose
2223 installation, it is safe to install packages to the system
2224 (`pip install`, `npm install -g`) instead of in `$SRCDIR` itself
2225 because the build image is only used for a single project and can
2226 easily be thrown away and rebuilt so there's no risk of conflicting
2227 dependencies and no risk of polluting the host system.
2228
2229 * If **`mkosi.build`** (`BuildScripts=`) exists, it is executed with the
2230 build overlay mounted on top of the image's root directory. When
2231 running the build script, `$DESTDIR` points to a directory where the
2232 script should place any files generated it would like to end up in the
2233 image. Note that **make**-, **automake**-, and **meson**-based build systems
2234 generally honor `$DESTDIR`, thus making it very natural to build
2235 *source* trees from the build script. After running the build script,
2236 the contents of `$DESTDIR` are copied into the image.
2237
2238 * If **`mkosi.postinst`** (`PostInstallationScripts=`) exists, it is
2239 executed after the (optional) build tree and extra trees have been
2240 installed. This script may be used to alter the images without any
2241 restrictions, after all software packages and built sources have been
2242 installed.
2243
2244 * If **`mkosi.finalize`** (`FinalizeScripts=`) exists, it is executed as
2245 the last step of preparing an image.
2246
2247 * If **`mkosi.postoutput`** (`PostOutputScripts=`) exists, it is executed right
2248 after all the output files have been generated, before they are finally
2249 moved into the output directory. This can be used to generate additional or
2250 alternative outputs, e.g. `SHA256FILES` or SBOM manifests.
2251
2252 * If **`mkosi.clean`** (`CleanScripts=`) exists, it is executed right
2253 after the outputs of a previous build have been cleaned up. A clean
2254 script can clean up any outputs that **mkosi** does not know about (e.g.
2255 artifacts from `SplitArtifacts=partitions` or RPMs built in a build script).
2256 Note that this script does not use the tools tree even if one is configured.
2257
2258 * If **`mkosi.version`** exists and is executable, it is run during
2259 configuration parsing and populates `ImageVersion=` with the output on stdout.
2260 This can be used for external version tracking, e.g. with `git describe` or
2261 `date '+%Y-%m-%d'`. Note that this script is executed on the host system
2262 without any sandboxing.
2263
2264 * If **`mkosi.rootpw`** exists and is executable, it is run during
2265 configuration parsing and populates `RootPassword=` with the output
2266 on stdout. This can be used to randomly generate a password and can
2267 be remembered by outputting it to stderr or by reading `$MKOSI_CONFIG`
2268 in another script (e.g. `mkosi.postoutput`). Note that this script is
2269 executed on the host system without any sandboxing.
2270
2271 If a script uses the `.chroot` extension, **mkosi** will chroot into the
2272 image using **mkosi-chroot** (see below) before executing the script. For
2273 example, if `mkosi.postinst.chroot` exists, **mkosi** will chroot into the
2274 image and execute it as the post-installation script.
2275
2276 Instead of a single file script, **mkosi** will also read all files in lexicographical order from appropriately
2277 named `.d` directories, e.g. all files in a `mkosi.build.d` would be used as build scripts. This is supported
2278 by
2279
2280 * `mkosi.sync.d`,
2281 * `mkosi.prepare.d`,
2282 * `mkosi.build.d`,
2283 * `mkosi.postinst.d`,
2284 * `mkosi.finalize.d`,
2285 * `mkosi.postoutput.d`, and
2286 * `mkosi.clean.d`.
2287
2288 This can be combined with the `.chroot` extension, e.g. `mkosi.build.d/01-foo.sh` would be run without
2289 chrooting into the image and `mkosi.build.d/02-bar.sh.chroot` would be run after chrooting into the image
2290 first.
2291
2292 Scripts executed by **mkosi** receive the following environment variables:
2293
2294 * `$ARCHITECTURE` contains the architecture from the `Architecture=`
2295 setting. If `Architecture=` is not set, it will contain the native
2296 architecture of the host machine. See the documentation of
2297 `Architecture=` for possible values for this variable.
2298
2299 * `$QEMU_ARCHITECTURE` contains the architecture from `$ARCHITECTURE` in
2300 the format used by **qemu**. Useful for finding the qemu binary (
2301 `qemu-system-$QEMU_ARCHITECTURE`).
2302
2303 * `$DISTRIBUTION` contains the distribution from the `Distribution=` setting.
2304
2305 * `$RELEASE` contains the release from the `Release=` setting.
2306
2307 * `$DISTRIBUTION_ARCHITECTURE` contains the architecture from
2308 `$ARCHITECTURE` in the format used by the configured distribution.
2309
2310 * `$PROFILES` contains the profiles from the `Profiles=` setting as a
2311 comma-delimited string.
2312
2313 * `$CACHED=` is set to `1` if a cached image is available, `0` otherwise.
2314
2315 * `$CHROOT_SCRIPT` contains the path to the running script relative to
2316 the image root directory. The primary usecase for this variable is in
2317 combination with the **mkosi-chroot** script. See the description of
2318 **mkosi-chroot** below for more information.
2319
2320 * `$SRCDIR` contains the path to the directory **mkosi** was invoked from,
2321 with any configured build sources mounted on top. `$CHROOT_SRCDIR`
2322 contains the value that `$SRCDIR` will have after invoking
2323 **mkosi-chroot**.
2324
2325 * `$BUILDDIR` is only defined if `mkosi.builddir` exists and points to
2326 the build directory to use. This is useful for all build systems that
2327 support out-of-tree builds to reuse already built artifacts from
2328 previous runs. `$CHROOT_BUILDDIR` contains the value that `$BUILDDIR`
2329 will have after invoking **mkosi-chroot**.
2330
2331 * `$DESTDIR` is a directory into which any installed software generated
2332 by a build script may be placed. This variable is only set when
2333 executing a build script. `$CHROOT_DESTDIR` contains the value that
2334 `$DESTDIR` will have after invoking **mkosi-chroot**.
2335
2336 * `$OUTPUTDIR` points to the staging directory used to store build
2337 artifacts generated during the build. `$CHROOT_OUTPUTDIR` contains the
2338 value that `$OUTPUTDIR` will have after invoking **mkosi-chroot**.
2339
2340 * `$PACKAGEDIR` points to the directory containing the local package
2341 repository. Build scripts can add more packages to the local
2342 repository by writing the packages to `$PACKAGEDIR`.
2343
2344 * `$ARTIFACTDIR` points to the directory that is used to pass around build
2345 artifacts generated during the build and make them available for use by
2346 mkosi. This is similar to `PACKAGEDIR`, but is meant for artifacts that may
2347 not be packages understood by the package manager, e.g. initrds created by
2348 other initrd generators than mkosi. Build scripts can add more artifacts to
2349 the directory by placing them in `$ARTIFACTDIR`. Files in this directory are
2350 only available for the current build and are not copied out like the contents
2351 of `$OUTPUTDIR`.
2352
2353 **mkosi** will also use certain subdirectories of an artifacts directory to
2354 automatically use their contents at certain steps. Currently the following
2355 two subdirectories in the artifact directory are used by mkosi:
2356 - `io.mkosi.microcode`: All files in this directory are used as microcode
2357 files, i.e. they are prepended to the initrds in lexicographical order.
2358 - `io.mkosi.initrd`: All files in this directory are used as initrds and
2359 joined in lexicographical order.
2360
2361 It is recommended, that users of `$ARTIFACTDIR` put things for their own use in a
2362 similar namespaced directory, e.g. `local.my.namespace`.
2363
2364 * `$BUILDROOT` is the root directory of the image being built,
2365 optionally with the build overlay mounted on top depending on the
2366 script that's being executed.
2367
2368 * `$WITH_DOCS` is either `0` or `1` depending on whether a build
2369 without or with installed documentation was requested
2370 (`WithDocs=yes`). A build script should suppress installation of
2371 any package documentation to `$DESTDIR` in case `$WITH_DOCS` is set
2372 to `0`.
2373
2374 * `$WITH_TESTS` is either `0` or `1` depending on whether a build
2375 without or with running the test suite was requested
2376 (`WithTests=no`). A build script should avoid running any unit or
2377 integration tests in case `$WITH_TESTS` is `0`.
2378
2379 * `$WITH_NETWORK` is either `0` or `1` depending on whether a build
2380 without or with networking is being executed (`WithNetwork=no`).
2381 A build script should avoid any network communication in case
2382 `$WITH_NETWORK` is `0`.
2383
2384 * `$SOURCE_DATE_EPOCH` is defined if requested (`SourceDateEpoch=TIMESTAMP`,
2385 `Environment=SOURCE_DATE_EPOCH=TIMESTAMP` or the host environment variable
2386 `$SOURCE_DATE_EPOCH`). This is useful to make builds reproducible. See
2387 [SOURCE_DATE_EPOCH](https://reproducible-builds.org/specs/source-date-epoch/)
2388 for more information.
2389
2390 * `$MKOSI_UID` and `$MKOSI_GID` respectively are the uid, gid of the
2391 user that invoked mkosi.
2392
2393 * `$MKOSI_CONFIG` is a file containing a json summary of the settings of the
2394 current image. This file can be parsed inside scripts to gain access to all
2395 settings for the current image.
2396
2397 * `$IMAGE_ID` contains the identifier from the `ImageId=` or `--image-id=` setting.
2398
2399 * `$IMAGE_VERSION` contains the version from the `ImageVersion=` or `--image-version=` setting.
2400
2401 Consult this table for which script receives which environment variables:
2402
2403 | Variable | `configure` | `sync` | `prepare` | `build` | `postinst` | `finalize` | `postoutput` | `clean` |
2404 |-----------------------------|:-----------:|:------:|:---------:|:-------:|:----------:|:----------:|:------------:|:-------:|
2405 | `ARCHITECTURE` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2406 | `QEMU_ARCHITECTURE` | ✓ | | | | | | | |
2407 | `DISTRIBUTION` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2408 | `DISTRIBUTION_ARCHITECTURE` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2409 | `RELEASE` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2410 | `PROFILES` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ✓ |
2411 | `CACHED` | | ✓ | | | | | | |
2412 | `CHROOT_SCRIPT` | | | ✓ | ✓ | ✓ | ✓ | | |
2413 | `SRCDIR` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2414 | `CHROOT_SRCDIR` | | | ✓ | ✓ | ✓ | ✓ | | |
2415 | `BUILDDIR` | | | | ✓ | ✓ | ✓ | | |
2416 | `CHROOT_BUILDDIR` | | | | ✓ | | | | |
2417 | `DESTDIR` | | | | ✓ | | | | |
2418 | `CHROOT_DESTDIR` | | | | ✓ | | | | |
2419 | `OUTPUTDIR` | | | | | ✓ | ✓ | ✓ | ✓ |
2420 | `CHROOT_OUTPUTDIR` | | | | | ✓ | ✓ | | |
2421 | `BUILDROOT` | | | ✓ | ✓ | ✓ | ✓ | | |
2422 | `PACKAGEDIR` | | | ✓ | ✓ | ✓ | ✓ | | |
2423 | `ARTIFACTDIR` | | | ✓ | ✓ | ✓ | ✓ | | |
2424 | `WITH_DOCS` | | | ✓ | ✓ | | | | |
2425 | `WITH_TESTS` | | | ✓ | ✓ | | | | |
2426 | `WITH_NETWORK` | | | ✓ | ✓ | ✓ | ✓ | | |
2427 | `SOURCE_DATE_EPOCH` | | | ✓ | ✓ | ✓ | ✓ | | ✓ |
2428 | `MKOSI_UID` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2429 | `MKOSI_GID` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2430 | `MKOSI_CONFIG` | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2431 | `IMAGE_ID` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2432 | `IMAGE_VERSION` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2433
2434 Additionally, when a script is executed, a few scripts are made
2435 available via `$PATH` to simplify common usecases.
2436
2437 * **mkosi-chroot**: This script will chroot into the image and execute the
2438 given command. On top of chrooting into the image, it will also mount
2439 various files and directories (`$SRCDIR`, `$DESTDIR`, `$BUILDDIR`,
2440 `$OUTPUTDIR`, `$CHROOT_SCRIPT`) into the image and modify the
2441 corresponding environment variables to point to the locations inside
2442 the image. It will also mount APIVFS filesystems (`/proc`, `/dev`,
2443 ...) to make sure scripts and tools executed inside the chroot work
2444 properly. It also propagates `/etc/resolv.conf` from the host into the
2445 chroot if requested so that DNS resolution works inside the chroot.
2446 After the mkosi-chroot command exits, various mount points are cleaned
2447 up.
2448
2449 For example, to invoke **ls** inside of the image, use the following:
2450
2451 ```sh
2452 mkosi-chroot ls ...
2453 ```
2454
2455 To execute the entire script inside the image, add a `.chroot` suffix
2456 to the name (`mkosi.build.chroot` instead of `mkosi.build`, etc.).
2457
2458 * For all of the supported package managers (**dnf**, **rpm**, **apt**, **dpkg**,
2459 **pacman**, **zypper**), scripts of the same name are put into `$PATH`
2460 that make sure these commands operate on the image's root directory
2461 with the configuration supplied by the user instead of on the host
2462 system. This means that from a script, you can do e.g.
2463 `dnf install vim` to install vim into the image.
2464
2465 Additionally, `mkosi-install`, `mkosi-reinstall`, `mkosi-upgrade` and
2466 `mkosi-remove` will invoke the corresponding operation of the package
2467 manager being used to built the image.
2468
2469 * **git** is automatically invoked with `safe.directory=*` to avoid
2470 permissions errors when running as the root user in a user namespace.
2471
2472 * **useradd** and **groupadd** are automatically invoked with
2473 `--root=$BUILDROOT` when executed outside of the image.
2474
2475 When scripts are executed, any directories that are still writable are
2476 also made read-only (`/home`, `/var`, `/root`, ...) and only the minimal
2477 set of directories that need to be writable remain writable. This is to
2478 ensure that scripts can't mess with the host system when **mkosi** is
2479 running as root.
2480
2481 Note that when executing scripts, all source directories are made
2482 ephemeral which means all changes made to source directories while
2483 running scripts are thrown away after the scripts finish executing. Use
2484 the output, build or cache directories if you need to persist data
2485 between builds.
2486
2487 # Files
2488
2489 To make it easy to build images for development versions of your
2490 projects, **mkosi** can read configuration data from the local directory,
2491 under the assumption that it is invoked from a *source*
2492 tree. Specifically, the following files are used if they exist in the
2493 local directory:
2494
2495 * The **`mkosi.skeleton/`** directory or **`mkosi.skeleton.tar`**
2496 archive may be used to insert files into the image. The files are
2497 copied *before* the distribution packages are installed into the
2498 image. This allows creation of files that need to be provided
2499 early, for example to configure the package manager or set systemd
2500 presets.
2501
2502 When using the directory, file ownership is not preserved: all files
2503 copied will be owned by root. To preserve ownership, use a tar
2504 archive.
2505
2506 * The **`mkosi.extra/`** directory or **`mkosi.extra.tar`** archive
2507 may be used to insert additional files into the image, on top of
2508 what the distribution includes in its packages. They are similar to
2509 `mkosi.skeleton/` and `mkosi.skeleton.tar`, but the files are copied
2510 into the directory tree of the image *after* the OS was installed.
2511
2512 When using the directory, file ownership is not preserved: all files
2513 copied will be owned by root. To preserve ownership, use a tar
2514 archive.
2515
2516 * The **`mkosi.sandbox/`** directory or **`mkosi.sandbox.tar`** archive
2517 may be used to configure the package manager without the files being
2518 inserted into the image. If the files should be included in the image
2519 `mkosi.skeleton/` and `mkosi.skeleton.tar` should be used instead.
2520
2521 When using the directory, file ownership is not preserved: all files
2522 copied will be owned by root. To preserve ownership, use a tar
2523 archive.
2524
2525 * The **`mkosi.nspawn`** nspawn settings file will be copied into the same place as the output image file, if
2526 it exists. This is useful since nspawn looks for settings files next to image files it boots, for
2527 additional container runtime settings.
2528
2529 * The **`mkosi.cache/`** directory, if it exists, is automatically used as package download cache, in order
2530 to speed repeated runs of the tool.
2531
2532 * The **`mkosi.builddir/`** directory, if it exists, is automatically used as out-of-tree build directory, if
2533 the build commands in the `mkosi.build` scripts support it. Specifically, this directory will be mounted
2534 into the build container, and the `$BUILDDIR` environment variable will be set to it when the build scripts
2535 are invoked. A build script may then use this directory as build directory, for **automake**-style or
2536 **ninja**-style out-of-tree builds. This speeds up builds considerably, in particular when **mkosi** is used in
2537 incremental mode (`-i`): not only the image and build overlay, but also the build tree is reused between
2538 subsequent invocations. Note that if this directory does not exist the `$BUILDDIR` environment variable is
2539 not set, and it is up to the build scripts to decide whether to do an in-tree or an out-of-tree build, and
2540 which build directory to use.
2541
2542 * The **`mkosi.rootpw`** file can be used to provide the password for the root user of the image. If the
2543 password is prefixed with `hashed:` it is treated as an already hashed root password. The password may
2544 optionally be followed by a newline character which is implicitly removed. The file must have an access
2545 mode of 0600 or less. If this file does not exist, the distribution's default root password is set (which
2546 usually means access to the root user is blocked).
2547
2548 * The **`mkosi.passphrase`** file provides the passphrase to use when
2549 LUKS encryption is selected. It should contain the passphrase
2550 literally, and not end in a newline character (i.e. in the same
2551 format as **cryptsetup** and `/etc/crypttab` expect the passphrase
2552 files). The file must have an access mode of 0600 or less.
2553
2554 * The **`mkosi.crt`** and **`mkosi.key`** files contain an X.509 certificate and PEM private key to use when
2555 signing is required (UEFI SecureBoot, verity, ...).
2556
2557 * The **`mkosi.output/`** directory is used to store all build
2558 artifacts.
2559
2560 * The **`mkosi.credentials/`** directory is used as a
2561 source of extra credentials similar to the `Credentials=` option. For
2562 each file in the directory, the filename will be used as the credential
2563 name and the file contents become the credential value, or, if the file is
2564 executable, **mkosi** will execute the file and the command's
2565 output to stdout will be used as the credential value. Output to stderr will be ignored.
2566 Credentials configured with `Credentials=` take precedence over files in `mkosi.credentials`.
2567
2568 * The **`mkosi.repart/`** directory is used as the source for
2569 **systemd-repart** partition definition files which are passed to
2570 **systemd-repart** when building a disk image. If it does not exist and
2571 the `RepartDirectories=` setting is not configured, **mkosi** will default
2572 to the following partition definition files:
2573
2574 `00-esp.conf` (if we're building a bootable image):
2575
2576 ```ini
2577 [Partition]
2578 Type=esp
2579 Format=vfat
2580 CopyFiles=/boot:/
2581 CopyFiles=/efi:/
2582 SizeMinBytes=512M
2583 SizeMaxBytes=512M
2584 ```
2585
2586 `05-bios.conf` (if we're building a BIOS bootable image):
2587
2588 ```ini
2589 [Partition]
2590 # UUID of the grub BIOS boot partition which grubs needs on GPT to
2591 # embed itself into.
2592 Type=21686148-6449-6e6f-744e-656564454649
2593 SizeMinBytes=1M
2594 SizeMaxBytes=1M
2595 ```
2596
2597 `10-root.conf`
2598
2599 ```ini
2600 [Partition]
2601 Type=root
2602 Format=<distribution-default-filesystem>
2603 CopyFiles=/
2604 Minimize=guess
2605 ```
2606
2607 Note that if either `mkosi.repart/` is found or `RepartDirectories=`
2608 is used, we will not use any of the default partition definitions.
2609
2610 All these files are optional.
2611
2612 Note that the location of all these files may also be configured
2613 during invocation via command line switches, and as settings in
2614 `mkosi.conf`, in case the default settings are not acceptable for a
2615 project.
2616
2617 # CACHING
2618
2619 **mkosi** supports three different caches for speeding up repetitive
2620 re-building of images. Specifically:
2621
2622 1. The package cache of the distribution package manager may be cached
2623 between builds. This is configured with the `--cache-directory=` option
2624 or the `mkosi.cache/` directory. This form of caching relies on the
2625 distribution's package manager, and caches distribution packages
2626 (RPM, deb, …) after they are downloaded, but before they are
2627 unpacked.
2628
2629 2. If the incremental build mode is enabled with `--incremental`, cached
2630 copies of the final image and build overlay are made immediately
2631 before the build sources are copied in (for the build overlay) or the
2632 artifacts generated by `mkosi.build` are copied in (in case of the
2633 final image). This form of caching allows bypassing the time-consuming
2634 package unpacking step of the distribution package managers, but is only
2635 effective if the list of packages to use remains stable, but the build
2636 sources and its scripts change regularly. Note that this cache requires
2637 manual flushing: whenever the package list is modified the cached
2638 images need to be explicitly removed before the next re-build,
2639 using the `-f` switch.
2640
2641 3. Finally, between multiple builds the build artifact directory may
2642 be shared, using the `mkosi.builddir/` directory. This directory
2643 allows build systems such as Meson to reuse already compiled
2644 sources from a previous built, thus speeding up the build process
2645 of a `mkosi.build` build script.
2646
2647 The package cache and incremental mode are unconditionally useful. The
2648 final cache only apply to uses of **mkosi** with a source tree and build
2649 script. When all three are enabled together turn-around times for
2650 complete image builds are minimal, as only changed source files need to
2651 be recompiled.
2652
2653 # Building multiple images
2654
2655 If the `mkosi.images/` directory exists, **mkosi** will load individual
2656 subimage configurations from it and build each of them. Image
2657 configurations can be either directories containing **mkosi** configuration
2658 files or regular files with the `.conf` extension.
2659
2660 When image configurations are found in `mkosi.images/`, **mkosi** will build
2661 the images specified in the `Dependencies=` setting of the main image
2662 and all of their dependencies (or all of them if no images were
2663 explicitly configured using `Dependencies=` in the main image
2664 configuration). To add dependencies between subimages, the
2665 `Dependencies=` setting can be used as well. Subimages are always built
2666 before the main image.
2667
2668 When images are defined, **mkosi** will first read the main image
2669 configuration (configuration outside of the `mkosi.images/` directory),
2670 followed by the image specific configuration. Several "universal"
2671 settings apply to the main image and all its subimages and cannot be
2672 configured separately in subimages. The following settings are universal
2673 and cannot be configured in subimages:
2674
2675 - `Architecture=`
2676 - `BuildDirectory=`
2677 - `BuildSources=`
2678 - `BuildSourcesEphemeral=`
2679 - `CacheDirectory=`
2680 - `CacheOnly=`
2681 - `Distribution=`
2682 - `ExtraSearchPaths=`
2683 - `Incremental=`
2684 - `LocalMirror=`
2685 - `Mirror=`
2686 - `OutputDirectory=`
2687 - `OutputMode=`
2688 - `PackageCacheDirectory=`
2689 - `PackageDirectories=`
2690 - `Profiles=`
2691 - `ProxyClientCertificate=`
2692 - `ProxyClientKey=`
2693 - `ProxyExclude=`
2694 - `ProxyPeerCertificate=`
2695 - `ProxyUrl=`
2696 - `Release=`
2697 - `RepartOffline=`
2698 - `Repositories=`
2699 - `RepositoryKeyCheck=`
2700 - `SandboxTrees=`
2701 - `SourceDateEpoch=`
2702 - `ToolsTree=`
2703 - `ToolsTreeCertificates=`
2704 - `UseSubvolumes=`
2705 - `SecureBootCertificate=`
2706 - `SecureBootCertificateSource=`
2707 - `SecureBootKey=`
2708 - `SecureBootKeySource=`
2709 - `VerityCertificate=`
2710 - `VerityCertificateSource=`
2711 - `VerityKey=`
2712 - `VerityKeySource=`
2713 - `SignExpectedPcrCertificate=`
2714 - `SignExpectedPcrCertificateSource=`
2715 - `SignExpectedPcrKey=`
2716 - `SignExpectedPcrKeySource=`
2717 - `VolatilePackageDirectories=`
2718 - `WithNetwork=`
2719 - `WithTests`
2720 - `WorkspaceDirectory=`
2721
2722 There are also settings which are passed down to subimages but can
2723 be overridden. For these settings, values configured explicitly in
2724 the subimage will take priority over values configured on the CLI or
2725 in the main image config. Currently the following settings are passed
2726 down to subimages but can be overridden:
2727
2728 - `ImageId=`
2729 - `ImageVersion=`
2730 - `SectorSize=`
2731
2732 Images can refer to outputs of images they depend on. Specifically,
2733 for the following options, **mkosi** will only check whether the inputs
2734 exist just before building the image:
2735
2736 - `BaseTrees=`
2737 - `ExtraTrees=`
2738 - `Initrds=`
2739
2740 To refer to outputs of a image's dependencies, simply configure any of
2741 these options with a relative path to the output to use in the output
2742 directory of the dependency. Or use the `%O` specifier to refer to the
2743 output directory.
2744
2745 A good example on how to build multiple images can be found in the
2746 [systemd](https://github.com/systemd/systemd/tree/main/mkosi.images)
2747 repository.
2748
2749 # ENVIRONMENT VARIABLES
2750
2751 * `$MKOSI_LESS` overrides options for **less** when it is invoked by
2752 **mkosi** to page output.
2753
2754 * `$MKOSI_DNF` can be used to override the executable used as **dnf**.
2755 This is particularly useful to select between **dnf** and **dnf5**.
2756
2757 * `$EPEL_MIRROR` can be used to override the default mirror location
2758 used for the epel repositories when `Mirror=` is used. By default
2759 **mkosi** looks for the epel repositories in the `fedora` subdirectory of
2760 the parent directory of the mirror specified in `Mirror=`. For example
2761 if the mirror is set to `https://mirror.net/centos-stream` **mkosi** will
2762 look for the epel repositories in `https://mirror.net/fedora/epel`.
2763
2764 * `SYSEXT_SCOPE` and `CONFEXT_SCOPE` can be used to override the default
2765 value of the respective `extension-release` file when building a sysext
2766 or confext. By default the value is set to `initrd system portable`.
2767
2768 # EXAMPLES
2769
2770 Create and run a raw *GPT* image with *ext4*, as `image.raw`:
2771
2772 ```console
2773 # mkosi -p systemd --incremental boot
2774 ```
2775
2776 Create and run a bootable *GPT* image, as `foobar.raw`:
2777
2778 ```console
2779 $ mkosi -d fedora -p kernel-core -p systemd -p systemd-boot -p udev -o foobar.raw
2780 # mkosi --output foobar.raw boot
2781 $ mkosi --output foobar.raw vm
2782 ```
2783
2784 Create and run a *Fedora Linux* image in a plain directory:
2785
2786 ```console
2787 # mkosi --distribution fedora --format directory boot
2788 ```
2789
2790 Create a compressed image `image.raw.xz` with SSH installed and add a checksum file:
2791
2792 ```console
2793 $ mkosi --distribution fedora --format disk --checksum --compress-output --package=openssh-clients
2794 ```
2795
2796 Inside the source directory of an **automake**-based project, configure
2797 **mkosi** so that simply invoking **mkosi** without any parameters builds
2798 an OS image containing a built version of the project in its current
2799 state:
2800
2801 ```console
2802 $ cat >mkosi.conf <<EOF
2803 [Distribution]
2804 Distribution=fedora
2805
2806 [Output]
2807 Format=disk
2808
2809 [Content]
2810 Packages=kernel,systemd,systemd-udev,openssh-clients,httpd
2811 BuildPackages=make,gcc,libcurl-devel
2812 EOF
2813 $ cat >mkosi.build <<EOF
2814 #!/bin/sh
2815
2816 if [ "$container" != "mkosi" ]; then
2817 exec mkosi-chroot "$CHROOT_SCRIPT" "$@"
2818 fi
2819
2820 cd $SRCDIR
2821 ./autogen.sh
2822 ./configure --prefix=/usr
2823 make -j `nproc`
2824 make install
2825 EOF
2826 $ chmod +x mkosi.build
2827 # mkosi --incremental boot
2828 # systemd-nspawn -bi image.raw
2829 ```
2830
2831 ## Different ways to boot with `vm`
2832
2833 The easiest way to boot a virtual machine is to build an image with the
2834 required components and let **mkosi** call **qemu** with all the right options:
2835 ```console
2836 $ mkosi -d fedora \
2837 --autologin \
2838 -p systemd-udev,systemd-boot,kernel-core \
2839 build
2840 $ mkosi -d fedora vm
2841 ...
2842 fedora login: root (automatic login)
2843 [root@fedora ~]#
2844 ```
2845
2846 The default is to boot with a text console only.
2847 In this mode, messages from the boot loader, the kernel, and systemd,
2848 and later the **getty** login prompt and shell all use the same terminal.
2849 It is possible to switch between the **qemu** console and monitor
2850 by pressing `Ctrl-a c`.
2851 The **qemu** monitor may for example be used to inject special keys
2852 or shut down the machine quickly. Alternatively the machine can be shut down
2853 using `Ctrl-a x`.
2854
2855 To boot with a graphical window, add `--console=gui`:
2856 ```console
2857 $ mkosi -d fedora --console=gui qemu
2858 ```
2859
2860 A kernel may be booted directly with
2861 `mkosi vm -kernel ... -initrd ... -append '...'`.
2862 This is a bit faster because no boot loader is used, and it is also
2863 easier to experiment with different kernels and kernel commandlines.
2864 Note that despite the name, **qemu**'s `-append` option replaces
2865 the default kernel commandline embedded in the kernel
2866 and any previous `-append` specifications.
2867
2868 The UKI is also copied into the output directory and may be booted directly:
2869 ```console
2870 $ mkosi vm -kernel mkosi.output/fedora~38/image.efi
2871 ```
2872
2873 When booting using an external kernel, we don't need the kernel *in* the image,
2874 but we would still want the kernel modules to be installed.
2875
2876 It is also possible to do a *direct kernel boot* into a boot loader,
2877 taking advantage of the fact that **systemd-boot**(7) is a valid UEFI binary:
2878 ```console
2879 $ mkosi vm -kernel /usr/lib/systemd/boot/efi/systemd-bootx64.efi
2880 ```
2881 In this scenario, the kernel is loaded from the ESP in the image by **systemd-boot**.
2882
2883 # REQUIREMENTS
2884
2885 mkosi is packaged for various distributions: Debian, Kali, Ubuntu, Arch
2886 Linux, Fedora Linux, OpenMandriva, Gentoo. Note that it has been a while
2887 since the last release and the packages shipped by distributions are
2888 very out of date. We currently recommend running **mkosi** from git until a
2889 new release happens.
2890
2891 mkosi requires a Linux kernel that provides `mount_setattr()` which was introduces in 5.12.
2892
2893 mkosi currently requires systemd 254 to build bootable disk images.
2894
2895 When not using distribution packages make sure to install the
2896 necessary dependencies. For example, on *Fedora Linux* you need:
2897
2898 ```bash
2899 # dnf install btrfs-progs apt dosfstools mtools edk2-ovmf e2fsprogs squashfs-tools gnupg python3 tar xfsprogs xz zypper sbsigntools
2900 ```
2901
2902 On Debian/Kali/Ubuntu it might be necessary to install the `ubuntu-keyring`,
2903 `ubuntu-archive-keyring`, `kali-archive-keyring` and/or `debian-archive-keyring`
2904 packages explicitly, in addition to **apt**, depending on what kind of distribution
2905 images you want to build.
2906
2907 Note that the minimum required Python version is 3.9.
2908
2909 mkosi needs unrestricted abilities to create and act within namespaces. Some
2910 distros restrict creation of, or capabilities within, user namespaces, which
2911 breaks mkosi.
2912
2913 For information about Ubuntu, that implements such restrictions using AppArmor, see
2914 https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces.
2915 For other systems, try researching the `kernel.unprivileged_userns_clone` or
2916 `user.max.user_namespace` sysctls.
2917
2918 For Ubuntu systems, you can remove the restrictions for **mkosi** by
2919 adapting this snippet to point to your **mkosi** binary, copying it to
2920 `/etc/apparmor.d/path.to.mkosi`, and then running `systemctl reload apparmor`:
2921
2922 ```
2923 abi <abi/4.0>,
2924
2925 include <tunables/global>
2926
2927 /path/to/mkosi flags=(default_allow) {
2928 userns,
2929 }
2930 ```
2931
2932 # Frequently Asked Questions (FAQ)
2933
2934 - Why does `mkosi vm` with KVM not work on Debian/Kali/Ubuntu?
2935
2936 While other distributions are OK with allowing access to `/dev/kvm`, on
2937 Debian/Kali/Ubuntu this is only allowed for users in the `kvm` group. Because
2938 **mkosi** unshares a user namespace when running unprivileged, even if the
2939 calling user was in the kvm group, when **mkosi** unshares the user
2940 namespace to run unprivileged, it loses access to the `kvm` group and by
2941 the time we start **qemu** we don't have access to `/dev/kvm` anymore. As
2942 a workaround, you can change the permissions of the device nodes to
2943 `0666` which is sufficient to make KVM work unprivileged. To persist
2944 these settings across reboots, copy
2945 `/usr/lib/tmpfiles.d/static-nodes-permissions.conf` to
2946 `/etc/tmpfiles.d/static-nodes-permissions.conf` and change the mode of
2947 `/dev/kvm` from `0660` to `0666`.
2948
2949 - How do I add a regular user to an image?
2950
2951 You can use the following snippet in a post-installation script:
2952
2953 ```sh
2954 useradd --create-home --user-group $USER --password "$(openssl passwd -stdin -6 <$USER_PASSWORD_FILE)"
2955 ```
2956
2957 Note that from systemd v256 onwards, if enabled,
2958 **systemd-homed-firstboot.service** will prompt to create a regular user
2959 on first boot if there are no regular users.
2960
2961 - Why do I see failures to chown files when building images?
2962
2963 When not running as root, your user is not able to change ownership of
2964 files to arbitrary owners. Various distributions still ship files in their
2965 packages that are not owned by the root user. When not running as root, mkosi
2966 maps the current user to root when invoking package managers, which means that
2967 changing ownership to root will work but changing ownership to any other user
2968 or group will fail.
2969
2970 Note that chown calls are only suppressed when running package managers, but
2971 not when running scripts. If this is required, e.g. for a build script, you
2972 can set the `MKOSI_CHROOT_SUPPRESS_CHOWN` variable to a true value (`1`,
2973 `yes`, `true`) to suppress chown calls in **mkosi-chroot** and `.chroot` scripts.
2974
2975 If this behavior causes applications running in your image to misbehave, you
2976 can consider running **mkosi** as root which avoids this problem. Alternatively,
2977 if running **mkosi** as root is not desired, you can use
2978 `unshare --map-auto --map-current-user --setuid 0 --setgid 0` to become root in
2979 a user namespace with more than one user assuming the UID/GID mappings in
2980 `/etc/subuid` and `/etc/subgid` are configured correctly. Note that running mkosi
2981 as root or with `unshare` means that all output files produced by **mkosi** will not
2982 be owned by your current user anymore.
2983
2984 Note that for systemd services that need directories in `/var` owned by the service
2985 user and group, an alternative to shipping these directories in packages or
2986 creating them via systemd-tmpfiles is to use `StateDirectory=`, `CacheDirectory=` or
2987 `LogsDirectory=` in the service file which instructs systemd to create the directory
2988 when it first starts the service.
2989
2990 Alternatively, the `z` or `Z` directives for `systemd-tmpfiles` can be used to chown
2991 various directories and files to their owning user when the system first boots up.
2992
2993 - Why does `portablectl inspect <image>`/`systemd-dissect <image>` say my portable service isn't one?
2994
2995 `systemd-dissect` and`portablectl inspect` check for `PORTABLE_PREFIXES=` in `os-release` and if the key is
2996 missing, will fail to recognise a portable service as one, showing ✗ under *Use as* for in the case of
2997 `systemd-dissect` or `n/a` under *Portable Service* for `portablectl`.
2998
2999 Since there is no good default to set for this key and the generated portable service images will still
3000 attach properly, even when the key is not set, **mkosi** doesn't set one.
3001
3002 You can set `PORTABLE_PREFIXES=` in the `os-release` file yourself in a postinst script.
3003
3004 # REFERENCES
3005 * [Primary mkosi git repository on GitHub](https://github.com/systemd/mkosi/)
3006 * [mkosi — A Tool for Generating OS Images](https://0pointer.net/blog/mkosi-a-tool-for-generating-os-images.html) introductory blog post by Lennart Poettering
3007 * [The mkosi OS generation tool](https://lwn.net/Articles/726655/) story on LWN
3008
3009 # SEE ALSO
3010 **systemd-nspawn**(1), **systemd-repart**(8), **dnf**(8)