Commit Graph
310 Commits
Author SHA1 Message Date
flixman f9b52a6be3 Implement fallback for cmdline in ukify installation
Added fallback for cmdline if not provided in config.

(cherry picked from commit 1e098a4b34c68e9b1878efb9d7c1b56a2c220619)
2026-10-16 11:36:32 +01:00
Zbigniew Jędrzejewski-Szmek efd63ddfbf shared/verbs: turn verb argument specification into nulstr
Like the command-level CommandDescription.argspec, a verb's argspec is now
a nulstr, so that a verb may declare multiple alternative usage lines. The
verbs help table renders one synopsis line per nulstr entry in the
synopsis cell.

All verb argument specifications must gain an explicit NUL suffix. This
is a lot of churn, but I think this needs to be done. For now, there'll
be only one user of the new functionality (i.e. a verb with more than
one argspec), but I think we'll eventually want to use this in other
places too.
2026-08-28 09:29:04 +02:00
felix h a11144d0a9 tree-wide: format man page references as foo(1) 2026-08-28 06:34:45 +09:00
Zbigniew Jędrzejewski-Szmek 3694241e3f shared/verbs: add helper to call command_print_help_full with name only
I didn't do this previously because I thought that there wouldn't
be too many callers. But it turns out that there're quite a few.
2026-08-26 12:14:50 +02:00
Zbigniew Jędrzejewski-Szmek 2b4c6dda9d kernel-install: convert to VERB_COMMAND and add --introspect-cli
The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added. The note about invocation as 'installkernel' is
kept as the footer. Verb and option column widths are kept separate, since
the verb table is very wide. --help now goes through the pager, like other
commands with --no-pager.

A separate COMMAND block is included for installkernel, but it is only
used for introspection data.
2026-08-25 09:33:52 +02:00
Yu Watanabe cad2c455ec fstab-filter: fix preserve fstab option escaping (#43274)
Fixes #42787.
2026-08-14 00:23:47 +09:00
wyu 7b00f957fe strv: drop the escape_separator flag from strv_join_full()
Now that fstab_filter_options() no longer uses strv_join_full() with
escape_separator=true (it splits with EXTRACT_UNESCAPE_RELAX and joins the kept
options verbatim), the escape_separator flag has no users. Drop it from
strv_join_full() and its wrapper strv_join(), and update the remaining callers in
kernel-install and the tests accordingly.
2026-08-13 11:17:23 +08:00
Simon de Vlieger cb9c4c4e81 test-kernel-install: tests for entry_name_format=
Test that custom entry_name_format=%e_%v produces correctly-named BLS
loader entries (the-token_1.1.4.conf) and UKI files (the-token_1.1.5.efi),
verifying that the full add/remove cycle works with the new entry name.
2026-08-06 16:34:17 +02:00
Simon de Vlieger f0fde6b5ea 90-loaderentry: use KERNEL_INSTALL_ENTRY_NAME
Replace the hardcoded $ENTRY_TOKEN-$KERNEL_VERSION pattern with
$KERNEL_INSTALL_ENTRY_NAME for the BLS Type#1 loader entry filename.
Falls back to $ENTRY_TOKEN-$KERNEL_VERSION when the variable is not set.
2026-08-06 16:34:17 +02:00
Simon de Vlieger f15b7eadc6 90-uki-copy: use KERNEL_INSTALL_ENTRY_NAME
Replace the hardcoded $ENTRY_TOKEN-$KERNEL_VERSION pattern with
$KERNEL_INSTALL_ENTRY_NAME, which is resolved by kernel-install from the
entry_name_format= setting. Falls back to $ENTRY_TOKEN-$KERNEL_VERSION
when the variable is not set, for compatibility with older kernel-install.
2026-08-06 16:34:17 +02:00
Simon de Vlieger 87b4a9eeba kernel-install: entry_name_format= support
Read entry_name_format= from install.conf (or KERNEL_INSTALL_ENTRY_NAME_FORMAT
env var) and resolve it using specifier_printf() to produce a configurable entry
name. The resolved name is exported as KERNEL_INSTALL_ENTRY_NAME for plugins.

Override specifiers:
  %e - entry token
  %m - machine ID (kernel-install's resolved machine ID)
  %v - kernel version being installed (overrides standard %v)

All COMMON_SYSTEM_SPECIFIERS are also available (%a for architecture, %A for
IMAGE_VERSION, %M for IMAGE_ID, etc.).

Default format is "%e-%v", preserving the existing $ENTRY_TOKEN-$KERNEL_VERSION
behavior.
2026-08-06 16:34:17 +02:00
Simon de Vlieger 95f286b9b4 kernel-config: entry_name_format in install.conf
Extend load_kernel_install_conf_at() to parse the new entry_name_format=
setting from install.conf. This plumbing only, no behavioral change yet.
Existing callers pass NULL for the new parameter.

The entry_name_format= setting will allow configuring the boot entry
filename format using specifiers, replacing the current hardcoded
$ENTRY_TOKEN-$KERNEL_VERSION pattern. This is useful for image-based OS
builds (e.g. via mkosi, or image-builder) that require versioned UKI
filenames in the ESP for sysupdate A/B updates.

Having this configuration option allows to do that directly at build
time without having to side-step kernel-install and moving files around
manually.
2026-08-06 16:22:29 +02:00
Yu Watanabe 7b2906af9f test: split out inline python script
Then, we can apply ruff to the script.
2026-08-05 11:37:29 +09:00
Simon de Vlieger bdb5d53d4f 60-ukify: skip /proc/cmdline in containers
When running inside a container (during image builds or such),
`/proc/cmdline` belongs to the host and would leak the host's root= (or a
faked placeholder like root=/dev/osbuild) into the UKI.

Mirror the same guard that `90-loaderentry.install` has: check
`systemd-detect-virt --container` before falling back to `/proc/cmdline`,
and return an empty cmdline if we are in a container to ensure both
modes (`uki` and `bls`) work the same.

Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
2026-08-04 19:18:17 +09:00
dongshengyuan 48b1109b0c kernel-install: keep ukify cmdline inside conf root
KERNEL_INSTALL_CONF_ROOT overrides kernel-install config lookup. When it
was set and cmdline was absent, 60-ukify still fell back to
/proc/cmdline and embedded host boot options into the target UKI.

Return an empty base cmdline in that case, matching the adjacent
90-loaderentry behavior of not searching outside the override root.

Reproducer:
  KERNEL_INSTALL_CONF_ROOT=$(mktemp -d) python3 -c '
  import runpy
  ns = runpy.run_path("src/kernel-install/60-ukify.install.in",
                      run_name="not_main")
  print(ns["kernel_cmdline_base"]())'

Before:
  The host /proc/cmdline was returned.

Follow-up for: 40c0c9d4bc
2026-07-23 12:19:48 +09:00
Yu Watanabe 4c0d8d9673 tree-wide: embed dlopen notes into individual executables
Previously, when a library was dynamically loaded via a helper function
inside libsystemd-shared.so, the resulting dlopen ELF note was not
propagated to the invoking executable's ELF metadata.

This commit explicitly annotates each executable with the relevant
dlopen ELF notes for any optional dependencies it might potentially
load. This ensures that package managers and build systems can properly
discover runtime dependencies that are triggered indirectly.
2026-07-10 16:35:19 +09:00
Lennart Poettering 90d285ade7 recurse-dir: optionally, only enumerate dentries of a specific type
At various places we filter directory enumerations by inode type. Let's
add explicit support for that, so that the "struct dirent" array we
return already suppresses them.

This shortens code and makes things more robust.
2026-06-22 14:40:16 +02:00
Lennart Poettering eb3799a373 fd-util: add wildcard_fd_is_valid() helper and use it tree-wide
Many *at()-style helpers accept a directory fd that may be either a
regular, valid fd (>= 0) or one of the special AT_FDCWD/XAT_FDROOT
wildcard values, and open-code that check in their assertions. Add a
wildcard_fd_is_valid() helper for it and use it tree-wide.
2026-05-28 13:33:08 +01:00
Zbigniew Jędrzejewski-Szmek 39a3647539 tree-wide: get rid of old dispatch_verb
Also rename dispatch_verb_with_args to dispatch_verb.
2026-05-16 18:37:10 +02:00
Zbigniew Jędrzejewski-Szmek 587c522487 various: fix duplicated logging from parse_path_argument
As pointed out in review, parse_path_argument can fail for non-oom reasons.
But the function already logs, so the correct thing to do is to just
propagate the error.
2026-05-14 14:15:55 +02:00
Zbigniew Jędrzejewski-Szmek 71c3123b17 kernel-install: convert to the new option and verb parsers
The verb synopses are very long because of the many parameters.
Previously were shown without help and occupied all available columns.
With the autogenerated help format, this doesn't work great. So the
verbs and options tables are not synced, so that help for options can
use more columns. I think in this case this is better than the
alternatives.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-14 14:15:50 +02:00
Daan De Meyer 79862d33a0 chase: add explicit root_fd parameter to chaseat() and drop CHASE_AT_RESOLVE_IN_ROOT
Split the single directory fd that chaseat() used to take into two separate
fds: a root_fd that sets the chroot boundary (symlinks may not escape it,
absolute symlinks resolve relative to it), and a dir_fd that path resolution
starts from. This makes the chroot semantics of chaseat() explicit at every
call site instead of encoding them in the CHASE_AT_RESOLVE_IN_ROOT flag,
which is removed. It also decouples the starting directory from the root
boundary, so callers can descend from any inode inside the tree without
having to reopen the root separately.

XAT_FDROOT passed as root_fd means "no containment" (host root); as dir_fd
it means "start at root_fd". For a smoother transition, AT_FDCWD is also
accepted as root_fd and treated as XAT_FDROOT. When root_fd points to a
directory that is actually the host root, it is normalized to XAT_FDROOT
up front so the existing shortcut path can kick in.

Absolute paths returned by chaseat() are now relative to root_fd, and
relative paths are relative to dir_fd. The result is absolute only when
there is no chroot boundary (root_fd is XAT_FDROOT), or when an absolute
symlink made resolution jump out of the dir_fd subtree; otherwise callers
get a relative path they can feed straight back into an openat()-style
call against dir_fd. Specifically, when dir_fd == root_fd and we're not
operating on the host's root directory, we return a relative path even if
we received an absolute path or resolved an absolute symlink to allow
passing the path directly to openat() style functions. We do this to not
have to go modify every caller of chaseat() to make sure they deal properly
with any absolute paths they might receive. Only when root_fd != dir_fd do
we have to return an absolute path to indicate that the path is relative to
root_fd and not dir_fd.

The shortcut that skips the per-component walk is reworked around a new
chase_xopenat() helper that funnels CHASE_NOFOLLOW, CHASE_MUST_BE_* and
CHASE_TRIGGER_AUTOFS through xopenat_full()'s O_NOFOLLOW, O_DIRECTORY,
XO_REGULAR, XO_SOCKET and XO_TRIGGER_AUTOMOUNT flags. As a result these
flags no longer force us off the shortcut and can be dropped from
CHASE_NO_SHORTCUT_MASK, and the old openat_opath_with_automount() helper
goes away. A CHASE_MUST_BE_ANY alias is introduced for shortcut callers
(stat/access paths) that don't go through xopenat_full() and still need
to bail on those flags locally.

All *_and_* helpers built on top of chaseat() (chase_and_openat,
chase_and_opendirat, chase_and_statat, chase_and_accessat,
chase_and_fopenat_unlocked, chase_and_unlinkat, chase_and_open_parent_at)
gain the same root_fd parameter, and every call site in the tree is
ported to the new signature.

chase_and_open() is also fixed to correctly handle CHASE_EXTRACT_FILENAME
without CHASE_PARENT.
2026-04-20 23:35:31 +02:00
Lennart Poettering 853d0649d5 find-esp: return pinned fd to ESP/XBOOTLDR
The reworks the ESP/XBOOTLDR logic to pin the ESP/XBOOTLDR via an fd,
and return that as optional return parameter.

So far we only pinned the parent dir of the ESP/XBOOTLDR, which was
useful when verifying that ESP/XBOOTLDR is actually a mount point by
comparing mount ids. This however became obsolete with
a98a6eb95c. Hence, let's clean this up,
and pin the inode we really care about and return it.
2026-04-20 17:19:27 +02:00
Michael Vogt bd141bd818 many: fix remaining check-pointer-deref issues
The updated parsing_hacks.h file uncovered a bunch of extra
things that the check-pointer-deref coccinelle script flags.

This commit fixes them to make the tree check-pointer-deref clean.
2026-04-12 15:27:15 +02:00
Lennart Poettering d90d0a1f63 kernel-image: minor refactoring to inspect_kernel()
Let's add make three arguments optional, by splitting inspect_kernel()
from inspect_kernel_full().

Let's also downgrade logging to debug, so that this becomes more
library-like. Let's log on the call-site instead.
2026-04-03 08:15:27 +02:00
Cynthia 0c2747e789 kernel-install(uki): filter comments from cmdline
This change aligns the behaviour of UKI generation with the behaviour
of BLS. The latter filters out lines starting with a #, allowing users
to add comments and/or temporarily remove some flags from the kernel
command line.

The kernel-install test have been adjusted to use a multiline cmdline
with a comment in it. Without this patch, the test fails.
2026-03-26 14:28:22 +01:00
Robin Ebert 55e7dc5ce4 kernel-install: fix assert in context_copy 2026-03-20 15:17:44 +01:00
Zbigniew Jędrzejewski-Szmek 31ddd87da0 tree-wide: extend verbs functions with extra per-verb data parameter
We often have a pattern where the same verb function is used for
multiple actions. This leads to an antipattern where we figure out what
action needs to be taken from argv[0] multiple times: often once in
parse_argv() to figure out what options are allowed, then once again
implicitly in dispatch_verb(), and then again in the action verb itself.
Let's allow passing a parameter into the verb to simplify this.

This matches a pattern we have in conf-parser.h, where we have both
void *userdata (more global) and void *data (per-config item). Here,
I opted for uintptr_t userdata. It seems that most of the time we'll
want to just pass an enum value. This works OK with no casts. I also
tried a void* and union. In both cases, much more boilerplate is needed:
either a cast or a macro to help avoid compiler warnings. uintptr_t
seems generic enough to cover foreseeable usecases with no fuss.

This is a noop refactoring. See next commit for an example.
2026-03-18 10:28:47 +00:00
Lennart Poettering 8a2c423870 find-esp: introduce _full() flavour of ESP/XBOOTLDR discovery functions
These functions take so many return paramaters, and in many of our cases
we don't actually needt them. Hence introduce _full() flavours of the
funcs, and hide the params by default.
2026-03-18 10:25:59 +00:00
Lennart Poettering cfee2c1900 kernel-install: allocate "Context" object only in verb_xyz() functions, not already in run()
We soon want to add a Varlink interface to this, but that means that the
various paramaters for the Context object will be sourced from a Varlink
message not from the command line. Hence split apart the parsing logic
so that we alway parse the command line into arg_xyz first, and then,
inside the verb_abc() calls copy the data from there into the Context
object.

This matches a similar pattern in bootctl.
2026-02-09 10:21:16 +01:00
Lennart Poettering 533afe86c3 kernel-install: rework in preparation for varlink
This reworks things a bit, so that the "Context" object can later be
allocated for each Varlink call separately. For example we define a
more precise CONTEXT_NULL that invalidates truly all fields, so that we
can discern "defaults" from "unspecified" later on.

Other minor rearrangements too
2026-02-09 10:21:16 +01:00
Jörg Behrmann cab4b9defd kernel-install: handle removal unsuccessful UKIs and loader entries separately
When a tries file exists, 90-uki-copy.install removes a previous UKI of the
same kernel version and all it's unbooted variants. This removal is guarded
behind a check for the existence of the already booted UKI, i.e. if uki.efi
already exists, uki.efi and uki+*.efi will be removed.

This leaves the edge case that if uki.efi does not exist, but only an unbooted,
e.g. uki+3.efi, it will not be removed. This is not a problem, if the number of
tries is constant between both builds, since a new uki+3.efi would overwrite
the existing one, but if the number of tries is changed to, e.g. uki+5.efi, we
are left with both uki+3.efi and uki+5.efi.

The same is done for loader entries.
2026-01-27 15:53:48 +01:00
Lennart Poettering 6ecfa12af0 conf-files: add support for root_fd based operation
Let's make sure we can safely load configuration files based on a root
fd, including XAT_FDROOT.

(While we are at it, always pass path to root fs before fd to root fs,
following our recently updated CODING_STYLE)
2026-01-25 20:51:50 +01:00
Yu Watanabe 2aa496312e conf-files: introduce CONF_FILES_WARN flag and set it at various places
Closes #40285.
2026-01-16 23:05:33 +09:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De MeyerandYu Watanabe ee6b3d1aa2 test: Stop using grep -q in integration test
When a TTY is attached to the test unit, grep -q will generate SIGPIPE
for the previous command in the pipeline which in combo with `pipefail`
will cause the command to fail with exit status 141 which will fail the
test.

Replace with >/dev/null to avoid this from happening.

See also https://www.gnu.org/software/grep/manual/html_node/Usage.html
> There is a related problem with Bash’s set -e -o pipefail. Since grep
> does not always read all its input, a command outputting to a pipe read
> by grep can fail when grep exits before reading all its input, and the
> command’s failure can cause Bash to exit.

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-12-10 12:09:10 +01:00
Antonio Álvarez Feijoo 4ae16cf9b7 kernel-install: exit with option --json=help (#39974)
In that case, `parse_json_argument()` returns 0.

Follow-up for bdd36c003d (v255).
2025-12-03 01:56:01 +09:00
Mike Gilbert 1a88817b83 test-kernel-install: respect TMPDIR in expected output 2025-12-01 13:23:42 +00:00
Lennart Poettering f8fcf7de7c kernel-install: move staging area to /var/tmp/
The generated files (UKIs...) can potentially be huge, hence create them
in /var/tmp/, rather than /tmp/.
2025-11-03 09:01:44 +01:00
Yu Watanabe d1893390e5 test-kernel-install: support the case when custom default locale is specified
This also makes 'diff' command output to stderr, otherwise the
difference is eaten by meson by default, so hard to debug.
2025-10-13 10:31:43 +02:00
Mike Yuan 6870f78dcd kernel-install: drop unneeded empty_to_root() 2025-10-08 09:22:07 +02:00
Lennart Poettering 435bef5d05 kernel-install: when listing kernels sort them by version 2025-09-18 09:31:35 +02:00
Zbigniew Jędrzejewski-Szmek 66b2d758c5 various: add a fixed name to log about plugin execution
Function execute_directories logged in a way that was meaningless
without additional context:
  systemd[1]: No executables found.
In execute_strv this was partially rectified by extracting the directory
name from one of the directories and using this as the identifier. But
the directory name is not always meaningful, and can also be set from
an environment variable. Let's simplify things by providing a fixed name
that can be used consistently in all log messages. In particular this will
make error messages easier to understand if users report just the error
without additional context.
2025-09-03 08:56:23 +02:00
Zbigniew Jędrzejewski-Szmek c5dcbd073e meson: use files() not find_program() for helper scripts
We went back and forth between 'prog.sh', files('prog.sh'), and
find_program('prog.sh'). We want to use files() or find_program() so that we
get a good error message if the file is missing. Behaviour of meson changed
over time, and in the past not all forms could be used in all places. For
example 0f4c4f3824 added find_program() in many
places to avoid repeated messages. But it seems that all recent meson versions
work fine with files().

find_program prints silly messages:
  Program tools/make-man-index.py found: YES
       (/home/zbyszek/src/systemd/tools/make-man-index.py)
  Program tools/meson-render-jinja2.py found: YES
       (/home/zbyszek/src/systemd/tools/meson-render-jinja2.py)
  ...
We know that those files will be found, they are part of the git checkout.
With files() this is gone and the meson output is easier to read.
2025-07-25 14:04:17 +02:00
Li Tian 9e3c496bd3 90-uki-copy.install: Skip removing UKI related when BOOT_ENTRY_TYPE=type1
Commit b6d4997683
("Add --entry-type=type1|type2 option to kernel-install.")

Skip removing UKI related contents when BOOT_ENTRY_TYPE=type1

Signed-off-by: Li Tian <litian@redhat.com>
2025-07-15 22:56:33 +09:00
vlefebvre 96ba43388f uki.conf is used by the ukify tool to create an Unified Kernel Image. It
would make sense to install it only if ukify is wanted.
2025-07-12 00:40:08 +09:00
Yu Watanabe 19d4040d71 kernel-install: regroup options in help meesage
And slightly updates the description.

Follow-up for b6d4997683.
2025-07-11 17:32:04 +09:00
Yu Watanabe 9026f17907 kernel-install: do not mix || and &&
This also slightly updates log message, and make it shown only when
verbose mode is enabled.

Follow-up for b6d4997683.
2025-07-11 17:32:02 +09:00
Li Tian b6d4997683 Add --entry-type=type1|type2 option to kernel-install.
Both kernel-core and kernel-uki-virt call kernel-install upon removal. Need an additional argument to avoid complete removal for both traditional kernel and UKI.

Signed-off-by: Li Tian <litian@redhat.com>
2025-07-10 18:07:23 +02:00
Zbigniew Jędrzejewski-Szmek 7d247d3cb8 meson: drop explicit custom_target names
[1] says:
> Since 0.60.0 the name argument is optional and defaults to the basename of
> the first output
We specify >= 0.62 as the supported version, so drop the duplicate name in all cases
where it is the same as outputs[0], i.e. almost all cases.

[1] https://mesonbuild.com/Reference-manual_functions.html#custom_target
2025-06-28 17:14:50 +02:00