Rework firmware-list settings to use globs instead of regexps
This mirrors the change to module-list options. The two FirmwareInclude/FirmwareExclude
options are replaced by one FirmwareFiles option that takes positive and negative
globs. (Firmware name is already taken.)
This creates the following difference:
-usr/lib/modules/6.14.0-0.rc1.15.fc42.x86_64/kernel/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/ch_ipsec.ko.xz
-usr/lib/modules/6.14.0-0.rc1.15.fc42.x86_64/kernel/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/ch_ktls.ko.xz
In the previous syntax, we included those modules accidentally because
'inline_crypto/' matches 'crypto/'.
Rework module-list settings to use globs instead of regexps
"If you have a problem, and use a regexp, now you have two problems."
I don't think this quip applies in all cases, but the existing interface with
regexps was problematic for a few reasons:
- users usually want to match at a word boundary, but regexps apply anywhere in
the string, so to actually match correctly, the regexp has to be carefully
constructed with word boundary assertions.
Even our own config for initrds included some modules by mistake,
e.g. drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/ch_ipsec.ko.xz
was matched by crypto/.
- once the regexps include the word boundary assertions, they became quite
complex and hard to read.
- because of the separate evaluation of include and exlude patterns, we
need to have exclude patterns in the include patterns. The example given
in the review:
^drivers/net/(?!wireless/)
But this means that we can do exclusions in two places, making the whole
scheme very complex.
- the default to include all modules by default goes against the general
design of mkosi, where only things that are explicitly configured are
put in the image. That default is only useful when trying to build a
"maximal" image that matches the current machine. In most uses, the
default of including only requested modules makes more sense (initrd,
addons, any not-host-only images).
A new setting that takes glob patterns is added. There is only one setting
instead of a pair, exclusion patterns are prefixed by '-'. The last matching
glob wins. The details of how those globs are interpreted is crafted to
match our particular use cases.
For a single glob, the rules are:
- 'foo' matches the basename, /some/path/foo.ko
- 'bar/foo' matches the last component of the path, bar/foo.ko
- '/full/path/bar' only matches /full/path/bar.ko.
- crypto/* or crypto/ match all modules any crypto/ directory.
- /crypto/* matches the modules in the top-level directory.
This might seem complicated at first glance, but apart from the special
handling of the suffix, those rules mostly match how 'ls' would handle
a local path argument.
Suffixes are not specified in the globs. '-' and '_' are treated as equivalent,
except when part of special glob syntax with […].
New settings are added:
KernelModules=GLOB
KernelInitrdModules=GLOB
(KernelModulesInitrd=BOOL already exists and specifies whether to create a
separate initrd.)
I think the new syntax is more pleasant to read and write. Backward
compatibility is maintained by keeping the old options in place. The change to
exclude all modules by default is a breaking change, but in most uses both
options were used in combination anyway, so I think this should be fine.
The example given in the review:
KernelModulesInclude=
^drivers/net/(?!wireless/)
becomes
KernelModules=
/drivers/net/
-/drivers/net/wireless/
Daan De Meyer [Thu, 13 Mar 2025 14:35:49 +0000 (15:35 +0100)]
fedora: Change default release to rawhide
Fedora releases new versions quite regularly, sometimes more regularly
than we do mkosi releases. This means that users on the latest official
mkosi release can end up building EOL fedora releases because the default
release will be the latest fedora release at the time of the mkosi release
which might be EOL already. Let's switch to rawhide as the default release
so users are guaranteed to get something recent regardless of how old their
mkosi version is.
This matches what we already do for debian, opensuse, arch and other distros.
Both styles were used by the existing code: ['--foo=bar'] and ['--foo', 'bar'].
Switch to the former exclusively. A single arg like '--foo=bar' is easier to
read and/or select&paste in the log output. Also, we avoid explicit str()
wrappers in a bunch of places.
Daan De Meyer [Tue, 11 Mar 2025 20:12:11 +0000 (21:12 +0100)]
Try to find volatile overlay upperdir directory that's not on overlayfs
Making a directory on overlayfs the upperdir of another overlayfs is
rejected by the kernel. Let's try to find a directory that's not on
overlayfs. The /dev/shm fallback is because on a default podman container
even /tmp is on overlayfs.
Daan De Meyer [Thu, 6 Mar 2025 22:47:33 +0000 (23:47 +0100)]
Rework --run-build-scripts
Instead of (optionally) building the image when this option is enabled,
let's insist that the image has already been built and cached. This allows
us to reuse the history of the previous build if History= is enabled. At
the same time, rename the option to --rerun-build-scripts to indicate more
clearly that the image needs to have been built once already.
This allows the option to be used in systemd's mkosi.clangd script to replace
"-t none" and "--incremental=strict" there.
Daan De Meyer [Wed, 5 Mar 2025 19:32:58 +0000 (20:32 +0100)]
Move package installation and removal to PackageManager interface
There's no need for these to be implemented by the Distribution
interface as they don't need distribution specific knowledge so let's
move them to the PackageManager interface instead.
Daan De Meyer [Wed, 5 Mar 2025 18:59:26 +0000 (19:59 +0100)]
debian: Install policy-rcd-declarative by default
Debian switched to systemd ages ago, but as we know legacy stuff
tends to linger in Debian for quite a while. Let's standardize on
using systemd presets to enable daemons by installing packages for
a deny-all policy for sysv-init style packages instead of messing
with the script ourselves.
Daan De Meyer [Tue, 4 Mar 2025 08:21:25 +0000 (09:21 +0100)]
centos: Handle major/minor releases in derivatives properly
While centos doesn't have major/minor releases, rocky, alma and rhel
do, so let's make sure we handle those cases properly.
Additionally, we also fix EPEL to use the proper major/minor release
when we're doing EPEL 10, as since EPEL 10 there's major/minor releases
for EPEL as well.
Septatrix [Sun, 2 Mar 2025 20:53:09 +0000 (21:53 +0100)]
Parse both mkosi.local.conf and mkosi.local/
This aligns more with what the users expects
and allows working around some limitations of the config system
(esp. regarding the interplay of `Include=` and `Profiles=`).
Enable only the initrd profiles specified with this option, rather than all by
default. This saves space and allows the user to choose only what is needed on
each system.
Daan De Meyer [Wed, 26 Feb 2025 13:42:12 +0000 (14:42 +0100)]
Implement build overlay mounting with mkosi-sandbox
Now that we have Context.rootoptions(), we can switch out how we set
up the root mount without having to modify code all over the place.
Let's use this to get rid of mount_build_overlay() and instead replace
it with setup_build_overlay(), which simply configures a bunch of
fields on Context that make rootoptions() set up the root mount as an
overlay instead of a bind mount.
Daan De Meyer [Wed, 26 Feb 2025 11:14:38 +0000 (12:14 +0100)]
Introduce --run-build-scripts (-R) to always run build scripts
Currently we run "mkosi -t none" in systemd and mkosi-kernel to run
the build script(s) without rebuilding the entire image. Using the
"none" output format for this purpose is a hack. It also breaks when
using History=yes as running mkosi -t none will change the output
format in the history after which running mkosi qemu will fail saying
it can't boot the "none" output format.
Let's introduce a --run-build-scripts argument which will make us always
run the build scripts regardless of whether the image has already been
built or not. At the same time, remove various behaviors from the "none"
format that were solely added to enable the hack of using it to run build
scripts without rebuilding the image:
- Clean up outputs from the previous build when the "none" output format
is used
Luca Boccassi [Tue, 25 Feb 2025 14:05:33 +0000 (14:05 +0000)]
mkosi-obs: support multiple mkosi.postoutput invocations
When multiple images are built mkosi.postoutput runs once
per image, so add access to output directory and ensure
the hashes.cpio.rsasign archive accumulates the hashes for
all images before proceeding to the next stage
Luca Boccassi [Tue, 25 Feb 2025 11:40:02 +0000 (11:40 +0000)]
mkosi-obs: fix compression detection
The recompress variable is not reset in the loop, so if
there is a compressed ddi and an uncompressed one, the
variable will be true for the second one. Reset it.
Daan De Meyer [Tue, 25 Feb 2025 17:46:16 +0000 (18:46 +0100)]
Enable Hyperscale rpm COW plugin
The CentOS Hyperscale SIG provides rpm/dnf plugins to enable rpm
COW which drastically speeds up image builds so let's ship the
necessary logic to make use of it when building images with the
Hyperscale experimental repositories.
Luca Boccassi [Tue, 25 Feb 2025 00:11:46 +0000 (00:11 +0000)]
mkosi-obs: sign bootloaders in ESPs
If there are bootloaders in the ESP(s), sign them too. Useful to
ensure everything is signed also with the certificate in the project
where the image is built.
Daan De Meyer [Sun, 23 Feb 2025 15:20:53 +0000 (16:20 +0100)]
Specify --suppress-sync when running package managers
Package managers tend to make sure of sync() and friends to ensure
that any files they write are actually written to disk. This is
important when a package manager is used to do system package upgrades,
but is unnecessary when using package managers to build OS images. So
let's make sync() and friends a noop when we invoke package managers
Daan De Meyer [Fri, 21 Feb 2025 09:57:39 +0000 (10:57 +0100)]
Reduce the number of filesystems we remount noexec/nosuid/nodev when root
For mkosi-initrd, /etc might very well contain executable scripts which
we should allow to run, so let's only mount /boot and /efi nodev/nosuid/noexec.
Philip Molloy [Thu, 20 Feb 2025 13:49:26 +0000 (14:49 +0100)]
README: Reference EXAMPLES and mkosi documentation
Generally, examples are a great way to get started with a new tool.
Additionally, there does not appear to be formal getting started
documentation for mkosi.
Daan De Meyer [Wed, 19 Feb 2025 14:21:18 +0000 (15:21 +0100)]
Clean up default tools tree package lists
- util-linux is not needed anymore since we do mounts ourselves now
- dpkg is pulled in by apt on arch and we don't list it explicitly elsewhere
- glibc-gconv-modules-extra should be pulled in by something else on opensuse by now
- python3-cryptography is only required on ubuntu, rest already has a dependency on
it in systemd-ukify or is already on systemd v257 which doesn't need it anymore
- libarchive-tools seems like a leftover that isn't installed anywhere else