Skip to content

Commit 0ccfd35

Browse files
behrmannpoettering
authored andcommitted
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.
1 parent 87a7084 commit 0ccfd35

File tree

3 files changed

+131
-6
lines changed

3 files changed

+131
-6
lines changed

man/kernel-install.xml

+32-6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@
108108
is missing), or "Linux <replaceable>KERNEL-VERSION</replaceable>", if unset.</para>
109109

110110
<para>If <varname>$KERNEL_INSTALL_LAYOUT</varname> is not "bls", this plugin does nothing.</para></listitem>
111+
112+
<listitem><para><filename>90-uki-copy.install</filename> copies a file
113+
<filename>uki.efi</filename> from <varname>$KERNEL_INSTALL_STAGING_AREA</varname> or if it does
114+
not exist the <replaceable>KERNEL-IMAGE</replaceable> argument, iff it has a
115+
<literal>.efi</literal> extension, to
116+
<filename>$BOOT/EFI/Linux/<replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable>.efi</filename>.</para>
117+
118+
<para>If <varname>$KERNEL_INSTALL_LAYOUT</varname> is not "uki", this plugin does nothing.</para></listitem>
111119
</itemizedlist>
112120
</listitem>
113121
</varlistentry>
@@ -132,6 +140,9 @@
132140

133141
<listitem><para><filename>90-loaderentry.install</filename> removes the file
134142
<filename>$BOOT/loader/entries/<replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable>.conf</filename>.</para></listitem>
143+
144+
<listitem><para><filename>90-uki-copy.install</filename> removes the file
145+
<filename>$BOOT/EFI/Linux/<replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable>.efi</filename>.</para></listitem>
135146
</itemizedlist>
136147
</listitem>
137148
</varlistentry>
@@ -213,7 +224,7 @@
213224
(EFI System Partition) are mounted, and also conceptually referred to as <varname>$BOOT</varname>. Can
214225
be overridden by setting <varname>$BOOT_ROOT</varname> (see below).</para>
215226

216-
<para><varname>$KERNEL_INSTALL_LAYOUT=bls|other|...</varname> is set for the plugins to specify the
227+
<para><varname>$KERNEL_INSTALL_LAYOUT=bls|uki|other|...</varname> is set for the plugins to specify the
217228
installation layout. Defaults to <option>bls</option> if
218229
<filename>$BOOT/<replaceable>ENTRY-TOKEN</replaceable></filename> exists, or <option>other</option>
219230
otherwise. Additional layout names may be defined by convention. If a plugin uses a special layout,
@@ -235,6 +246,18 @@
235246
<para>Implemented by <filename>90-loaderentry.install</filename>.</para>
236247
</listitem>
237248
</varlistentry>
249+
<varlistentry>
250+
<term>uki</term>
251+
<listitem>
252+
<para>Standard <ulink
253+
url="https://uapi-group.org/specifications/specs/boot_loader_specification">Boot Loader
254+
Specification</ulink> Type #2 layout, compatible with
255+
<citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>:
256+
unified kernel images under <filename>$BOOT/EFI/Linux</filename> as
257+
<filename>$BOOT/EFI/Linux/<replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable>[+<replaceable>TRIES</replaceable>].efi</filename>.</para>
258+
<para>Implemented by <filename>90-uki-copy.install</filename>.</para>
259+
</listitem>
260+
</varlistentry>
238261
<varlistentry>
239262
<term>other</term>
240263
<listitem>
@@ -312,12 +335,15 @@
312335
<filename>/etc/kernel/tries</filename>
313336
</term>
314337
<listitem>
315-
<para>Read by <filename>90-loaderentry.install</filename>. If this file exists a numeric value is read from
316-
it and the naming of the generated entry file is slightly altered to include it as
317-
<filename>$BOOT/loader/entries/<replaceable>MACHINE-ID</replaceable>-<replaceable>KERNEL-VERSION</replaceable>+<replaceable>TRIES</replaceable>.conf</filename>. This
338+
<para>Read by <filename>90-loaderentry.install</filename> and
339+
<filename>90-uki-copy.install</filename>. If this file exists a numeric value is read from it
340+
and the naming of the generated entry file or UKI is slightly altered to include it as
341+
<filename>$BOOT/loader/entries/<replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable>+<replaceable>TRIES</replaceable>.conf</filename>
342+
or
343+
<filename>$BOOT/EFI/Linux/<replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable>+<replaceable>TRIES</replaceable>.conf</filename>, respectively. This
318344
is useful for boot loaders such as
319-
<citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry> which
320-
implement boot attempt counting with a counter embedded in the entry file name.
345+
<citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry>
346+
which implement boot attempt counting with a counter embedded in the entry file name.
321347
<varname>$KERNEL_INSTALL_CONF_ROOT</varname> may be used to override the path.</para>
322348
</listitem>
323349
</varlistentry>
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3+
# ex: ts=8 sw=4 sts=4 et filetype=sh
4+
# SPDX-License-Identifier: LGPL-2.1-or-later
5+
#
6+
# This file is part of systemd.
7+
#
8+
# systemd is free software; you can redistribute it and/or modify it
9+
# under the terms of the GNU Lesser General Public License as published by
10+
# the Free Software Foundation; either version 2.1 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# systemd is distributed in the hope that it will be useful, but
14+
# WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU Lesser General Public License
19+
# along with systemd; If not, see <https://www.gnu.org/licenses/>.
20+
21+
set -e
22+
23+
COMMAND="${1:?}"
24+
KERNEL_VERSION="${2:?}"
25+
# shellcheck disable=SC2034
26+
ENTRY_DIR_ABS="$3"
27+
KERNEL_IMAGE="$4"
28+
29+
[ "$KERNEL_INSTALL_LAYOUT" = "uki" ] || exit 0
30+
31+
ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN"
32+
BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
33+
34+
UKI_DIR="$BOOT_ROOT/EFI/Linux"
35+
36+
case "$COMMAND" in
37+
remove)
38+
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
39+
echo "Removing $UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION*.efi"
40+
exec rm -f \
41+
"$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi" \
42+
"$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+"*".efi"
43+
;;
44+
add)
45+
;;
46+
*)
47+
exit 0
48+
;;
49+
esac
50+
51+
if ! [ -d "$UKI_DIR" ]; then
52+
echo "Error: entry directory '$UKI_DIR' does not exist" >&2
53+
exit 1
54+
fi
55+
56+
TRIES_FILE="${KERNEL_INSTALL_CONF_ROOT:-/etc/kernel}/tries"
57+
58+
if [ -f "$TRIES_FILE" ]; then
59+
read -r TRIES <"$TRIES_FILE"
60+
if ! echo "$TRIES" | grep -q '^[0-9][0-9]*$'; then
61+
echo "$TRIES_FILE does not contain an integer." >&2
62+
exit 1
63+
fi
64+
UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.efi"
65+
else
66+
UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi"
67+
fi
68+
69+
# If there is a UKI named uki.efi on the staging area use that, if not use what
70+
# was passed in as $KERNEL_IMAGE but insist it has a .efi extension
71+
if [ -f "$KERNEL_INSTALL_STAGING_AREA/uki.efi" ]; then
72+
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Installing $KERNEL_INSTALL_STAGING_AREA/uki.efi"
73+
install -m 0644 "$KERNEL_INSTALL_STAGING_AREA/uki.efi" "$UKI_FILE" || {
74+
echo "Error: could not copy '$KERNEL_INSTALL_STAGING_AREA/uki.efi' to '$UKI_FILE'." >&2
75+
exit 1
76+
}
77+
elif [ -n "$KERNEL_IMAGE" ]; then
78+
[ -f "$KERNEL_IMAGE" ] || {
79+
echo "Error: UKI '$KERNEL_IMAGE' not a file." >&2
80+
exit 1
81+
}
82+
[ "$KERNEL_IMAGE" != "${KERNEL_IMAGE%*.efi}.efi" ] && {
83+
echo "Error: $KERNEL_IMAGE is missing .efi suffix." >&2
84+
exit 1
85+
}
86+
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Installing $KERNEL_IMAGE"
87+
install -m 0644 "$KERNEL_IMAGE" "$UKI_FILE" || {
88+
echo "Error: could not copy '$KERNEL_IMAGE' to '$UKI_FILE'." >&2
89+
exit 1
90+
}
91+
else
92+
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "No UKI available. Nothing to do."
93+
exit 0
94+
fi
95+
chown root:root "$UKI_FILE" || :
96+
97+
exit 0

src/kernel-install/meson.build

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ loaderentry_install = custom_target(
1212
install_mode : 'rwxr-xr-x',
1313
install_dir : kernelinstalldir)
1414

15+
uki_copy_install = files('90-uki-copy.install')
16+
1517
if want_kernel_install
1618
install_data('50-depmod.install',
1719
install_mode : 'rwxr-xr-x',

0 commit comments

Comments
 (0)