46e28b
From 8ab3020205ea92cbef3ca250c924d9b500c5d9aa Mon Sep 17 00:00:00 2001
46e28b
From: Hari Bathini <hbathini@linux.ibm.com>
46e28b
Date: Tue, 12 Jul 2022 13:55:47 +0530
46e28b
Subject: [PATCH] fix(squash): build ld cache for squash loader
46e28b
46e28b
Commit dc21638c3f0a fixes kdump kernel crash, due to non-conventional
46e28b
library path in powerpc, by copying /etc/ld.so.cache under initdir.
46e28b
While that works in general, it is vulnerable to failure because of
46e28b
missing links, when the CPU is reconfigured to run in compatibility
46e28b
mode of older CPU version. Avoid this by running ldconfig for squash
46e28b
loader to create the necessary links & ld cache for it. Doing this
46e28b
also saves a few kilobyes of space as the copied ld cache is bigger
46e28b
in size than the one needed for squash loader environment.
46e28b
46e28b
Fixes: dc21638c3f0a ("fix(squash): keep ld cache under initdir")
46e28b
Cc: Pingfan Liu <piliu@redhat.com>
46e28b
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
46e28b
46e28b
Resolves: rhbz#2122274
46e28b
---
46e28b
 dracut-init.sh                     | 14 ++++++++++++++
46e28b
 dracut.sh                          | 11 +----------
46e28b
 modules.d/99squash/module-setup.sh |  8 +++-----
46e28b
 3 files changed, 18 insertions(+), 15 deletions(-)
46e28b
46e28b
diff --git a/dracut-init.sh b/dracut-init.sh
46e28b
index 900e8b83..fe1b1426 100644
46e28b
--- a/dracut-init.sh
46e28b
+++ b/dracut-init.sh
46e28b
@@ -504,6 +504,20 @@ inst_rules_wildcard() {
46e28b
     [[ $_found ]] || dinfo "Skipping udev rule: $_rule"
46e28b
 }
46e28b
 
46e28b
+# make sure that library links are correct and up to date
46e28b
+build_ld_cache() {
46e28b
+    for f in "$dracutsysrootdir"/etc/ld.so.conf "$dracutsysrootdir"/etc/ld.so.conf.d/*; do
46e28b
+        [[ -f $f ]] && inst_simple "${f#$dracutsysrootdir}"
46e28b
+    done
46e28b
+    if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc/ld.so.conf; then
46e28b
+        if [[ $EUID == 0 ]]; then
46e28b
+            derror "ldconfig exited ungracefully"
46e28b
+        else
46e28b
+            derror "ldconfig might need uid=0 (root) for chroot()"
46e28b
+        fi
46e28b
+    fi
46e28b
+}
46e28b
+
46e28b
 prepare_udev_rules() {
46e28b
     if [ -z "$UDEVVERSION" ]; then
46e28b
         UDEVVERSION=$(udevadm --version)
46e28b
diff --git a/dracut.sh b/dracut.sh
46e28b
index 210a8275..d2f07ac6 100755
46e28b
--- a/dracut.sh
46e28b
+++ b/dracut.sh
46e28b
@@ -2360,16 +2360,7 @@ fi
46e28b
 
46e28b
 if [[ $kernel_only != yes ]]; then
46e28b
     # make sure that library links are correct and up to date
46e28b
-    for f in "$dracutsysrootdir"/etc/ld.so.conf "$dracutsysrootdir"/etc/ld.so.conf.d/*; do
46e28b
-        [[ -f $f ]] && inst_simple "${f#$dracutsysrootdir}"
46e28b
-    done
46e28b
-    if ! $DRACUT_LDCONFIG -r "$initdir" -f /etc/ld.so.conf; then
46e28b
-        if [[ $EUID == 0 ]]; then
46e28b
-            derror "ldconfig exited ungracefully"
46e28b
-        else
46e28b
-            derror "ldconfig might need uid=0 (root) for chroot()"
46e28b
-        fi
46e28b
-    fi
46e28b
+    build_ld_cache
46e28b
 fi
46e28b
 
46e28b
 if dracut_module_included "squash"; then
46e28b
diff --git a/modules.d/99squash/module-setup.sh b/modules.d/99squash/module-setup.sh
46e28b
index c42eb679..f31ff556 100644
46e28b
--- a/modules.d/99squash/module-setup.sh
46e28b
+++ b/modules.d/99squash/module-setup.sh
46e28b
@@ -28,11 +28,6 @@ installpost() {
46e28b
         [[ $squash_dir == "$i"/* ]] || mv "$i" "$squash_dir"/
46e28b
     done
46e28b
 
46e28b
-    # initdir also needs ld.so.* to make ld.so work
46e28b
-    inst /etc/ld.so.cache
46e28b
-    inst /etc/ld.so.conf
46e28b
-    inst_dir /etc/ld.so.conf.d
46e28b
-
46e28b
     # Create mount points for squash loader
46e28b
     mkdir -p "$initdir"/squash/
46e28b
     mkdir -p "$squash_dir"/squash/
46e28b
@@ -67,6 +62,9 @@ installpost() {
46e28b
     ln_r /usr/bin /bin
46e28b
     ln_r /usr/sbin /sbin
46e28b
     inst_simple "$moddir"/init-squash.sh /init
46e28b
+
46e28b
+    # make sure that library links are correct and up to date for squash loader
46e28b
+    build_ld_cache
46e28b
 }
46e28b
 
46e28b
 install() {
46e28b