]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install: create the entry directory only if $BOOT/$MACHINE_ID exists
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Mar 2019 20:18:56 +0000 (21:18 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 12 Mar 2019 08:45:16 +0000 (09:45 +0100)
Things are currently fairly ugly in Fedora: we create $BOOT/$MACHINE_ID/$KERNEL_VERSION/,
and then 20-grub.install that is installed by grub2-common.rpm wants to remove that
directory before 50-dracut.install get a chance to run. 50-dracut.install
checks for the presence of that directory to decide where to install the
kernel. So let's make the creation of the directory conditional. Previous
commit changes bootctl install to create $BOOT/$MACHINE_ID, and this commit
makes kernel-install not create it. In effect, the entry directory will only be
created if 'bootctl install' or something else created the parent directory.

https://bugzilla.redhat.com/show_bug.cgi?id=1648907

man/kernel-install.xml
src/kernel-install/00-entry-directory.install [new file with mode: 0644]
src/kernel-install/kernel-install
src/kernel-install/meson.build

index db0a0b8256f135098d14ac9c60acfd908c9ceb2a..73b582c8487da9ae475fa90bbe41a5aecebe5334 100644 (file)
         <term><command>add <replaceable>KERNEL-VERSION</replaceable> <replaceable>KERNEL-IMAGE</replaceable> [<replaceable>INITRD-FILE</replaceable> ...]</command></term>
         <listitem>
           <para>This command expects a kernel version string and a path to a kernel image file as
-          arguments. <command>kernel-install</command> creates the directory
-          <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/</filename>
-          and calls the executables from <filename>/usr/lib/kernel/install.d/*.install</filename> and
+          arguments. <command>kernel-install</command> calls the executables from
+          <filename>/usr/lib/kernel/install.d/*.install</filename> and
           <filename>/etc/kernel/install.d/*.install</filename> with the following arguments:
 
           <programlisting>add <replaceable>KERNEL-VERSION</replaceable> <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/</filename> <replaceable>KERNEL-IMAGE</replaceable> [<replaceable>INITRD-FILE</replaceable> ...]</programlisting>
           </para>
 
-          <para>Two default plugins execute the following operations in this case:</para>
+          <para>Three default plugins execute the following operations in this case:</para>
 
           <itemizedlist>
+            <listitem><para><filename>00-entry-directory.install</filename> creates the directory
+            <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/</filename>
+            if <filename>/boot/<replaceable>MACHINE-ID</replaceable>/</filename> already exists.
+            </para></listitem>
 
             <listitem><para><filename>50-depmod.install</filename> runs
             <citerefentry><refentrytitle>depmod</refentrytitle><manvolnum>8</manvolnum></citerefentry> for the
             <filename>/boot/loader/entries/<replaceable>MACHINE-ID</replaceable>-<replaceable>KERNEL-VERSION</replaceable>.conf</filename>.
             The title of the entry is the <replaceable>PRETTY_NAME</replaceable> parameter specified in
             <filename>/etc/os-release</filename> or <filename>/usr/lib/os-release</filename> (if the former is
-            missing), or "Linux <replaceable>KERNEL-VERSION</replaceable>", if unset.</para></listitem>
+            missing), or "Linux <replaceable>KERNEL-VERSION</replaceable>", if unset.</para>
+
+            <para>If the entry directory
+            <filename>/boot/<replaceable>MACHINE-ID</replaceable>/<replaceable>KERNEL-VERSION</replaceable>/</filename>
+            does not exist, this plugin does nothing.</para></listitem>
           </itemizedlist>
         </listitem>
       </varlistentry>
diff --git a/src/kernel-install/00-entry-directory.install b/src/kernel-install/00-entry-directory.install
new file mode 100644 (file)
index 0000000..2aa8c58
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+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
+
+# If the boot dir exists (e.g. $ESP/<machine-id>),
+# create the entry directory ($ESP/<machine-id>/<kernel-version>).
+# This is the only function of this plugin.
+MACHINE_ID_DIR="${ENTRY_DIR_ABS%/*}"
+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
index fcf36f181ff339171e068ae2b6d30a3bf75525d4..610959ba9fc16575b2c06723c70a594ce0eaf5d7 100644 (file)
@@ -125,11 +125,6 @@ case $COMMAND in
             exit 1
         fi
 
-        mkdir -p "$ENTRY_DIR_ABS" || {
-            echo "Could not create boot directory '$ENTRY_DIR_ABS'." >&2
-            exit 1
-        }
-
         for f in "${PLUGINS[@]}"; do
             if [[ -x $f ]]; then
                 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
index c6e6f816d962b196b3a9a561e2362e7cf27a6ef8..261c3aaae450199a3d238af96b4bae9f2c1473ca 100644 (file)
@@ -4,7 +4,8 @@ install_data('kernel-install',
              install_mode : 'rwxr-xr-x',
              install_dir : bindir)
 
-install_data('50-depmod.install',
+install_data('00-entry-directory.install',
+             '50-depmod.install',
              '90-loaderentry.install',
              install_mode : 'rwxr-xr-x',
              install_dir : kernelinstalldir)