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
Daan De Meyer [Wed, 19 Feb 2025 11:39:06 +0000 (12:39 +0100)]
mkosi-tools: Split off misc, package-manager and runtime profiles
Let's make the dependencies verb a little more flexible by splitting
off various profiles in mkosi-tools, the misc, package-manager and
runtime profiles. The misc profile contains all the useful tools we
install to make sure they're available in scripts. The package manager
contains non-native package managers and related tools. The runtime
profile contains all the tools required to boot images. The regular
configuration now only includes the tools required to build native images
with mkosi.
The default tools tree still includes both the misc, package-manager and
runtime profiles by default but the list of profiles can be changed with
the new ToolsTreeProfiles= setting. The dependencies verb includes neither
profile, but we now allow passing arbitrary settings to the dependency verb
as arguments so that packages from additional profiles can be requested if
needed.
Russell Bunch [Tue, 18 Feb 2025 16:58:52 +0000 (10:58 -0600)]
Search for underscores in `systemd-stub`
Building raw disk images of RHEL 9 x86-64 are failing with:
```
...‣ Unable to determine systemd-stub version, found '#### LoaderInfo: systemd-stub 252-46.el9_5.2 ####'
```
Changes the regex for `systemd-stub` to include underscores for RHEL95.
Daan De Meyer [Tue, 18 Feb 2025 10:06:43 +0000 (11:06 +0100)]
run: Wait for child process in try block in spawn()
If we only wait in finally block then any keyboard interrupt
triggered during the wait will leave the child process alive and
won't wait for it to exit. Let's make sure this doesn't happen by
waiting in the try block as well.
Daan De Meyer [Tue, 18 Feb 2025 09:44:11 +0000 (10:44 +0100)]
Drop boot counting support
Setting up boot counting for the initial UKI in an image does not
make sense as there's nothing to fall back to. The existing interface
where we pick up the number of tries from a file in /etc inside the
image was also rather bad so let's get rid of the boot counting
specifier.
Daan De Meyer [Sat, 15 Feb 2025 21:58:04 +0000 (22:58 +0100)]
Make sure we always delete workspace / "root" as a subvolume
Currently, we delete it as a subvolume if the build succeeds but not
if the build fails. Let's handle the deletion in setup_workspace() so
we delete it as a subvolume both on success and on failure.
Daan De Meyer [Fri, 14 Feb 2025 12:39:48 +0000 (13:39 +0100)]
Make Linux= support delayed specifiers
In mkosi-kernel, I want to add the following:
```
Linux=&b/kernel/arch/x86_64/boot/bzImage
```
So that I can run `mkosi -t none` to rebuild the kernel image and
`mkosi qemu` to boot into it. To make this work, let's add support
for a delayed specifier to Linux= that expands to the finalized
build directory.
Daan De Meyer [Thu, 13 Feb 2025 23:34:36 +0000 (00:34 +0100)]
Add BuildKey= and CacheKey= settings
Let's give users more control over how many different cache and
build subdirectories we maintain by introducing CacheKey= and
BuildKey= with support for delayed specifiers.
Daan De Meyer [Thu, 13 Feb 2025 21:23:41 +0000 (22:23 +0100)]
Move load_environment() into finalize_environment() method of Config
Let's stop showing all derived environment variables values in the
summary and let's stop passing them to the default tools and initrd
images since they'll be derived again there anyway.
Daan De Meyer [Thu, 13 Feb 2025 19:13:18 +0000 (20:13 +0100)]
docs: Various fixes
- Make sure we suffix all long CLI options with '='
- Make sure whenever we use a boolean option that we pass an argument
- Make sure we prefix with '--' whenever we pass extra arguments
Daan De Meyer [Thu, 13 Feb 2025 09:14:32 +0000 (10:14 +0100)]
Force ssh to use bash to run the ProxyCommand
We only have bash installed in the tools tree and by default ssh
will try to use the user's shell to execute the proxy command which
might not be available so force it use bash.
Daan De Meyer [Wed, 12 Feb 2025 09:49:59 +0000 (10:49 +0100)]
Require delimiting extra options for invoked commands with '--'
This is one of the biggest footguns when using mkosi so let's break
compat and fix it. Any options that should be passed to the command
invoked by mkosi when using various verbs should be delimited from
regular options now using '--'.
Daan De Meyer [Tue, 11 Feb 2025 14:58:38 +0000 (15:58 +0100)]
run: Simplify spawn()
Let's reduce the nesting by stopping usage of Popen() as a context
manager. It's __exit__() method doesn't handle anything important that
we don't already handle ourselves. Let's also only handle
FileNotFoundError when spawning the process but not after yielding.
Finally, get rid of the failed() nested function as it only has one
remaining caller.
Daan De Meyer [Tue, 11 Feb 2025 14:48:29 +0000 (15:48 +0100)]
mkosi-sandbox: Implement --pack-fds
This allows us to move the file descriptor packing logic from spawn()
to mkosi-sandbox. The main advantage here is that we can pass file
descriptors now without necessarily packing them together, which we now
only do for systemd-journal-remote which requires it.
Luca Boccassi [Tue, 11 Feb 2025 13:19:15 +0000 (13:19 +0000)]
partition: do not return TBD as roothash
When a verity partition is skipped/deferred (eg: second run for ESP
partitioning) the JSON output will list the roothash as 'TBD' which
is obviously not valid, so skip it in that case
Daan De Meyer [Mon, 10 Feb 2025 20:24:37 +0000 (21:24 +0100)]
Make VM registration work unprivileged
Since systemd 257, it's possible for unprivileged users to register
VMs with systemd-machined (gated behind polkit). So let's not require
root privileges to register virtual machines with systemd-machined, but
only do it as an unprivileged user if registration is explicitly requested
to avoid the polkit prompt.
To avoid having to detect which systemd version the system is running,
we skip errors on varlink registration for now when running unprivileged.
https://github.com/systemd/systemd/pull/36344 will allow us to detect if
the machined varlink interface can be accessed as an unprivileged user or
not.
Daan De Meyer [Tue, 11 Feb 2025 09:54:13 +0000 (10:54 +0100)]
sandbox: Replace --exec-fd with --suspend
Let's change our synchronization mechanism from a file descriptor
to use SIGSTOP instead. This is both simpler and gives us a two way
synchronization mechanism. We can wait in the parent for the initialization
to complete just like before by waiting for the process to go into the
stopped state. But we can also have the subprocess wait indefinitely
until the parent tells it to continue by sending the SIGCONT signal. We make
use of this to register the qemu VM with systemd-machined before actually
starting the qemu process itself.
Daan De Meyer [Tue, 11 Feb 2025 09:29:37 +0000 (10:29 +0100)]
Drop foreground process logic
Let's stop messing around with process groups in favor of handling
terminal signals properly ourselves. We had to use process groups in
the past because we still used subprocess.run() which meant that by
the time we had a chance to handle KeyboardInterrupt(), the subprocess
would have already been SIGKILLed by subprocess.run(). Now that we don't
use subprocess.run() anymore, we can catch KeyboardInterrupt() at the
right time and forward it to the child process.
For the mkosi process itself, we have to modify the signal handlers
slightly to make sure we only raise the KeyboardInterrupt() exception
once, as when we're running a forked subprocess, both the parent process
and the forked subprocess will receive SIGINT if Ctrl+C is entered on the
terminal, and the parent process will forward the SIGINT to the child process,
which is already handling its own SIGINT, causing KeyboardInterrupt() to get
raised twice if we don't add an extra check to the signal handler to make sure
it only gets raised once.