kernel-install: configurable entry name format (#43290)
For some of us building image based operating systems with
`systemd-sysupdate` it's useful to have UKI filenames that encode
`IMAGE_VERSION` (and architecture). For example
`SimonOS_45.20260805.0_x86-64.efi`.
Currently to do this I have to manually post-process around the `.efi`
produced by `60-ukify` because it is named
`$ENTRY_TOKEN-$KERNEL_VERSION.efi`. It'd be very useful if I could skip
that step and instead have the image built directly without this
post-processing step; then extract the UKI and /usr partitions and plop
them onto my update server. It makes the build much more "install RPMs
into a tree and you're done" (barring other things `60-ukify` currently
can't do but I have follow-ups for those in mind).
This PR adds a knob to `install.conf` to let users specify a custom
format for the output filename for both UKI's and BLS entries produced
by `kernel-install`.
It accepts the following specifiers:
- `%e`: entry token
- `%v`: kernel version being installed
- Several common specifiers
The default is %e-%v, which is the current behavior. With
`entry_name_format=%M_%A_%a`, an OS with `IMAGE_ID=SimonOS` and
`IMAGE_VERSION=1.0` would get moved to `SimonOS_1.0_x86-64.efi`.
The resolved name is exported as `$KERNEL_INSTALL_ENTRY_NAME` for shell
plugins. Both `90-uki-copy.install` and `90-loaderentry.install` are
updated to use it, with a fallback to `$ENTRY_TOKEN-$KERNEL_VERSION` for
compatibility with older kernel-install versions.
This commit is contained in:
+76
-1
@@ -562,6 +562,13 @@
|
||||
on the file name and extension: Files named <filename>initrd*</filename> will be installed as <replaceable>INITRD-FILE</replaceable>s,
|
||||
and files named <filename>microcode*</filename> will be prepended before <replaceable>INITRD-FILE</replaceable>s.</para>
|
||||
|
||||
<para><varname>$KERNEL_INSTALL_ENTRY_NAME</varname> is set for the plugins to the resolved entry name,
|
||||
derived by expanding specifiers in the entry name format string. This is the base name (without file
|
||||
extension) used for UKI files, loader entry configuration files, and similar. By default this is
|
||||
<literal><replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable></literal>,
|
||||
matching the traditional naming. See <varname>$KERNEL_INSTALL_ENTRY_NAME_FORMAT</varname> below for
|
||||
details on the available specifiers.</para>
|
||||
|
||||
</refsect2>
|
||||
|
||||
<refsect2>
|
||||
@@ -589,6 +596,73 @@
|
||||
|
||||
<para>The last two variables may also be set in <filename>install.conf</filename>. Variables set in the
|
||||
environment take precedence over the values specified in the config file.</para>
|
||||
|
||||
<para><varname>$KERNEL_INSTALL_ENTRY_NAME_FORMAT</varname> can be set to configure the format string
|
||||
used to derive the entry name for boot loader entries and UKI files. The format string is expanded
|
||||
using specifier expansion. May also be configured as <varname>entry_name_format=</varname> in
|
||||
<filename>install.conf</filename>. The following specifiers are understood:</para>
|
||||
|
||||
<table class='specifiers'>
|
||||
<title>Specifiers available in <varname>$KERNEL_INSTALL_ENTRY_NAME_FORMAT</varname></title>
|
||||
<tgroup cols='3' align='left' colsep='1' rowsep='1'>
|
||||
<colspec colname="spec" />
|
||||
<colspec colname="mean" />
|
||||
<colspec colname="detail" />
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Specifier</entry>
|
||||
<entry>Meaning</entry>
|
||||
<entry>Details</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="a"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="A"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="B"/>
|
||||
<row>
|
||||
<entry><literal>%e</literal></entry>
|
||||
<entry>Entry token</entry>
|
||||
<entry>The entry token, same as <varname>$KERNEL_INSTALL_ENTRY_TOKEN</varname>.</entry>
|
||||
</row>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="H"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="l"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="m"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="M"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="o"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="q"/>
|
||||
<row>
|
||||
<entry><literal>%v</literal></entry>
|
||||
<entry>Kernel version</entry>
|
||||
<entry>The kernel version being installed. Note that unlike the common specifier <literal>%v</literal> which expands to the currently running kernel version (i.e. <command>uname -r</command>), here it refers to the target kernel version passed to <command>kernel-install</command>.</entry>
|
||||
</row>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="w"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="W"/>
|
||||
<xi:include href="standard-specifiers.xml" xpointer="percent"/>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
|
||||
<para>The resolved entry name must be a valid filename (no path separators). Defaults to
|
||||
<literal>%e-%v</literal>, which produces the traditional
|
||||
<literal><replaceable>ENTRY-TOKEN</replaceable>-<replaceable>KERNEL-VERSION</replaceable></literal>
|
||||
naming.</para>
|
||||
|
||||
<para>For example, setting <varname>entry_name_format=%M_%A_%a</varname> on a system with
|
||||
<varname>IMAGE_ID=myos</varname>, <varname>IMAGE_VERSION=20250830</varname>, and architecture
|
||||
<literal>x86-64</literal> would produce entry names like
|
||||
<literal>myos_20250830_x86-64</literal>.</para>
|
||||
|
||||
<para>Note that the entry name is resolved at the time of each
|
||||
<command>kernel-install</command> invocation. If the format string uses specifiers that
|
||||
depend on mutable system state (e.g. <literal>%M</literal>, <literal>%A</literal>,
|
||||
<literal>%H</literal>), and that state changes between installing and removing a kernel,
|
||||
the <command>remove</command> operation may compute a different entry name than
|
||||
<command>add</command> did, leaving stale files on the boot partition. The
|
||||
<varname>entry_name_format=</varname> setting should therefore remain stable across a
|
||||
kernel's install/remove lifecycle. Additionally, the format should produce a unique name
|
||||
for each installed kernel, e.g. by including <literal>%v</literal> (kernel version) or
|
||||
<literal>%A</literal> (<varname>IMAGE_VERSION</varname>); otherwise installing multiple
|
||||
kernels will overwrite each other's boot entries.</para>
|
||||
</refsect2>
|
||||
</refsect1>
|
||||
|
||||
@@ -726,7 +800,8 @@
|
||||
<varname>BOOT_ROOT=</varname>,
|
||||
<varname>layout=</varname>,
|
||||
<varname>initrd_generator=</varname>,
|
||||
<varname>uki_generator=</varname>.
|
||||
<varname>uki_generator=</varname>,
|
||||
<varname>entry_name_format=</varname>.
|
||||
See the Environment variables section above for details.</para>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v250"/>
|
||||
|
||||
@@ -338,7 +338,8 @@ static int load_kernel_install_layout(InstallContext *c) {
|
||||
/* ret_boot_root= */ NULL,
|
||||
&layout,
|
||||
/* ret_initrd_generator= */ NULL,
|
||||
/* ret_uki_generator= */ NULL);
|
||||
/* ret_uki_generator= */ NULL,
|
||||
/* ret_entry_name_format= */ NULL);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ fi
|
||||
MACHINE_ID="${KERNEL_INSTALL_MACHINE_ID:?}"
|
||||
ENTRY_TOKEN="${KERNEL_INSTALL_ENTRY_TOKEN:?}"
|
||||
BOOT_ROOT="${KERNEL_INSTALL_BOOT_ROOT:?}"
|
||||
ENTRY_NAME="${KERNEL_INSTALL_ENTRY_NAME:-$ENTRY_TOKEN-$KERNEL_VERSION}"
|
||||
|
||||
[ -n "$BOOT_MNT" ] || BOOT_MNT="$(stat -c %m "$BOOT_ROOT")"
|
||||
if [ "$BOOT_MNT" = '/' ]; then
|
||||
@@ -45,7 +46,7 @@ fi
|
||||
|
||||
KERNEL_DEST="$ENTRY_DIR_ABS/linux"
|
||||
KERNEL_ENTRY="$ENTRY_DIR/linux"
|
||||
LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION.conf"
|
||||
LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_NAME.conf"
|
||||
|
||||
case "$COMMAND" in
|
||||
remove)
|
||||
|
||||
@@ -28,6 +28,7 @@ KERNEL_IMAGE="$4"
|
||||
|
||||
ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN"
|
||||
BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
|
||||
ENTRY_NAME="${KERNEL_INSTALL_ENTRY_NAME:-$ENTRY_TOKEN-$KERNEL_VERSION}"
|
||||
|
||||
UKI_DIR="$BOOT_ROOT/EFI/Linux"
|
||||
|
||||
@@ -39,11 +40,11 @@ case "$COMMAND" in
|
||||
exit 0
|
||||
fi
|
||||
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
|
||||
echo "Removing $UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION*.efi and extras"
|
||||
echo "Removing $UKI_DIR/$ENTRY_NAME*.efi and extras"
|
||||
exec rm -rf \
|
||||
"$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi" \
|
||||
"$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi.extra.d/" \
|
||||
"$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+"*".efi"
|
||||
"$UKI_DIR/$ENTRY_NAME.efi" \
|
||||
"$UKI_DIR/$ENTRY_NAME.efi.extra.d/" \
|
||||
"$UKI_DIR/$ENTRY_NAME+"*".efi"
|
||||
;;
|
||||
add)
|
||||
;;
|
||||
@@ -67,24 +68,24 @@ if [ -f "$TRIES_FILE" ]; then
|
||||
echo "$TRIES_FILE does not contain an integer." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -f "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi" ]; then
|
||||
if [ -f "$UKI_DIR/$ENTRY_NAME.efi" ]; then
|
||||
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
|
||||
echo "Removing previous UKI '$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi' without boot counting." >&2
|
||||
rm -f "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi"
|
||||
echo "Removing previous UKI '$UKI_DIR/$ENTRY_NAME.efi' without boot counting." >&2
|
||||
rm -f "$UKI_DIR/$ENTRY_NAME.efi"
|
||||
fi
|
||||
for uki in "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+"*.efi; do
|
||||
[ "$uki" = "$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+*.efi" ] && break
|
||||
for uki in "$UKI_DIR/$ENTRY_NAME+"*.efi; do
|
||||
[ "$uki" = "$UKI_DIR/$ENTRY_NAME+*.efi" ] && break
|
||||
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
|
||||
echo "Removing previous UKI '$uki' that has not yet booted successfully." >&2
|
||||
rm -f "$uki"
|
||||
done
|
||||
|
||||
UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.efi"
|
||||
UKI_FILE="$UKI_DIR/$ENTRY_NAME+$TRIES.efi"
|
||||
else
|
||||
UKI_FILE="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi"
|
||||
UKI_FILE="$UKI_DIR/$ENTRY_NAME.efi"
|
||||
fi
|
||||
|
||||
EXTRA_DIR="$UKI_DIR/$ENTRY_TOKEN-$KERNEL_VERSION.efi.extra.d"
|
||||
EXTRA_DIR="$UKI_DIR/$ENTRY_NAME.efi.extra.d"
|
||||
|
||||
# If there is a UKI named uki.efi on the staging area use that, if not use what
|
||||
# was passed in as $KERNEL_IMAGE but insist it has a .efi extension
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "path-util.h"
|
||||
#include "recurse-dir.h"
|
||||
#include "rm-rf.h"
|
||||
#include "specifier.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
@@ -108,12 +109,19 @@ typedef struct Context {
|
||||
char **initrds;
|
||||
char *initrd_generator;
|
||||
char *uki_generator;
|
||||
char *entry_name_format;
|
||||
char *entry_name;
|
||||
char *staging_area;
|
||||
char **plugins;
|
||||
char **argv;
|
||||
char **envp;
|
||||
} Context;
|
||||
|
||||
/* Longest filename suffix plugins append to the entry name (from 90-uki-copy.install) */
|
||||
#define ENTRY_NAME_SUFFIX_MAX STRLEN(".efi.extra.d")
|
||||
|
||||
#define DEFAULT_ENTRY_NAME_FORMAT "%e-%v"
|
||||
|
||||
#define CONTEXT_NULL \
|
||||
(Context) { \
|
||||
.rfd = XAT_FDROOT, \
|
||||
@@ -137,6 +145,8 @@ static void context_done(Context *c) {
|
||||
strv_free(c->initrds);
|
||||
free(c->initrd_generator);
|
||||
free(c->uki_generator);
|
||||
free(c->entry_name_format);
|
||||
free(c->entry_name);
|
||||
if (c->action == ACTION_INSPECT)
|
||||
free(c->staging_area);
|
||||
else
|
||||
@@ -199,6 +209,9 @@ static int context_copy(const Context *source, Context *ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
r = strdup_to(©.uki_generator, source->uki_generator);
|
||||
if (r < 0)
|
||||
return r;
|
||||
r = strdup_to(©.entry_name_format, source->entry_name_format);
|
||||
if (r < 0)
|
||||
return r;
|
||||
r = strdup_to(©.staging_area, source->staging_area);
|
||||
@@ -327,6 +340,63 @@ static int context_set_uki_generator(Context *c, const char *s, const char *sour
|
||||
return context_set_string(s, source, "UKI_GENERATOR", &c->uki_generator);
|
||||
}
|
||||
|
||||
static int context_set_entry_name_format(Context *c, const char *s, const char *source) {
|
||||
assert(c);
|
||||
return context_set_string(s, source, "ENTRY_NAME_FORMAT", &c->entry_name_format);
|
||||
}
|
||||
|
||||
static int context_resolve_entry_name(Context *c) {
|
||||
assert(c);
|
||||
|
||||
if (c->entry_name)
|
||||
return 0;
|
||||
|
||||
const Specifier table[] = {
|
||||
{ 'e', specifier_string, c->entry_token },
|
||||
{ 'm', specifier_id128, &c->machine_id },
|
||||
{ 'v', specifier_string, c->version ?: "KERNEL_VERSION" },
|
||||
{ 'a', specifier_architecture, NULL },
|
||||
{ 'A', specifier_os_image_version, NULL },
|
||||
{ 'B', specifier_os_build_id, NULL },
|
||||
{ 'H', specifier_hostname, NULL },
|
||||
{ 'l', specifier_short_hostname, NULL },
|
||||
{ 'q', specifier_pretty_hostname, NULL },
|
||||
{ 'M', specifier_os_image_id, NULL },
|
||||
{ 'o', specifier_os_id, NULL },
|
||||
{ 'w', specifier_os_version_id, NULL },
|
||||
{ 'W', specifier_os_variant_id, NULL },
|
||||
{}
|
||||
};
|
||||
|
||||
_cleanup_free_ char *resolved = NULL;
|
||||
int r;
|
||||
|
||||
r = specifier_printf(
|
||||
c->entry_name_format ?: DEFAULT_ENTRY_NAME_FORMAT,
|
||||
NAME_MAX - ENTRY_NAME_SUFFIX_MAX,
|
||||
table,
|
||||
arg_root,
|
||||
/* userdata= */ c,
|
||||
&resolved);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to expand entry name format '%s': %m",
|
||||
c->entry_name_format ?: DEFAULT_ENTRY_NAME_FORMAT);
|
||||
|
||||
if (isempty(resolved))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Entry name format '%s' resolved to empty string.",
|
||||
c->entry_name_format ?: DEFAULT_ENTRY_NAME_FORMAT);
|
||||
|
||||
if (!filename_is_valid(resolved))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Entry name format '%s' resolved to invalid filename: %s",
|
||||
c->entry_name_format ?: DEFAULT_ENTRY_NAME_FORMAT, resolved);
|
||||
|
||||
c->entry_name = TAKE_PTR(resolved);
|
||||
log_debug("Using entry name: %s", c->entry_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int context_set_version(Context *c, const char *s) {
|
||||
assert(c);
|
||||
|
||||
@@ -449,12 +519,14 @@ static int context_load_environment(Context *c) {
|
||||
(void) context_set_boot_root(c, getenv("BOOT_ROOT"), "environment");
|
||||
(void) context_set_conf_root(c, getenv("KERNEL_INSTALL_CONF_ROOT"), "environment");
|
||||
(void) context_set_plugins(c, getenv("KERNEL_INSTALL_PLUGINS"), "environment");
|
||||
(void) context_set_entry_name_format(c, getenv("KERNEL_INSTALL_ENTRY_NAME_FORMAT"), "environment");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int context_load_install_conf(Context *c) {
|
||||
_cleanup_free_ char *machine_id = NULL, *boot_root = NULL, *layout = NULL,
|
||||
*initrd_generator = NULL, *uki_generator = NULL;
|
||||
*initrd_generator = NULL, *uki_generator = NULL,
|
||||
*entry_name_format = NULL;
|
||||
int r;
|
||||
|
||||
assert(c);
|
||||
@@ -467,7 +539,8 @@ static int context_load_install_conf(Context *c) {
|
||||
&boot_root,
|
||||
&layout,
|
||||
&initrd_generator,
|
||||
&uki_generator);
|
||||
&uki_generator,
|
||||
&entry_name_format);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
@@ -476,6 +549,7 @@ static int context_load_install_conf(Context *c) {
|
||||
(void) context_set_layout(c, layout, "config");
|
||||
(void) context_set_initrd_generator(c, initrd_generator, "config");
|
||||
(void) context_set_uki_generator(c, uki_generator, "config");
|
||||
(void) context_set_entry_name_format(c, entry_name_format, "config");
|
||||
|
||||
log_debug("Loaded config.");
|
||||
return 0;
|
||||
@@ -1032,6 +1106,10 @@ static int context_build_environment(Context *c) {
|
||||
if (c->envp)
|
||||
return 0;
|
||||
|
||||
r = context_resolve_entry_name(c);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = strv_env_assign_many(&e,
|
||||
"LC_COLLATE", SYSTEMD_DEFAULT_LOCALE,
|
||||
"KERNEL_INSTALL_VERBOSE", one_zero(arg_verbose),
|
||||
@@ -1043,7 +1121,8 @@ static int context_build_environment(Context *c) {
|
||||
"KERNEL_INSTALL_INITRD_GENERATOR", strempty(c->initrd_generator),
|
||||
"KERNEL_INSTALL_UKI_GENERATOR", strempty(c->uki_generator),
|
||||
"KERNEL_INSTALL_BOOT_ENTRY_TYPE", boot_entry_type_to_string(c->entry_type),
|
||||
"KERNEL_INSTALL_STAGING_AREA", c->staging_area);
|
||||
"KERNEL_INSTALL_STAGING_AREA", c->staging_area,
|
||||
"KERNEL_INSTALL_ENTRY_NAME", c->entry_name);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to build environment variables for plugins: %m");
|
||||
|
||||
@@ -1413,6 +1492,10 @@ static int verb_inspect(int argc, char *argv[], uintptr_t _data, void *userdata)
|
||||
TABLE_STRING, boot_entry_token_type_to_string(c.entry_token_type),
|
||||
TABLE_FIELD, "Entry Token",
|
||||
TABLE_STRING, c.entry_token,
|
||||
TABLE_FIELD, "Entry Name Format",
|
||||
TABLE_STRING, c.entry_name_format ?: DEFAULT_ENTRY_NAME_FORMAT,
|
||||
TABLE_FIELD, "Entry Name",
|
||||
TABLE_STRING, c.entry_name,
|
||||
TABLE_FIELD, "Entry Directory",
|
||||
TABLE_STRING, c.entry_dir,
|
||||
TABLE_FIELD, "Kernel Version",
|
||||
|
||||
@@ -294,6 +294,99 @@ test ! -e "$BOOT_ROOT/hoge/1.1.1"
|
||||
test -d "$BOOT_ROOT/hoge"
|
||||
rmdir "$BOOT_ROOT/hoge"
|
||||
|
||||
###########################################
|
||||
# tests for entry_name_format=
|
||||
###########################################
|
||||
|
||||
# Test inspect with custom entry_name_format
|
||||
cat >>"$D/sources/install.conf" <<EOF
|
||||
entry_name_format=%e_%v
|
||||
EOF
|
||||
|
||||
output="$("$kernel_install" -v --json=pretty inspect 1.1.1 "$D/sources/linux")"
|
||||
echo "$output" | grep -E '"EntryNameFormat" : "%e_%v"' >/dev/null
|
||||
echo "$output" | grep -E '"EntryName" : "the-token_1.1.1"' >/dev/null
|
||||
|
||||
# Test type#1 BLS entry with custom entry_name_format
|
||||
rm -f "$D/sources/tries"
|
||||
cat >"$D/sources/install.conf" <<EOF
|
||||
layout=bls
|
||||
initrd_generator=none
|
||||
entry_name_format=%e_%v
|
||||
EOF
|
||||
|
||||
KERNEL_INSTALL_PLUGINS="'${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v add 1.1.4 "$D/sources/linux" "$D/sources/initrd"
|
||||
entry="$BOOT_ROOT/loader/entries/the-token_1.1.4.conf"
|
||||
test -f "$entry"
|
||||
grep -qE '^version +1.1.4' "$entry"
|
||||
KERNEL_INSTALL_PLUGINS="'${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v remove 1.1.4
|
||||
test ! -e "$entry"
|
||||
rm -rf "$BOOT_ROOT/the-token"
|
||||
|
||||
# Test UKI with custom entry_name_format
|
||||
if [ -f "$ukify" ]; then
|
||||
cat >"$D/sources/install.conf" <<EOF
|
||||
layout=uki
|
||||
uki_generator=ukify
|
||||
initrd_generator=none
|
||||
entry_name_format=%e_%v
|
||||
EOF
|
||||
rm -f "$D/sources/tries"
|
||||
|
||||
KERNEL_INSTALL_PLUGINS="'${ukify_install}' '${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v add 1.1.5 "$D/sources/linux" "$D/sources/initrd"
|
||||
uki="${BOOT_ROOT}/EFI/Linux/the-token_1.1.5.efi"
|
||||
test -f "$uki"
|
||||
KERNEL_INSTALL_PLUGINS="'${ukify_install}' '${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v remove 1.1.5
|
||||
test ! -e "$uki"
|
||||
|
||||
# Test boot counting with custom entry_name_format
|
||||
echo '56' >"$D/sources/tries"
|
||||
KERNEL_INSTALL_PLUGINS="'${ukify_install}' '${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v add 1.1.5 "$D/sources/linux" "$D/sources/initrd"
|
||||
uki="${BOOT_ROOT}/EFI/Linux/the-token_1.1.5+56.efi"
|
||||
test -f "$uki"
|
||||
KERNEL_INSTALL_PLUGINS="'${ukify_install}' '${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v remove 1.1.5
|
||||
test ! -e "$uki"
|
||||
|
||||
rm -f "$D/sources/tries"
|
||||
fi
|
||||
|
||||
# Test add-all with custom entry_name_format (exercises context_copy)
|
||||
KVER="$(uname -r)"
|
||||
if test -f "/usr/lib/modules/$KVER/vmlinuz"; then
|
||||
rm -rf "$BOOT_ROOT"
|
||||
mkdir -p "$BOOT_ROOT"
|
||||
cat >"$D/sources/install.conf" <<EOF
|
||||
layout=bls
|
||||
initrd_generator=none
|
||||
entry_name_format=%e_%v
|
||||
EOF
|
||||
|
||||
KERNEL_INSTALL_PLUGINS="'${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v add-all
|
||||
entry="$BOOT_ROOT/loader/entries/the-token_${KVER}.conf"
|
||||
test -f "$entry"
|
||||
grep -qE "^version +${KVER}" "$entry"
|
||||
KERNEL_INSTALL_PLUGINS="'${loaderentry_install}' '${uki_copy_install}'" \
|
||||
"$kernel_install" -v remove "$KVER"
|
||||
test ! -e "$entry"
|
||||
rm -rf "$BOOT_ROOT/the-token"
|
||||
fi
|
||||
|
||||
# Restore install.conf and plugins
|
||||
cat >"$D/sources/install.conf" <<EOF
|
||||
initrd_generator=none
|
||||
# those are overridden by envvars
|
||||
BOOT_ROOT="$D/badboot"
|
||||
MACHINE_ID=badbadbadbadbadbad6abadbadbadbad
|
||||
EOF
|
||||
export KERNEL_INSTALL_PLUGINS="$D/00-skip.install"
|
||||
|
||||
###########################################
|
||||
# tests for --json=
|
||||
###########################################
|
||||
@@ -307,6 +400,8 @@ diff -u <(echo "$output") - >&2 <<EOF
|
||||
"BootRoot" : "$BOOT_ROOT",
|
||||
"EntryTokenType" : "literal",
|
||||
"EntryToken" : "the-token",
|
||||
"EntryNameFormat" : "%e-%v",
|
||||
"EntryName" : "the-token-1.1.1",
|
||||
"EntryDirectory" : "$BOOT_ROOT/the-token/1.1.1",
|
||||
"KernelVersion" : "1.1.1",
|
||||
"Kernel" : "$D/sources/linux",
|
||||
@@ -326,7 +421,8 @@ diff -u <(echo "$output") - >&2 <<EOF
|
||||
"KERNEL_INSTALL_LAYOUT=other",
|
||||
"KERNEL_INSTALL_INITRD_GENERATOR=none",
|
||||
"KERNEL_INSTALL_UKI_GENERATOR=",
|
||||
"KERNEL_INSTALL_STAGING_AREA=${TMPDIR:-/var/tmp}/kernel-install.staging.XXXXXX"
|
||||
"KERNEL_INSTALL_STAGING_AREA=${TMPDIR:-/var/tmp}/kernel-install.staging.XXXXXX",
|
||||
"KERNEL_INSTALL_ENTRY_NAME=the-token-1.1.1"
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
@@ -14,16 +14,19 @@ int load_kernel_install_conf_at(
|
||||
char **ret_boot_root,
|
||||
char **ret_layout,
|
||||
char **ret_initrd_generator,
|
||||
char **ret_uki_generator) {
|
||||
char **ret_uki_generator,
|
||||
char **ret_entry_name_format) {
|
||||
|
||||
_cleanup_free_ char *machine_id = NULL, *boot_root = NULL, *layout = NULL,
|
||||
*initrd_generator = NULL, *uki_generator = NULL;
|
||||
*initrd_generator = NULL, *uki_generator = NULL,
|
||||
*entry_name_format = NULL;
|
||||
const ConfigTableItem items[] = {
|
||||
{ NULL, "MACHINE_ID", config_parse_string, 0, &machine_id },
|
||||
{ NULL, "BOOT_ROOT", config_parse_string, 0, &boot_root },
|
||||
{ NULL, "layout", config_parse_string, 0, &layout },
|
||||
{ NULL, "initrd_generator", config_parse_string, 0, &initrd_generator },
|
||||
{ NULL, "uki_generator", config_parse_string, 0, &uki_generator },
|
||||
{ NULL, "MACHINE_ID", config_parse_string, 0, &machine_id },
|
||||
{ NULL, "BOOT_ROOT", config_parse_string, 0, &boot_root },
|
||||
{ NULL, "layout", config_parse_string, 0, &layout },
|
||||
{ NULL, "initrd_generator", config_parse_string, 0, &initrd_generator },
|
||||
{ NULL, "uki_generator", config_parse_string, 0, &uki_generator },
|
||||
{ NULL, "entry_name_format", config_parse_string, 0, &entry_name_format },
|
||||
{}
|
||||
};
|
||||
int r;
|
||||
@@ -71,5 +74,7 @@ int load_kernel_install_conf_at(
|
||||
*ret_initrd_generator = TAKE_PTR(initrd_generator);
|
||||
if (ret_uki_generator)
|
||||
*ret_uki_generator = TAKE_PTR(uki_generator);
|
||||
if (ret_entry_name_format)
|
||||
*ret_entry_name_format = TAKE_PTR(entry_name_format);
|
||||
return r >= 0; /* Return 0 if we got -ENOENT above, 1 otherwise. */
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ int load_kernel_install_conf_at(
|
||||
char **ret_boot_root,
|
||||
char **ret_layout,
|
||||
char **ret_initrd_generator,
|
||||
char **ret_uki_generator);
|
||||
char **ret_uki_generator,
|
||||
char **ret_entry_name_format);
|
||||
|
||||
static inline int load_kernel_install_conf(
|
||||
const char *root,
|
||||
@@ -21,7 +22,8 @@ static inline int load_kernel_install_conf(
|
||||
char **ret_boot_root,
|
||||
char **ret_layout,
|
||||
char **ret_initrd_generator,
|
||||
char **ret_uki_generator) {
|
||||
char **ret_uki_generator,
|
||||
char **ret_entry_name_format) {
|
||||
|
||||
return load_kernel_install_conf_at(root, XAT_FDROOT, conf_root, ret_machine_id, ret_boot_root, ret_layout, ret_initrd_generator, ret_uki_generator);
|
||||
return load_kernel_install_conf_at(root, XAT_FDROOT, conf_root, ret_machine_id, ret_boot_root, ret_layout, ret_initrd_generator, ret_uki_generator, ret_entry_name_format);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user