Commit Graph

246 Commits

Author SHA1 Message Date
Lennart Poettering
80889bd9cc bootctl: automatically write out $BOOT/entries/standard.srel 2022-03-22 00:34:49 +01:00
Lennart Poettering
a5b30e156a bootctl: generalize open_tmpfile_linkable() use a bit
We want FILE* here, instead of a plain fd. Let's generalize this in
tmpfile-util.c, so we can reuse it later easily.
2022-03-22 00:34:48 +01:00
Lennart Poettering
b72676e7a0 bootctl: load /etc/kernel/install.conf's $layout field, too
bootctl so far tried to determine the layout from /etc/machine-info, but
that's obsolete, and the kernel-install script never looked there. Let's
read the setting from /etc/kernel/install.conf instead, where
kernel-install actually looks.

Support for reading the field from /etc/machine-info is retained for
compat.

This means we'll now read /etc/machine-id, /etc/machine-info and
/etc/kernel/install.conf, and read the machine ID from the former too
and the layout setting from the latter two.
2022-03-21 23:54:33 +01:00
Lennart Poettering
ea29abece9 bootctl: $KERNEL_INSTALL_MACHINE_ID + $KERNEL_INSTALL_LAYOUT are deprecated
Let's add a comment about this, and generate log messages if these
fields are actually used.
2022-03-21 23:50:17 +01:00
Yu Watanabe
de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Zbigniew Jędrzejewski-Szmek
5f1077af1e Merge pull request #22519 from poettering/boot-order-title-revert
sd-boot: rework boot entry sorting
2022-03-18 19:04:48 +01:00
Lennart Poettering
e94830c0a1 shared: split out ESP/XBOOTLDR search stuff from bootspec.c
The code is quite different from the rest of bootspec.c, with different
deps and stuff. There's even a /***/ line to separate the two parts.
Given how large the file already is, let#s just split it into two.

No code changes, just some splitting out.
2022-03-18 12:01:45 +01:00
Lennart Poettering
20ec8f534f sd-boot: make use of new "sort-key" boot loader spec field 2022-03-18 11:59:30 +01:00
Lennart Poettering
8d3e0d607e bootctl: add comment, explaining when verb_install() is called 2022-03-18 09:30:29 +01:00
Lennart Poettering
d16da79ec0 bootctl: use faccessat() more 2022-03-18 09:30:25 +01:00
Lennart Poettering
1c2b617703 bootctl: fix typo 2022-03-18 09:30:21 +01:00
Lennart Poettering
f337f903df bootctl: update to new kernel-install semantics
This makes a bunch of closely related changes:

1. The "entry-token" concept already introduced in kernel-install is now
   made use of. i.e. specifically there's a new option --entry-token=
   that can be used to explicitly select by which ID to identify boot
   loader entries: the machine ID, or some OS ID (ID= or IMAGE_ID= from
   /etc/os-release, or even some completely different string. The
   selected string is then persisted to /etc/kernel/entry-token, so that
   kernel-install can find it there.

2. The --make-machine-id-directory= switch is renamed to
   --make-entry-directory= since after all it's not necessarily the
   machine ID the dir is named after, but can be any other string as
   selected by the entry token.

3. This drops all code to make automatic changes to /etc/machine-info.
   Specifically, the KERNEL_INSTALL_MACHINE_ID= field is now more
   generically implemented in /etc/kernel/entry-token described above,
   hence no need to place it at two locations. And the
   KERNEL_INSTALL_LAYOUT= field is not configurable by user switch or
   similar anyway in bootctl, but only read from
   /etc/kernel/install.conf, and hence copying it from one configuration
   file to another appears unnecessary, the second copy is fully
   redundant. Note that this just drops writing these fields, they'll
   still be honoured when already set.
2022-03-11 11:39:34 +01:00
Tobias Stoeckmann
1a823cdeb9 core: check size before mmap
The data type off_t can be 64 on 32 bit systems if they have large
file support. Since mmap expects a size_t with 32 bits as second
argument truncation could occur. At worst these huge files could
lead to mmaps smaller than the previous check for small files.

This in turn shouldn't have a lot of impact because mmap allocates
at page size boundaries. This also made the PAGE_ALIGN call in
open_mmap unneeded. In fact it was neither in sync with other mmap
calls nor with its own munmap counterpart in error path.

If such large files are encountered, which is very unlikely in these
code paths, treat them with the same error as if they are too small.
2022-03-03 22:48:43 +01:00
Lennart Poettering
f63b5ad935 boot: suppress XBOOTLDR if same device as ESP when enumerating entries
On my local system I linked up the ESP and XBOOTLDR partitions, and
ended up with duplicate entries being listed. Try hard to detect that
and only enumerate entries in the ESP if it turns out that both dirs
have the same dev_t.

This should detect both bind mounted and symlinked cases and should make
our list output less confusing.
2022-02-14 16:24:04 +01:00
Lennart Poettering
bb68205768 bootctl: show more information about boot entry state in list
Let's improve display of boot entries and show what type they have (i.e.
boot loader spec type 1, or type 2, or auto-discovered or reported by
boot loader), and in particular mark entries the boot loader discovered
but we can't find (i.e. that likely vanished, or possibly couldn't be
found due to a misconfiguration) and that the boot loader didn't find
but we see (which are new, or possibly also the result of
misconfiguraiton).

This is supposed to be a replacement for #22161, but instead of hiding
vanished entries, highlights them, which I think is more appropriate for
a low-level tool such bootctl.

Replaces: #22161 #22398
2022-02-14 15:44:07 +01:00
Lennart Poettering
a78e472dfd bootspec: also collect/mark the "selected" boot entry (i.e. the one currently booted)
it's helpful and easy, so let's do it
2022-02-14 15:44:07 +01:00
Lennart Poettering
fdc5c04299 bootspec: parse/show devicetree-overlay field too
It has been defined in the boot loader spec, and is the only field we
currently don't parse, hence fix that.
2022-02-14 15:44:07 +01:00
Lennart Poettering
9951736b7f Revert "bootctl: Ignore boot entries (continue #22041)" 2022-02-14 15:44:07 +01:00
Daan De Meyer
17e2e8073f boot: Don't require a machine ID to be available
Regression introduced in https://github.com/systemd/systemd/pull/21807.

Fixes #22224
2022-01-31 13:58:06 +00:00
Goffredo Baroncelli
2fbf50d675 bootctl: removed unused parameter only_auto
Remove the parameter 'only_auto' from the function
boot_entries_augment_from_loader() because each caller set it always to
true.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2022-01-18 19:32:35 +01:00
Goffredo Baroncelli
9914d89b51 bootctl: ignore the bootloader boot entries
When bootctl lists the boot entries, considers also the ones
returned by systemd-boot (via the efi LoaderEntries variable),
created at boot time.

Unfortunately this list may became incorrect if (e.g.) the user remove a
kernel package.

This patch changes this behaviour, so bootctl ignores some the
boot entries returned by systemd-boot.

In any case, bootctl still considers the 'auto-xxx' boot entries
listed below:

  Boot entrie name                 Title
  -----------------------------    ------------------------------
  auto-osx                         macOS boot loader
  auto-windows                     Windows Boot Manager
  auto-efi-shell                   EFI Shell
  auto-efi-default                 EFI Default Loader
  auto-reboot-to-firmware-setup    Reboot Into Firmware Interface

The other entries that systemd-boot synthetizes (e.g. the ones loaded from
/efi/loader/entries/<uuid>) can be synthetized by bootctl too, so no
information is lost.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
2022-01-18 19:32:35 +01:00
Zbigniew Jędrzejewski-Szmek
49927ad813 bootctl: do not update sd-boot if it wasn't installed in the first place
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2038289.
2022-01-11 10:57:36 +01:00
Zbigniew Jędrzejewski-Szmek
d9f048b5d1 bootctl: split out the check whether sd-boot is installed 2022-01-11 10:56:29 +01:00
Zbigniew Jędrzejewski-Szmek
1ff493d5c1 bootctl: deprecate --make-machine-id-directory=auto
Now that kernel-install creates the machine-id directory, we don't need to do
this is 'bootctl install', and in fact it's better not to do this since it
might never be necessary. So let's change the default behaviour to 'no'.

I kept support for 'auto' to maintain backwards compatibility, even though the
default was changed. Previous behaviour can be requested by specifying
--make-machine-id-directory=auto.
2021-12-17 18:48:08 +01:00
Zbigniew Jędrzejewski-Szmek
47fb161e3a bootctl: write KERNEL_INSTALL_LAYOUT=bls and KERNEL_INSTALL_MACHINE_ID=…
This is a natural extension of d6bce6e224: if we are installing sd-boot, we
want to use the sd-boot layout, so let's write the appropriate
KERNEL_INSTALL_LAYOUT setting. Effectively, if we do 'booctl install',
kernel-install will not autodetect the layout anymore.

And 357376d0bb added support for KERNEL_INSTALL_MACHINE_ID. We need to support
it here too. We both read it, so that we create the right directories, and also
write it if it wasn't written yet and we created some directories using it, so
that kernel-install that is executed later knows the machine-id that matches
the directories we crated.

The code is changed in some places to fail if we can't figure out the current
status. When installing the boot loader it's probably better not to guess.
2021-12-17 18:47:53 +01:00