Commit Graph

161 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
3f80c1393e test/60-ukify: override stub location in tests
Without this, build would fail if the stub is not available in /usr/lib/.
2023-05-05 18:42:37 +02:00
Zbigniew Jędrzejewski-Szmek
f9a6cb0e13 test-kernel-install: test 60-ukify.install and 90-uki-copy.install
We install a kernel with layout=uki and uki_generator=ukify, and test
that a UKI gets installed in the expected place. The two plugins cooperate,
so it's easiest to test them together.
2023-05-05 18:42:37 +02:00
Zbigniew Jędrzejewski-Szmek
ca1abaa5c4 60-ukify: kernel-install plugin that calls ukify to create a UKI
60-ukify.install calls ukify with a config file, so singing and policies and
splash will be done through the ukify config file, without 60-ukify.install
knowing anything directly.

In meson.py, the variable for loaderentry.install.in is used just once, let's
drop it. (I guess this approach was copied from kernel_install_in, which is
used in another file.)

The general idea is based on cvlc12's #27119, but now in Python instead of
bash.
2023-05-05 18:42:37 +02:00
Zbigniew Jędrzejewski-Szmek
d3533162d1 90-loaderentry: make sure that variables are set
We unconditionally use the variables later on, so let's make sure
that they were passed as expected.
2023-05-03 12:29:40 +02:00
Yu Watanabe
0362953e9a test-kernel-install: several cleanups
- allow to run without $PROJECT_BUILD_ROOT,
- drop unnecessary export for bootctl,
- enable -x option to show commands,
- use 'test ! -e' to check the nonexistence of files,
- show more debugging logs.
2023-03-30 09:23:07 +02:00
Gertalitec
600362aa11 Define $KERNEL_INSTALL_UKI_GENERATOR
Define $KERNEL_INSTALL_UKI_GENERATOR in case one wants it to be different from $KERNEL_INSTALL_INITRD_GENERATOR. This can be useful if one wants to use mkinitcpio / Dracut to generate the initrd, but without creating the UKI so this can be left for e.g. ukify or something else. Right now these initrd generators will read /etc/kernel/install.conf and generate the UKI
2023-03-26 16:54:16 +02:00
Yu Watanabe
b0e339547f kernel-install: check all entry candidates first, then check existence of $pref/loader/entries only once
If we have multiple entries in $ENTRY_TOKEN_SEARCH, and $pref/loader/entries
exists, then previously we would always exit after the first candidate and
ignore the second and later candidates.

Follow-up for 1b43f86893.
2023-03-17 20:41:17 +09:00
Yu Watanabe
561d801370 Revert "kernel-install: also try to find $BOOT by partition GUID"
This reverts commit 41f39e2144.

From the post merge comment in #26648:

> Hmm, this is highly problematic, no? if I boot from my ssd and then
> plug in a fedora live usb stick, then there will be two ESPs around,
> the one from my ssd and the one from the live usb one, and this code
> might find the wrong one and bad things will happen
2023-03-17 20:41:17 +09:00
Luca Boccassi
25a45b0dd1 Merge pull request #26119 from kraxel/uki.install
kernel-install: improve uki handling
2023-03-08 21:25:25 +00:00
Gerd Hoffmann
3d5f0bfe4e kernel-install: handle uki installs automatically
Detect image type using "bootctl kernel-identify $kernel",
store result in KERNEL_INSTALL_IMAGE_TYPE.

Extend layout autodetection to check the kernel image type
and pick layout=uki for UKIs.

Resolves: #25822
2023-03-07 08:14:46 +01:00
Gerd Hoffmann
c7314ee7e2 90-uki-copy.install: create $BOOT/EFI/Linux directory if needed
Do not consider a missing 'Linux' subdirectory an error.
Just create it instead.
2023-03-07 08:14:46 +01:00
Luca Boccassi
41f39e2144 kernel-install: also try to find $BOOT by partition GUID
When there is nothing set up on /boot, /boot/efi or /efi, try to find the
$BOOT partition checking for the XBOOTLDR or ESP partition GUIDs.
Prefer XBOOTLDR as per BLS.

Fixes https://github.com/systemd/systemd/issues/26644
2023-03-03 10:50:57 +00:00
Luca Boccassi
3bf7e3c06e kernel-install: use log_verbose everywhere 2023-03-02 23:19:57 +00:00
Daan De Meyer
77db9ef2ab boot: Make sure we take --root into account everywhere. 2023-02-09 14:46:17 +00:00
Jan Janssen
4c181c1a33 meson: Properly install 90-uki-copy.install 2023-01-27 17:47:09 +01:00
Ludwig Nussel
8702496bfb bootctl: unlink and cleanup functions
The unlink command removes an entry from the ESP including
referenced files that are not referenced in other entries. That is
useful eg to have multiple entries that use the same kernel with
different options.

The cleanup command removes all files that are not referenced by any
entry.
2023-01-19 14:24:43 +01:00
Ludwig Nussel
5fe34dbfeb kernel-install: refactor some variables
In preparation for plugin support
2023-01-10 13:49:31 +01:00
Ludwig Nussel
dd003f1621 kernel-install: run depmod only if writeable 2023-01-05 21:46:09 +01:00
Joerg Behrmann
0ccfd3564b kernel-install: Add uki layout
Currently the kernel-install man page only documents the bls layout for use
with the boot loader spec type #1. 90-loaderentry.install uses this layout to
generate loader entries and copy the kernel image and initrd to $BOOT.

This commit documents a second layout "uki" and adds 90-uki-copy.install,
which copies a UKI "uki.efi" from the staging area or any file with the .efi
extension given on the command line to
$BOOT/EFI/Linux/$ENTRY_TOKEN-$KERNEl_VERSION(+$TRIES).efi

This allows for both locally generated and distro-provided UKIs to be handled
by kernel-install.
2022-11-29 11:33:27 +01:00
Zbigniew Jędrzejewski-Szmek
0be160136e kernel-install: add header to generate entry files
I was looking at a bug in bugzilla about some boot loader issue, and it was
hard to say if the boot entry files were generated by our plugin or something
else. Add a header to make this clear.

kernel-install invokes the plugins via absolute path always, so $0 gives as
the full path the location where the plugin is installed. This is what we want:

  title      Fedora Linux 37 (Workstation Edition)
  # Boot Loader Specification type#1 entry
  # File created by /usr/lib/kernel/install.d/90-loaderentry.install (systemd 252-409-g5028904^)
2022-11-23 10:14:25 +01:00
Zbigniew Jędrzejewski-Szmek
04fea8407c kernel-install: make 90-loadentry.install templated
It's a bit annoying that this causes so much churn, but I don't see a different
way to do this.
2022-11-22 16:12:09 +01:00
Marcus Schäfer
305dd91adf Handle MACHINE_ID=uninitialized
systemd supports /etc/machine-id to be set to: uninitialized
In this case the expectation is that systemd creates a new
machine ID and replaces the value 'uninitialized' with the
effective machine id. In the scope of kernel-install we
should also enforce the creation of a new machine id in this
condition
2022-11-17 07:45:25 +09:00
Marcus Schäfer
883e7cbfc0 Fix reading /etc/machine-id in kernel-install (#25388)
* Fix reading /etc/machine-id in kernel-install

The kernel-install script has code to read the contents of
/etc/machine-id into the MACHINE_ID variable. Depending
on the variable content kernel-install either logs the
value or creates a new machine id via 'systemd-id128 new'.
In that logic there is one issue. If the file /etc/machine-id
exists but is empty, the script tries to call read on an
empty file which return with an exit code != 0. As the
script code also uses 'set -e', kernel-install will exit at
this point which is unexpected.

The condition of an empty /etc/machine-id file exists for
example when building OS images, which should initialize the
system id on first boot but not staticly inside of the image.
afaik an empty /etc/machine-id is also a common approach
to make systemd indicate that it should create a new system
id. Because of this, the commit makes sure the reading of
/etc/machine-id does not fail in any case such that the
handling of the MACHINE_ID variable takes place.
2022-11-15 23:17:19 +00:00
Luca Boccassi
cda4d00dfc kernel-install: skip 50-depmod if depmod is not available
Images might be built without any kernel module, and without
installing depmod as it is not needed. Skip it.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1023607
2022-11-07 22:30:07 +01:00
Antonio Alvarez Feijoo
802d9219aa kernel-install/90-loaderentry: do not override an existing systemd.machine_id
If the systemd.machine_id command line option is already set, do not override
it.
2022-11-07 19:54:16 +01:00
Antonio Alvarez Feijoo
981502c5cc kernel-install/90-loaderentry: do not add multiple systemd.machine_id options
Do not unconditionally add a new systemd.machine_id command line option, first
check if it already exists with the expected value.

Fixes #25203
2022-11-04 16:53:40 +01:00
Yu Watanabe
c561c78063 kernel-install: do not fail if a plugin exits with 77 2022-09-28 13:36:38 +09:00
Yu Watanabe
46f347ada3 kernel-install: do not fail if $layout is not "bls"
Fixes #24836.
2022-09-28 13:36:29 +09:00
наб
3a79a037da kernel-install/90-loaderentry: fix chown 2022-09-21 16:40:17 +09:00
Yu Watanabe
e1b45a756f tree-wide: fix typo 2022-07-20 13:15:37 +09:00
Zbigniew Jędrzejewski-Szmek
b33c2757d8 kernel-install: add helper for logging 2022-07-14 22:20:49 +09:00
Zbigniew Jędrzejewski-Szmek
dd2ebd1b1d kernel-install: suppress bogus shellcheck hint
I don't quite understand this, but '{ ! true; }' is not the same as '( ! true )'.
In interactive mode, it seems to work as expected. But in a script, it doesn't.
2022-07-12 09:24:43 +02:00
Zbigniew Jędrzejewski-Szmek
b9b55a884b kernel-install: use set -e
This means that we'll fail hard if something goes wrong, e.g. reading
of a config file. I think this is appropriate. If errors should be ignored,
the caller should do that on their end.
2022-07-12 09:24:43 +02:00
Zbigniew Jędrzejewski-Szmek
852f98d6aa kernel-install: return 0 for unknown verbs in plugins
In practice this makes little difference, because kernel-install will
only call the plugins for 'add' or 'remove', and if we were to add a
new verb to kernel-install, we'd just change the plugins at the same
time. But our plugins serve as documentation for external plugins too,
and there it's better to silently ignore unknown verbs so that we can
add new verbs in the future.

(50-depomod.install was already like that.)
2022-07-12 09:24:43 +02:00
Zbigniew Jędrzejewski-Szmek
00e6278cac kernel-install: raise fuss if plugins are called without the expected parameters 2022-07-12 09:24:43 +02:00
Zbigniew Jędrzejewski-Szmek
f875e6bc39 test-kernel-install: add a simple test that kernel-install copies the files
I opted to tweaking kernel-install to allow overriding config
(with $KERNEL_INSTALL_CONF_ROOT, $KERNEL_INSTALL_PLUGINS). An alternative
would be to build a test environment in test/. We can still do that,
but I think it's nice to have a simple test that is very quick and easy
to debug.

Invocation as installkernel is for #23681.
2022-07-12 09:24:43 +02:00
Zbigniew Jędrzejewski-Szmek
c90cb977a1 kernel-install: mark the plugins as executable in git
We mark them as executable during installation, but it's also nice to mark
them as such in sources, so they can be executed directly.
2022-07-12 09:24:43 +02:00
Zbigniew Jędrzejewski-Szmek
6755285ccb kernel-install: allow overriding the plugin list too
The use of IFS=<newline> is dropped. Let's just iterate over the list, using
any whitespace as separator.
2022-07-12 09:22:09 +02:00
Zbigniew Jędrzejewski-Szmek
2bbf6c3590 kernel-install/90-loaderentry: make ownership change optional
This can be useful when running as non-root, e.g. for tests or when
installing to a chroot.
2022-07-06 16:33:11 +02:00
Zbigniew Jędrzejewski-Szmek
91199185b1 kernel-install: allow overriding the path to config files
It's pretty hard to write tests without this. I started out by adding separate
variables for each of the files we read, but there's a bunch, and in practice
it's good enough to just override the directory.
2022-07-06 16:33:11 +02:00
Zbigniew Jędrzejewski-Szmek
035f8acdf7 kernel-install: do not silently ignore files we can't read
'test -r' is changed to 'test -f' everywhere. If the file exists but we
cannot read it, it would be better if we fail with a permission error. E.g. if
/etc/kernel/cmdline is unreadable, and we're running something as non-root, we
shouldn't fall back to /usr/lib/kernel/cmdline. This commit doesn't resolve
this fully, because we're not running with 'set -e', but this is a preparator
step.
2022-07-06 16:33:11 +02:00
Zbigniew Jędrzejewski-Szmek
5e193bef89 kernel-install: do not let config file override variables
This implementation is pretty ugly, but POSIX sh doesn't allow
indirect variable expansion, so I couldn't figure out a way to make
it less verbose.
2022-07-06 16:32:15 +02:00
Zbigniew Jędrzejewski-Szmek
c9e7ab8c29 kernel-install: fix invocation as installkernel
Fixes #23681.
2022-07-06 16:32:07 +02:00
Michael Biebl
85fce6f42c Use https for gnu.org 2022-06-28 16:07:35 +02:00
Zbigniew Jędrzejewski-Szmek
02ece2fcb1 Merge pull request #23529 from nabijaczleweli/dollar-asterisk
Don't linebreak after each initrd in kernel-install verbose mode
2022-05-30 10:27:14 +02:00
наб
2f9f8b96d4 kernel-install: don't log each initrd on its own line in verbose mode 2022-05-26 23:18:34 +02:00
наб
c60ca42571 kernel-install: actually ignore the last two arguments 2022-05-26 23:16:13 +02:00
Zbigniew Jędrzejewski-Szmek
5aa285b437 kernel-install: if a plugin fails, return error immediately
Since the first version in 81516adcb7,
kernel-install would "gather" a return value by summing the exit codes
of the plugins… This makes no sense, because those are not additive values.

Let's just break off immediately. We now implement cleanup via trap, so if we
break, we should leave no garbage behind.
2022-05-26 21:46:58 +02:00
Zbigniew Jędrzejewski-Szmek
620ecc9c4b kernel-install: ignore extra args passed when invoked as installkernel
kernel's 'make install' invokes install.sh which calls /sbin/install-kernel.
Thus we are invoked as e.g.
  /sbin/installkernel 5.18.0 arch/x86/boot/bzImage System.map /boot
The last two arguments would be passed as "initrds".

Before , we would just quitely ignore
/boot, because it doesn't pass the 'test -f' test, and possibly try to do
something with System.map. 742561efbe tightened
the check, so we now throw an error.

It seems that the correct thing is to ignore those two arguments, because
our plugin syntax has no notion of System.map. And the installation directory
we can figure out ourselves better. Effectively, this makes things behave
like before, but less by accident.

Fixes #23490.
2022-05-24 23:31:43 +02:00
наб
35339eb88c shellcheck-clean kernel-install again 2022-05-23 12:52:56 +02:00