]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install: add "$KERNEL_INSTALL_STAGING_AREA" directory
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Jan 2022 11:20:22 +0000 (12:20 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 28 Jan 2022 15:17:47 +0000 (16:17 +0100)
The general approach of kernel-install was that each plugin would drop in some
files into the entry directory. But this doesn't scale well, because if we have
multiple initrd generators, or multiple initrds, each generator would need to
recreate the logic to put the generated files in the right place.

Also, effective cleanup is impossible if anything goes wrong on the way, so we
could end up with unused files in $BOOT.

So let's invert the process: plugins drop files into $KERNEL_INSTALL_STAGING_AREA,
and at the end 90-loaderentry.install DTRT with those files.

This allow new plugins like 50-mkosi-initrd.install to be significantly simpler.

man/kernel-install.xml
src/kernel-install/90-loaderentry.install
src/kernel-install/kernel-install

index bb76074d2edbeed2b14dff6afeecf62bf3ae7206..685617863ecfe89bd82f7af3f99741e7cf593821 100644 (file)
     This should be configured as <varname>initrd_generator=</varname> in <filename>install.conf</filename>.
     </para>
 
+    <para><varname>KERNEL_INSTALL_STAGING_AREA=...</varname> is set for plugins to a path to a directory.
+    Plugins may drop files in that directory, and they will be installed as part of the loader entry, based
+    on the file name and extension.</para>
+
     <variablelist>
       <varlistentry>
         <term>bls</term>
index 6a396910cbeb7140f9a4713b96c6a7f569bd6ebf..0888c260e260c6d22dfcd85623db6a11acdd0e7b 100644 (file)
@@ -18,6 +18,8 @@
 # You should have received a copy of the GNU Lesser General Public License
 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
+shopt -s nullglob
+
 COMMAND="$1"
 KERNEL_VERSION="$2"
 ENTRY_DIR_ABS="$3"
@@ -88,7 +90,8 @@ install -g root -o root -m 0644 "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" || {
 }
 
 shift "$INITRD_OPTIONS_SHIFT"
-for initrd; do
+# All files listed as arguments, and staged files called "initrd*" are installed as initrds.
+for initrd in "$@" "${KERNEL_INSTALL_STAGING_AREA}"/initrd*; do
     [ -f "$initrd" ] || {
         echo "Error: initrd '$initrd' not a file." >&2
         exit 1
@@ -114,11 +117,15 @@ mkdir -p "${LOADER_ENTRY%/*}" || {
     echo "machine-id $MACHINE_ID"
     echo "options    $BOOT_OPTIONS"
     echo "linux      $ENTRY_DIR/linux"
-    for initrd; do
+
+    have_initrd=
+    for initrd in "${@}" "${KERNEL_INSTALL_STAGING_AREA}"/initrd*; do
         echo "initrd     $ENTRY_DIR/${initrd##*/}"
+        have_initrd=yes
     done
+
     # Try "initrd", generated by dracut in its kernel-install hook, if no initrds were supplied
-    [ $# -eq 0 ] && [ -f "$ENTRY_DIR_ABS/initrd" ] && echo "initrd     $ENTRY_DIR/initrd"
+    [ -z "$have_initrd" ] && [ -f "$ENTRY_DIR_ABS/initrd" ] && echo "initrd     $ENTRY_DIR/initrd"
     :
 } >"$LOADER_ENTRY" || {
     echo "Error: could not create loader entry '$LOADER_ENTRY'." >&2
index a73a205d79783964b9aa243ebbc760e73bbe20c4..8cfef3208d69df865076157862125e43b8ccf214 100755 (executable)
@@ -128,10 +128,20 @@ fi
 
 ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
 
+# Provide a directory where to store generated initrds
+cleanup() {
+    [ -n "$KERNEL_INSTALL_STAGING_AREA" ] && rm -rf "$KERNEL_INSTALL_STAGING_AREA"
+}
+
+trap cleanup EXIT
+
+KERNEL_INSTALL_STAGING_AREA="$(mktemp -d -t -p /tmp kernel-install.staging.XXXXXXX)"
+
 export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
 export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
 export KERNEL_INSTALL_LAYOUT="$layout"
 export KERNEL_INSTALL_INITRD_GENERATOR="$initrd_generator"
+export KERNEL_INSTALL_STAGING_AREA
 
 [ "$layout" = "bls" ]
 MAKE_ENTRY_DIR_ABS=$?