From 338864d4218ea0c7dd72ee51f2b49b6df29de902 Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Tue, 6 Aug 2024 14:58:58 +0200 Subject: [PATCH] fix(dracut): ldd output borked with `--sysroot` (bsc#1228659) dracut-install calls ldd to resolve dependencies, but when the `--sysroot` option is used, ldd is not performing the search within the sysroot directory. To fix this issue, the `LD_LIBRARY_PATH` variable needs to be properly set to the directories containing shared libraries within the specified sysroot directory. E.g., running dracut with `--sysroot` produces an initrd without the required systemd shared libraries when the version between the host system and the sysroot directory differs: ``` localhost:~ # ldd /.snapshots/9/snapshot/usr/lib/systemd/systemd | grep libsystemd libsystemd-core-256.so => not found libsystemd-shared-256.so => not found localhost:~ # export LD_LIBRARY_PATH=/.snapshots/9/snapshot/usr/lib64/systemd localhost:~ # ldd /.snapshots/9/snapshot/usr/lib/systemd/systemd | grep libsystemd libsystemd-core-256.so => /.snapshots/9/snapshot/usr/lib64/systemd/libsystemd-core-256.so (0x00007f817b600000) libsystemd-shared-256.so => /.snapshots/9/snapshot/usr/lib64/systemd/libsystemd-shared-256.so (0x00007f817b000000) ``` --- dracut-init.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dracut-init.sh b/dracut-init.sh index e42a307d29..2ddba16605 100755 --- a/dracut-init.sh +++ b/dracut-init.sh @@ -104,6 +104,17 @@ if ! [[ $libdirs ]]; then export libdirs fi +# ldd needs LD_LIBRARY_PATH pointing to the libraries within the sysroot directory +if [[ -n $dracutsysrootdir ]]; then + for lib in $libdirs; do + mapfile -t -d '' lib_subdirs < <(find "$lib" -type d -print0 2> /dev/null) + for lib_subdir in "${lib_subdirs[@]}"; do + LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+"$LD_LIBRARY_PATH":}$dracutsysrootdir$lib_subdir" + done + done + export LD_LIBRARY_PATH +fi + # helper function for check() in module-setup.sh # to check for required installed binaries # issues a standardized warning message