summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-07-01 10:58:01 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-07-06 16:33:11 +0200
commit91199185b1449edb884dd2e85c6486027c440a34 (patch)
treebcdd22e0b9923b07d6d4d955902cad3c4ebbbee5
parent035f8acdf737ee5e0c49feaa14dd8cfcea0ffa5f (diff)
downloadsystemd-91199185b1449edb884dd2e85c6486027c440a34.tar.gz
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.
-rw-r--r--man/kernel-install.xml23
-rw-r--r--src/kernel-install/90-loaderentry.install14
-rwxr-xr-xsrc/kernel-install/kernel-install.in14
3 files changed, 35 insertions, 16 deletions
diff --git a/man/kernel-install.xml b/man/kernel-install.xml
index bb22443854..bde30ab16a 100644
--- a/man/kernel-install.xml
+++ b/man/kernel-install.xml
@@ -250,13 +250,18 @@
<refsect2>
<title>Environment variables understood by <command>kernel-install</command></title>
+ <para><varname>$KERNEL_INSTALL_CONF_ROOT</varname> can be set to override the location of the
+ configuration files read by <command>kernel-install</command>. When set,
+ <filename>install.conf</filename>, <filename>entry-token</filename>, and other files will be
+ read from this directory.</para>
+
<para><varname>$MACHINE_ID</varname> can be set for <command>kernel-install</command> to override
<varname>$KERNEL_INSTALL_MACHINE_ID</varname>, the machine ID.</para>
<para><varname>$BOOT_ROOT</varname> can be set for <command>kernel-install</command> to override
<varname>$KERNEL_INSTALL_BOOT_ROOT</varname>, the installation location for boot entries.</para>
- <para>Those variables may also be set in <filename>install.conf</filename>. Variables set in the
+ <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>
</refsect2>
</refsect1>
@@ -286,9 +291,10 @@
</term>
<listitem>
<para>Read by <filename>90-loaderentry.install</filename>. The content of the file
- <filename>/etc/kernel/cmdline</filename> specifies the kernel command line to use. If that file does not
- exist, <filename>/usr/lib/kernel/cmdline</filename> is used. If that also does not exist,
- <filename>/proc/cmdline</filename> is used.</para>
+ <filename>/etc/kernel/cmdline</filename> specifies the kernel command line to use. If that file
+ does not exist, <filename>/usr/lib/kernel/cmdline</filename> is used. If that also does not
+ exist, <filename>/proc/cmdline</filename> is used. <varname>$KERNEL_INSTALL_CONF_ROOT</varname>
+ may be used to override the path.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -301,7 +307,8 @@
<filename>$BOOT/loader/entries/<replaceable>MACHINE-ID</replaceable>-<replaceable>KERNEL-VERSION</replaceable>+<replaceable>TRIES</replaceable>.conf</filename>. This
is useful for boot loaders such as
<citerefentry><refentrytitle>systemd-boot</refentrytitle><manvolnum>7</manvolnum></citerefentry> which
- implement boot attempt counting with a counter embedded in the entry file name.</para>
+ implement boot attempt counting with a counter embedded in the entry file name.
+ <varname>$KERNEL_INSTALL_CONF_ROOT</varname> may be used to override the path.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -310,8 +317,9 @@
</term>
<listitem>
<para>If this file exists it is read and used as "entry token" for this system, i.e. is used for
- naming Boot Loader Specification entries, see
- <varname>$KERNEL_INSTALL_ENTRY_TOKEN</varname> above for details.</para>
+ naming Boot Loader Specification entries, see <varname>$KERNEL_INSTALL_ENTRY_TOKEN</varname>
+ above for details. <varname>$KERNEL_INSTALL_CONF_ROOT</varname> may be used to override the
+ path.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -346,6 +354,7 @@
<citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
<filename>/etc/kernel/install.conf</filename> will be read if present, and
<filename>/usr/lib/kernel/install.conf</filename> otherwise. This file is optional.
+ <varname>$KERNEL_INSTALL_CONF_ROOT</varname> may be used to override the path.
</para>
<para>Currently, the following keys are supported:
diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install
index ee55965110..b700a7b2a6 100644
--- a/src/kernel-install/90-loaderentry.install
+++ b/src/kernel-install/90-loaderentry.install
@@ -65,7 +65,11 @@ fi
SORT_KEY="$IMAGE_ID"
[ -z "$SORT_KEY" ] && SORT_KEY="$ID"
-if [ -f /etc/kernel/cmdline ]; then
+if [ -n "$KERNEL_INSTALL_CONF_ROOT" ]; then
+ if [ -f "$KERNEL_INSTALL_CONF_ROOT/cmdline" ]; then
+ BOOT_OPTIONS="$(tr -s "$IFS" ' ' <"$KERNEL_INSTALL_CONF_ROOT/cmdline")"
+ fi
+elif [ -f /etc/kernel/cmdline ]; then
BOOT_OPTIONS="$(tr -s "$IFS" ' ' </etc/kernel/cmdline)"
elif [ -f /usr/lib/kernel/cmdline ]; then
BOOT_OPTIONS="$(tr -s "$IFS" ' ' </usr/lib/kernel/cmdline)"
@@ -83,10 +87,12 @@ if [ "$ENTRY_TOKEN" = "$MACHINE_ID" ]; then
BOOT_OPTIONS="$BOOT_OPTIONS systemd.machine_id=$MACHINE_ID"
fi
-if [ -f /etc/kernel/tries ]; then
- read -r TRIES </etc/kernel/tries
+TRIES_FILE="${KERNEL_INSTALL_CONF_ROOT:-/etc/kernel}/tries"
+
+if [ -f "$TRIES_FILE" ]; then
+ read -r TRIES <"$TRIES_FILE"
if ! echo "$TRIES" | grep -q '^[0-9][0-9]*$'; then
- echo "/etc/kernel/tries does not contain an integer." >&2
+ echo "$TRIES_FILE does not contain an integer." >&2
exit 1
fi
LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.conf"
diff --git a/src/kernel-install/kernel-install.in b/src/kernel-install/kernel-install.in
index 044ba9f6f2..96595fa295 100755
--- a/src/kernel-install/kernel-install.in
+++ b/src/kernel-install/kernel-install.in
@@ -108,7 +108,9 @@ initrd_generator=
_MACHINE_ID_SAVED="$MACHINE_ID"
_BOOT_ROOT_SAVED="$BOOT_ROOT"
-if [ -f "/etc/kernel/install.conf" ]; then
+if [ -n "$KERNEL_INSTALL_CONF_ROOT" ]; then
+ install_conf="$KERNEL_INSTALL_CONF_ROOT/install.conf"
+elif [ -f "/etc/kernel/install.conf" ]; then
install_conf="/etc/kernel/install.conf"
elif [ -f "/usr/lib/kernel/install.conf" ]; then
install_conf="/usr/lib/kernel/install.conf"
@@ -116,7 +118,7 @@ else
install_conf=
fi
-if [ -n "$install_conf" ]; then
+if [ -f "$install_conf" ]; then
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Reading $install_conf…"
# shellcheck source=/dev/null
. "$install_conf"
@@ -171,10 +173,12 @@ fi
# $BOOT where we want to place the kernel/initrd and related resources, as well
# for naming the .conf boot loader spec entry. Typically this is just the
# machine ID, but it can be anything else, too, if we are told so.
-if [ -z "$ENTRY_TOKEN" ] && [ -f /etc/kernel/entry-token ]; then
- read -r ENTRY_TOKEN </etc/kernel/entry-token
+ENTRY_TOKEN_FILE="${KERNEL_INSTALL_CONF_ROOT:-/etc/kernel}/entry-token"
+
+if [ -z "$ENTRY_TOKEN" ] && [ -f "$ENTRY_TOKEN_FILE" ]; then
+ read -r ENTRY_TOKEN <"$ENTRY_TOKEN_FILE"
[ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
- echo "entry-token \"$ENTRY_TOKEN\" acquired from /etc/kernel/entry-token"
+ echo "entry-token \"$ENTRY_TOKEN\" acquired from $ENTRY_TOKEN_FILE"
fi
if [ -z "$ENTRY_TOKEN" ]; then
# If not configured explicitly, then use a few candidates: the machine ID,