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