diff --git a/man/kernel-install.xml b/man/kernel-install.xml index c6414b13dd..83255bb932 100644 --- a/man/kernel-install.xml +++ b/man/kernel-install.xml @@ -71,23 +71,21 @@ add KERNEL-VERSION $BOOT/MACHINE-ID/KERNEL-VERSION/ KERNEL-IMAGE [INITRD-FILE ...] - Three default plugins execute the following operations in this case: + Two default plugins execute the following operations in this case: - 00-entry-directory.install creates the directory - $BOOT/MACHINE-ID/KERNEL-VERSION/ - if $BOOT/MACHINE-ID/ already exists. - + kernel-install creates + $BOOT/MACHINE-ID/KERNEL-VERSION, + if enabled (see $KERNEL_INSTALL_LAYOUT=). 50-depmod.install runs depmod8 for the KERNEL-VERSION. - 90-loaderentry.install copies KERNEL-IMAGE - to + 90-loaderentry.install + copies KERNEL-IMAGE to $BOOT/MACHINE-ID/KERNEL-VERSION/linux. - If an INITRD-FILE is provided, it also copies INITRD-FILE - to + If INITRD-FILEs are provided, it also copies them to $BOOT/MACHINE-ID/KERNEL_VERSION/INITRD-FILE. It also creates a boot loader entry according to the Boot Loader Specification in @@ -96,9 +94,7 @@ /etc/os-release or /usr/lib/os-release (if the former is missing), or "Linux KERNEL-VERSION", if unset. - If the entry directory - $BOOT/MACHINE-ID/KERNEL-VERSION/ - does not exist, this plugin does nothing. + If $KERNEL_INSTALL_LAYOUT= is not "bls", this plugin does nothing. @@ -119,13 +115,15 @@ Two default plugins execute the following operations in this case: - 50-depmod.install removes the files generated by depmod for this kernel again. 90-loaderentry.install removes the file $BOOT/loader/entries/MACHINE-ID-KERNEL-VERSION.conf. - + kernel-install removes + $BOOT/MACHINE-ID/KERNEL-VERSION, + if enabled (see $KERNEL_INSTALL_LAYOUT=). + @@ -172,6 +170,30 @@ either 32 hexadecimal characters or the special value Default. KERNEL_INSTALL_BOOT_ROOT= is set for the plugins to the root directory (mount point, usually) of the hierarchy where boot-loader entries, kernel images, and associated resources should be placed. Can be overridden by setting BOOT_ROOT=. + + KERNEL_INSTALL_LAYOUT=bls|other|... specifies the installation layout. + Defaults to if $BOOT/MACHINE-ID exists, or otherwise. + Additional layout names may be defined by convention. If a plugin uses a special layout, + it's encouraged to declare its own layout name and configure layout= in install.conf upon initial installation. + + + + bls + + Standard Boot Loader Specification layout, + compatible with systemd-boot7: entries in + $BOOT/loader/entries/MACHINE-ID-KERNEL-VERSION[+TRIES].conf, + kernel and initrds under $BOOT/MACHINE-ID/KERNEL-VERSION/ + Provided by 90-loaderentry.install. + + + + other + + Some other layout not understood natively by kernel-install. + + + @@ -251,6 +273,18 @@ Otherwise, Linux KERNEL-VERSION will be used. + + + /usr/lib/kernel/install.conf + /etc/kernel/install.conf + + + Configuration options for kernel-install, + as a series of KEY=VALUE assignments, + compatible with shell syntax. + See the Environment variables section for supported keys. + + diff --git a/meson.build b/meson.build index db50f92512..0e8f58eb24 100644 --- a/meson.build +++ b/meson.build @@ -171,7 +171,8 @@ udevlibexecdir = rootprefixdir / 'lib/udev' udevrulesdir = udevlibexecdir / 'rules.d' udevhwdbdir = udevlibexecdir / 'hwdb.d' catalogdir = prefixdir / 'lib/systemd/catalog' -kernelinstalldir = prefixdir / 'lib/kernel/install.d' +kerneldir = prefixdir / 'lib/kernel' +kernelinstalldir = kerneldir / 'install.d' factorydir = datadir / 'factory' bootlibdir = prefixdir / 'lib/systemd/boot/efi' testsdir = prefixdir / 'lib/systemd/tests' diff --git a/src/kernel-install/00-entry-directory.install b/src/kernel-install/00-entry-directory.install deleted file mode 100644 index 5576179d52..0000000000 --- a/src/kernel-install/00-entry-directory.install +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash -# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- -# ex: ts=8 sw=4 sts=4 et filetype=sh -# SPDX-License-Identifier: LGPL-2.1-or-later -# -# This file is part of systemd. -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. -# -# systemd is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with systemd; If not, see . - -COMMAND="$1" -KERNEL_VERSION="$2" -ENTRY_DIR_ABS="$3" -KERNEL_IMAGE="$4" -INITRD_OPTIONS_START="5" - -if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then - exit 0 -fi - -if [[ $COMMAND != add ]]; then - exit 0 -fi - -# Create the entry directory if its parent exists ‒ -# this is an administrative decision and the only function of this plugin. -MACHINE_ID_DIR="$KERNEL_INSTALL_BOOT_ROOT/$KERNEL_INSTALL_MACHINE_ID" -if ! [ -d "$MACHINE_ID_DIR" ]; then - exit 0 -fi - -if [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ]; then - echo "+mkdir -v -p $ENTRY_DIR_ABS" - exec mkdir -v -p "$ENTRY_DIR_ABS" -else - exec mkdir -p "$ENTRY_DIR_ABS" -fi diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install index a4dba1396d..044eced3f0 100644 --- a/src/kernel-install/90-loaderentry.install +++ b/src/kernel-install/90-loaderentry.install @@ -28,7 +28,7 @@ if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then exit 0 fi -if ! [[ -d "$ENTRY_DIR_ABS" ]]; then +if [ "$KERNEL_INSTALL_LAYOUT" != "bls" ]; then exit 0 fi @@ -92,6 +92,15 @@ else LOADER_ENTRY="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf" fi +if ! [ -d "$ENTRY_DIR_ABS" ]; then + if [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ]; then + echo "+mkdir -v -p $ENTRY_DIR_ABS" + mkdir -v -p "$ENTRY_DIR_ABS" + else + mkdir -p "$ENTRY_DIR_ABS" + fi +fi + install -g root -o root -m 0644 "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" || { echo "Could not copy '$KERNEL_IMAGE' to '$ENTRY_DIR_ABS/linux'." >&2 exit 1 diff --git a/src/kernel-install/install.conf b/src/kernel-install/install.conf new file mode 100644 index 0000000000..e4802e6fae --- /dev/null +++ b/src/kernel-install/install.conf @@ -0,0 +1,10 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2.1 of the License, or (at your option) +# any later version. +# +# See kernel-install(8) for details. + +#layout=bls|other|... diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install index 103b44ebda..b358b03b2f 100755 --- a/src/kernel-install/kernel-install +++ b/src/kernel-install/kernel-install @@ -90,6 +90,12 @@ if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then exit 1 fi +if [ -r "/etc/kernel/install.conf" ]; then + . /etc/kernel/install.conf +elif [ -r "/usr/lib/kernel/install.conf" ]; then + . /usr/lib/kernel/install.conf +fi + # Prefer to use an existing machine ID from /etc/machine-info or /etc/machine-id. If we're using the machine # ID /etc/machine-id, try to persist it in /etc/machine-info. If no machine ID is found, try to generate # a new machine ID in /etc/machine-info. If that fails, use "Default". @@ -124,6 +130,26 @@ ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION" export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID" export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT" +if [ -z "$layout" ]; then + # Administrative decision: if not present, some scripts generate into /boot. + if [ -d "$BOOT_ROOT/$MACHINE_ID" ]; then + layout="bls" + else + layout="other" + fi +fi + + +ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION" + +export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID" +export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT" +export KERNEL_INSTALL_LAYOUT="$layout" + +[ "$layout" = "bls" ] +MAKE_ENTRY_DIR_ABS=$? + + ret=0 readarray -t PLUGINS <<<"$( @@ -144,6 +170,18 @@ case $COMMAND in exit 1 fi + if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then + # Compatibility with earlier versions that used the presence of $BOOT_ROOT/$MACHINE_ID + # to signal to 00-entry-directory to create $ENTRY_DIR_ABS + # to serve as the indication to use or to not use the BLS + if [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ]; then + echo "+mkdir -v -p $ENTRY_DIR_ABS" + mkdir -v -p "$ENTRY_DIR_ABS" + else + mkdir -p "$ENTRY_DIR_ABS" + fi + fi + for f in "${PLUGINS[@]}"; do if [[ -x $f ]]; then [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \ @@ -172,11 +210,10 @@ case $COMMAND in fi done - [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \ - echo "Removing $ENTRY_DIR_ABS" - - rm -rf "$ENTRY_DIR_ABS" - ((ret+=$?)) + if [ "$MAKE_ENTRY_DIR_ABS" -eq 0 ]; then + [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Removing $ENTRY_DIR_ABS/" + rm -rf "$ENTRY_DIR_ABS" + fi ;; *) diff --git a/src/kernel-install/meson.build b/src/kernel-install/meson.build index 893832461e..508058f1cf 100644 --- a/src/kernel-install/meson.build +++ b/src/kernel-install/meson.build @@ -7,12 +7,14 @@ if want_kernel_install install_mode : 'rwxr-xr-x', install_dir : bindir) - install_data('00-entry-directory.install', - '50-depmod.install', + install_data('50-depmod.install', '90-loaderentry.install', install_mode : 'rwxr-xr-x', install_dir : kernelinstalldir) + install_data('install.conf', + install_dir : kerneldir) + if install_sysconfdir meson.add_install_script('sh', '-c', mkdir_p.format(sysconfdir / 'kernel/install.d'))