Commit Graph

32 Commits

Author SHA1 Message Date
Itxaka
03eae2a402 boot: add an option to control action after SecureBoot enrollment (#36684)
This PR provides a new option for systemd-boot
`secure-boot-enroll-action` which allows to configure the behavior after
SecureBoot keys are enrolled.

Provides the option to either reboot or power off.

The current behavior is not changed, it will by default reboot as it did
before.

It also provides a small message about the action its going to take with
a small delay so the user can read it.
2025-05-08 13:28:41 +09:00
Daan De Meyer
1cf40697e3 tree-wide: Sort includes
This was done by running a locally built clang-format with
https://github.com/llvm/llvm-project/pull/137617 and
https://github.com/llvm/llvm-project/pull/137840 applied on all .c
and .h files.
2025-04-30 09:30:51 +02:00
Yu Watanabe
9dc735426a boot: always pass an array of PeSectionVector to pe_locate_sections()
Hopefully silences false-positive warnings by Coverity.
Fixes CID#1549198, CID#1549199, CID#1564903.
2025-03-19 10:40:31 +09:00
Yu Watanabe
1ae60b69fa boot: introduce string tables for RebootOnError and sucure_boot_enroll 2025-03-13 02:40:12 +09:00
Yu Watanabe
c5710c00ff boot: fix use of uninitialized value on error
Follow-up for 0bdf94e588.
2025-03-13 02:40:12 +09:00
nkraetzschmar
0bdf94e588 boot: add reboot-on-error config option
Enabling this option will cause the system to reboot in case the selected
entry fails to load.
2025-03-12 15:47:38 +01:00
Yu Watanabe
5c9feb2d6e tree-wide: drop unnecessary break in default branch 2025-03-06 11:42:20 +01:00
Lennart Poettering
395ac1c448 boot: split out call that adds reboot/poweroff/firmware entries 2025-02-25 21:15:10 +01:00
Lennart Poettering
612bc71210 boot: make secure boot enrollment less special
This is the last entry type that has special handling: with this in
place we now always invoke entry handlers the very same way. via the
.call() method of the BootEntry structure.
2025-02-25 21:15:10 +01:00
Lennart Poettering
fb09163a01 boot: move check if secure boot enrollment applies to a single place
Let's check if sb enrollment applies at a single place: inside the
discovery function, and let's not bother with additional checks later.
2025-02-25 21:15:10 +01:00
Lennart Poettering
fb6cf4bbb7 boot: make regular entries less special
Let's try to always invoke entries via the call() method of BootEntry
objects, to stick to a single uniform way to do so.
2025-02-25 21:15:10 +01:00
Lennart Poettering
d870ae47b7 boot: only save entry for some entry types
Much like the previous one, let's also condition the entry selection
saving on entry types.
2025-02-25 21:14:27 +01:00
Lennart Poettering
ae5e7f17d0 boot: only do random seed management for some entry types
Similar to the previous commits, let's carefully condition random seed
management (which might be slow, and simply pointless for various entry
types) on the entry type.
2025-02-25 21:14:27 +01:00
Lennart Poettering
729f3c21c5 boot: only do boot counting management for some menu entries
Let's do boot counting only for some menu entry types, and carefully
list which types those are.
2025-02-25 21:14:27 +01:00
Lennart Poettering
4801e16401 boot: make .call() method of BootEntry more complete
Let's pass some context information to the .call() methods so that it's
sufficient to implement the handlers for all entry types with them.

(This commit doesn't port the various entry types over though, that
happens in later commits.)
2025-02-25 21:14:27 +01:00
Lennart Poettering
95086da39f boot: split out line editor
let's make this beast of boot.c a bit more digestable
2025-02-25 21:08:38 +01:00
Lennart Poettering
fc8f0089bf boot: when we detect that sd-boot is called as NBP, print friendly message
Fixes: #11850
2025-02-21 10:04:15 +01:00
Lennart Poettering
4f3a3b7695 sd-boot: also read type #1 entries from SMBIOS Type #11
With this we can now do:

systemd-vmspawn -n -i foobar.raw -s io.systemd.boot.entries-extra:particleos-current.conf=$'title ParticleOS Current\nuki-url http://example.com/somedir/uki.efi'

Assuming sd-boot is available inside the ESP of foobar.raw a new item
will show up in the boot menu that allows booting directly into the
specified UKI.
2025-02-21 10:04:15 +01:00
Lennart Poettering
1089d0f89e boot: add new 'uki-url' bls type #1 menu items for booting remote UKIs
Companion BLS spec PR:

https://github.com/uapi-group/specifications/pull/135
2025-02-21 10:04:15 +01:00
Lennart Poettering
e2a3d56218 boot: add new bls type #1 stanza "uki"
This one is between "efi" and "linux": we'll recognize such entries as
linux, but we'll just invoke them as EFI binaries.

This creates a high-level concept for invoking UKIs via indirection of a
bls type #1 entry, for example to permit invocation from a non-standard
path or for giving entries a different name.

Companion BLS spec PR:

https://github.com/uapi-group/specifications/pull/135

(Let's rename LOADER_UNIFIED_LINUX to LOADER_TYPE2_UKI at the same time
to reduce confusion what is what)
2025-02-21 10:04:15 +01:00
Lennart Poettering
06648d4187 boot: move behaviour checks into per-entry-type helpers 2025-02-21 10:04:15 +01:00
Lennart Poettering
149609cfcb boot: be stricter when filtering out invalid bls #1 entries 2025-02-21 10:04:15 +01:00
Lennart Poettering
a6fbfd8db6 boot: bls type #1 with 'efi' stanza are bls type #1 too 2025-02-21 10:04:15 +01:00
Lennart Poettering
e15d18b4c6 sd-stub: if we are http booted, query source URL and write to EFI variable
This way userspace can read the field, and use it to retrieve more
resources from the same place.
2025-02-21 10:03:32 +01:00
Daan De Meyer
ff83795469 boot: Improve log message 2025-01-26 10:20:06 +09:00
Yu Watanabe
a8fe005209 tree-wide: drop merely used _cleanup_ macros, and introduce several new ones (#36071) 2025-01-21 03:41:27 +09:00
Yu Watanabe
99de29945f tree-wide: coding style fixlets done by coccinelle 2025-01-19 08:28:42 +09:00
Yu Watanabe
7eabb5ca61 boot: introduce _cleanup_strv_free_ 2025-01-19 04:18:04 +09:00
Yu Watanabe
6ea99fd2cf boot: introduce _cleanup_file_close_ 2025-01-19 04:15:27 +09:00
Zbigniew Jędrzejewski-Szmek
423de11f04 boot: exclude the trailing padding from initrd size in initrd_prepare()
This is a follow-up for f8fa4222c9 (boot: Make
initrd_prepare() semantically equivalent to combine_initrds()). That commit
changed the way that the initrd is prepared for type#1 boot loader entries,
also effectively rounding up the sizes to a multiple of 4. In [1], downstream
packagers report that the trailing zeroes result in the calculated hash being
different. To restore compatibility with previous hash calculations and
signatures, change the reported size by excluding the trailing padding. This
should restore the calculation results for the case where only one initrd is
used.

This patch doesn't touch the stub, i.e. doesn't change behaviour for UKIs. The
seems fine, since we didn't change that recently, so any changes there would
break compatiblity. The measurement results for type#1 and type#2 entries are
generally going to be different anyway. ukify and systemd-measure are also out
of scope here, because they are for UKIs.

Fixes https://github.com/systemd/systemd/issues/35439.
The other changes to the way the initrd is constructed are kept, so hopefully
the original issue with booting in qemu is not recreated.

[1] https://bugzilla.suse.com/show_bug.cgi?id=1233752

My simple test: I'm booting a QEMU VM with systemd-boot and a type#1 entry.
With old systemd-boot:
$ sudo systemd-pcrlock log | grep 'kernel-initrd.*event-tag'
  9 █ kernel-initrd  event-tag  - a337a8321bf81de5c53a842843e8f9a926f73a676e5620ff76df94d1c66bc931 F   - Linux: kernel command line
  9 █ kernel-initrd  event-tag  - aec1aee5358bde36f5498f2dc243dec2b103f81242de57b887a11f53677f1272 F   - Linux: initrd
With updated systemd-boot:
$ sudo systemd-pcrlock log | grep 'kernel-initrd.*event-tag'
  9 █ kernel-initrd  event-tag  - a337a8321bf81de5c53a842843e8f9a926f73a676e5620ff76df94d1c66bc931 F   - Linux: kernel command line
  9 █ kernel-initrd  event-tag  - 3ccaa710304aef8734a20265ea7fd3dd67d5461c6b3309c6d30d5c7d2a3ae7f9 F   - Linux: initrd
This matches the initrd hash:
$ sudo sha256sum /efi//26f948d2082e4ae89f5a3af351b63149/6.12.0-rc4+/initrd-dracut
3ccaa710304aef8734a20265ea7fd3dd67d5461c6b3309c6d30d5c7d2a3ae7f9  /efi//26f948d2082e4ae89f5a3af351b63149/6.12.0-rc4+/initrd-dracut
2024-12-09 15:14:03 +01:00
andre4ik3
6e207b370e boot/stub: allocate pages for combined initrds below 4GiB only on x86 (#35149)
Outside of x86, some machines (e.g. Apple silicon, AMD Opteron A1100)
have physical memory mapped above 4GiB, meaning this allocation will
fail, causing the entire boot process to fail on these machines.

This commit makes it so that the below-4GB address space allocation
requirement is only set on x86 platforms, and not on other platforms
(that don't have the specific Linux x86 boot protocol), thereby fixing
boot on those that have no memory mapped below 4GiB in their address
space.

Tested on an Apple silicon M1 laptop and an AMD x86_64 desktop tower.

Fixes: #35026
2024-11-14 13:20:09 +09:00
Zbigniew Jędrzejewski-Szmek
97318131fd Rename src/boot/efi to just src/boot
I very much dislike the approach in which we were mixing Linux and UEFI C code
in the same subdirectory. No code was shared between two environments. This
layout was created in e7dd673d1e, with the
justification of "being more consistent with the rest of systemd", but I don't
see how it's supposed to be so.

Originally, when the C code was just a single bootctl.c file, this wasn't so
bad. But over time the userspace code grew quite a bit. With the moves done in
previuos commits, the intermediate subdirectory is now empty except for the
efi/ subdir, and this additional subdirectory level doesn't have a good
justification. The components is called "systemd-boot", not "systemd-efi", and
we can remove one level of indentation.
2024-11-07 14:52:06 +01:00