Blame 1825-Skip-creating-initrd-when-initrd-is-provided.patch

ec3ccd
From f47bcdd7342ca0d46b889e712a1c7446e18434bc Mon Sep 17 00:00:00 2001
ec3ccd
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
ec3ccd
Date: Tue, 18 Jan 2022 18:08:42 +0100
ec3ccd
Subject: [PATCH 1/2] feat(kernel-install): do nothing when
ec3ccd
 $KERNEL_INSTALL_INITRD_GENERATOR says so
ec3ccd
ec3ccd
dracut may be installed without being actually used. This is very common in
ec3ccd
binary distros where a package may be pulled in through dependencies, even
ec3ccd
though the user does not need it in a particular setup. KERNEL_INSTALL_INITRD_GENERATOR
ec3ccd
is being added in systemd's kernel-install to select which of the possibly many
ec3ccd
initrd generation mechanisms will be used.
ec3ccd
ec3ccd
For backwards compat, if it not set, continue as before. But if set to
ec3ccd
something else, skip our kernel-install plugins.
ec3ccd
---
ec3ccd
 install.d/50-dracut.install        | 8 +++++++-
ec3ccd
 install.d/51-dracut-rescue.install | 5 +++++
ec3ccd
 2 files changed, 12 insertions(+), 1 deletion(-)
ec3ccd
ec3ccd
diff --git a/install.d/50-dracut.install b/install.d/50-dracut.install
ec3ccd
index 70632ec7f..552fd0338 100755
ec3ccd
--- a/install.d/50-dracut.install
ec3ccd
+++ b/install.d/50-dracut.install
ec3ccd
@@ -6,11 +6,17 @@ BOOT_DIR_ABS="$3"
ec3ccd
 KERNEL_IMAGE="$4"
ec3ccd
 
ec3ccd
 # If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory.
ec3ccd
-# So, let's skip to create initrd.
ec3ccd
+# In this case, do not create the initrd.
ec3ccd
 if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
ec3ccd
     exit 0
ec3ccd
 fi
ec3ccd
 
ec3ccd
+# Skip this plugin if we're using a different generator. If nothing is specified,
ec3ccd
+# assume we're wanted since we're installed.
ec3ccd
+if [ "${KERNEL_INSTALL_INITRD_GENERATOR:-dracut}" != "dracut" ]; then
ec3ccd
+    exit 0
ec3ccd
+fi
ec3ccd
+
ec3ccd
 if [[ -d "$BOOT_DIR_ABS" ]]; then
ec3ccd
     INITRD="initrd"
ec3ccd
 else
ec3ccd
diff --git a/install.d/51-dracut-rescue.install b/install.d/51-dracut-rescue.install
ec3ccd
index 8bf9a6d95..93483931a 100755
ec3ccd
--- a/install.d/51-dracut-rescue.install
ec3ccd
+++ b/install.d/51-dracut-rescue.install
ec3ccd
@@ -7,6 +7,11 @@ KERNEL_VERSION="$2"
ec3ccd
 BOOT_DIR_ABS="${3%/*}/0-rescue"
ec3ccd
 KERNEL_IMAGE="$4"
ec3ccd
 
ec3ccd
+# Skip this plugin if we're using a different generator. If nothing is specified,
ec3ccd
+# assume we're wanted since we're installed.
ec3ccd
+if [ "${KERNEL_INSTALL_INITRD_GENERATOR:-dracut}" != "dracut" ]; then
ec3ccd
+    exit 0
ec3ccd
+fi
ec3ccd
 
ec3ccd
 dropindirs_sort()
ec3ccd
 {
ec3ccd
ec3ccd
From 0b72cf5c4eca0e0db76e3e210cfdc48e6b49bb74 Mon Sep 17 00:00:00 2001
ec3ccd
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
ec3ccd
Date: Tue, 18 Jan 2022 18:58:58 +0100
ec3ccd
Subject: [PATCH 2/2] fix(kernel-install): do not generate an initrd when one
ec3ccd
 was specified
ec3ccd
ec3ccd
According to the synopsis, kernel-install can be called with an
ec3ccd
already-prepared initrd. In that case, no initrd should be generated by dracut.
ec3ccd
---
ec3ccd
 install.d/50-dracut.install | 4 ++++
ec3ccd
 1 file changed, 4 insertions(+)
ec3ccd
ec3ccd
diff --git a/install.d/50-dracut.install b/install.d/50-dracut.install
ec3ccd
index 552fd0338..836251e92 100755
ec3ccd
--- a/install.d/50-dracut.install
ec3ccd
+++ b/install.d/50-dracut.install
ec3ccd
@@ -4,6 +4,7 @@ COMMAND="$1"
ec3ccd
 KERNEL_VERSION="$2"
ec3ccd
 BOOT_DIR_ABS="$3"
ec3ccd
 KERNEL_IMAGE="$4"
ec3ccd
+INITRD_OPTIONS_SHIFT=4
ec3ccd
 
ec3ccd
 # If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory.
ec3ccd
 # In this case, do not create the initrd.
ec3ccd
@@ -27,6 +28,9 @@ fi
ec3ccd
 ret=0
ec3ccd
 case "$COMMAND" in
ec3ccd
     add)
ec3ccd
+        # If the initrd was provided on the kernel command line, we shouldn't generate our own.
ec3ccd
+        [ "$#" -gt "$INITRD_OPTIONS_SHIFT" ] && exit 0
ec3ccd
+
ec3ccd
         INITRD_IMAGE_PREGENERATED=${KERNEL_IMAGE%/*}/initrd
ec3ccd
         if [[ -f ${INITRD_IMAGE_PREGENERATED} ]]; then
ec3ccd
             # we found an initrd at the same place as the kernel