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