]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(squash): remove cyclic dependency
authorPhilipp Rudo <prudo@redhat.com>
Mon, 26 Aug 2024 13:23:41 +0000 (15:23 +0200)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Wed, 28 Aug 2024 11:59:47 +0000 (07:59 -0400)
With commit d0f8fde5 ("fix(dracut-init.sh): add module to mods_to_load
before checking dependencies") reverted 99squash can no longer rely on
dracut_module_included working as expected in its check() and depends()
function. Solve this problem by breaking up the cyclic dependency
between 99squash and 95squash-{squashfs,erofs} as the commit was
originally introduced to allow this cyclic dependency.

This requires to move all code shared by 95squash-{squashfs,erofs} from
99squash to a new 99squash-lib module and update the dependencies
accordingly. In addition update the checks in dracut.sh to check for
99squash-lib as 99squash is no longer guaranteed to be included.
Finally make sure that 99squash-lib isn't included without a back
end.

While at it improve and align the error messages in 99squash and
99squash-lib.

Signed-off-by: Philipp Rudo <prudo@redhat.com>
dracut.sh
modules.d/95squash-erofs/module-setup.sh
modules.d/95squash-squashfs/module-setup.sh
modules.d/99squash-lib/init-squash.sh [moved from modules.d/99squash/init-squash.sh with 100% similarity]
modules.d/99squash-lib/module-setup.sh [new file with mode: 0755]
modules.d/99squash/module-setup.sh

index c190d141b931a2bd8b225bc91eda4ab0667d9c27..96003abc3810117affbf34cf62188ff6ad0ca464 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -1938,7 +1938,7 @@ if [[ $kernel_only != yes ]]; then
     fi
 fi
 
-dracut_module_included "squash" && mkdir -p "$squashdir"
+dracut_module_included "squash-lib" && mkdir -p "$squashdir"
 
 _isize=0 #initramfs size
 modules_loaded=" "
@@ -2308,9 +2308,9 @@ if [[ $do_strip == yes ]] && ! [[ $DRACUT_FIPS_MODE ]]; then
     dinfo "*** Stripping files done ***"
 fi
 
-if dracut_module_included "squash"; then
+if dracut_module_included "squash-lib"; then
     dinfo "*** Squashing the files inside the initramfs ***"
-    DRACUT_SQUASH_POST_INST=1 module_install "squash"
+    DRACUT_SQUASH_POST_INST=1 module_install "squash-lib"
     rm -rf "$squashdir"
     dinfo "*** Squashing the files inside the initramfs done ***"
 
index 5f5b803b11b726e7aeda993c7682bf1596946cd9..45898f4128fc92c7a3979c96083432e0e9facc16 100755 (executable)
@@ -8,7 +8,7 @@ check() {
 }
 
 depends() {
-    echo "squash"
+    echo "squash-lib"
     return 0
 }
 
index 839737001dce1287e3a7cf5d67f8c1e4780c1b8a..d15586da08e373405f734877a5729cf9d8c10224 100755 (executable)
@@ -8,7 +8,7 @@ check() {
 }
 
 depends() {
-    echo "squash"
+    echo "squash-lib"
     return 0
 }
 
diff --git a/modules.d/99squash-lib/module-setup.sh b/modules.d/99squash-lib/module-setup.sh
new file mode 100755 (executable)
index 0000000..6a0b6f8
--- /dev/null
@@ -0,0 +1,101 @@
+#!/bin/bash
+
+check() {
+    require_kernel_modules loop overlay || return 1
+
+    return 255
+}
+
+depends() {
+    echo "systemd-initrd"
+
+    return 0
+}
+
+squash_get_handler() {
+    local _module _handler
+    local -a _modules=(squash-squashfs squash-erofs)
+
+    for _module in "${_modules[@]}"; do
+        if dracut_module_included "$_module"; then
+            _handler="$_module"
+            break
+        fi
+    done
+
+    if [[ -z $_handler ]]; then
+        dfatal "Cannot include squash-lib directly. It requires one of: ${_modules[*]}"
+        return 1
+    fi
+
+    echo "$_handler"
+}
+
+squash_install() {
+    local _busybox _dir
+
+    # verify that there is a valid handler before doing anything
+    squash_get_handler > /dev/null || return 1
+
+    _busybox=$(find_binary busybox)
+
+    # Create mount points for squash loader and basic directories
+    mkdir -p "$initdir"/squash
+    for _dir in squash usr/bin usr/sbin usr/lib; do
+        mkdir -p "$squashdir/$_dir"
+        [[ $_dir == usr/* ]] && ln_r "/$_dir" "${_dir#usr}"
+    done
+
+    # Install required modules and binaries for the squash image init script.
+    if [[ $_busybox ]]; then
+        module_install "busybox"
+    else
+        DRACUT_RESOLVE_DEPS=1 inst_multiple sh mount modprobe mkdir switch_root grep umount
+
+        # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
+        inst_libdir_file -o "libgcc_s.so*"
+
+        # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
+        [[ $DRACUT_FIPS_MODE ]] && inst_libdir_file -o "libssl.so*"
+    fi
+
+    hostonly="" instmods "loop" "overlay"
+    dracut_kernel_post
+
+    # Install squash image init script.
+    inst_simple "$moddir"/init-squash.sh /init
+
+    # make sure that library links are correct and up to date for squash loader
+    build_ld_cache
+}
+
+squash_installpost() {
+    local _file _handler
+
+    _handler=$(squash_get_handler)
+    [[ -n $_handler ]] || return 1
+
+    DRACUT_SQUASH_POST_INST=1 module_install "$_handler"
+
+    # Rescue the dracut spec files so dracut rebuild and lsinitrd can work
+    for _file in "$initdir"/usr/lib/dracut/*; do
+        [[ -f $_file ]] || continue
+        DRACUT_RESOLVE_DEPS=1 dstdir=$squashdir inst "$_file" "${_file#"$initdir"}"
+    done
+
+    # Remove everything that got squashed into the image
+    for _file in "$initdir"/*; do
+        [[ $_file == "$squashdir" ]] && continue
+        rm -rf "$_file"
+    done
+    mv "$squashdir"/* "$initdir"
+}
+
+install() {
+
+    if [[ $DRACUT_SQUASH_POST_INST ]]; then
+        squash_installpost
+    else
+        dstdir="$squashdir" squash_install
+    fi
+}
index 56f70774ae13adb2ab17abc1f86c52e1ea18463e..c48ba2c5a460b581ea5f34c34c573ed79e6006f0 100755 (executable)
 #!/bin/bash
 
 check() {
-    require_kernel_modules loop overlay || return 1
-
     return 255
 }
 
 depends() {
-    local _handler
-
-    _handler=$(squash_get_handler) || return 1
-
-    echo "systemd-initrd $_handler"
-    return 0
-}
-
-squash_get_handler() {
     local _module _handler
+    local -a _modules=(squash-squashfs squash-erofs)
 
-    for _module in squash-squashfs squash-erofs; do
+    for _module in "${_modules[@]}"; do
         if dracut_module_included "$_module"; then
             _handler="$_module"
             break
         fi
     done
 
-    if [ -z "$_handler" ]; then
+    if [[ -z $_handler ]]; then
         if check_module "squash-squashfs"; then
             _handler="squash-squashfs"
         elif check_module "squash-erofs"; then
             _handler="squash-erofs"
         else
-            dfatal "No valid handler for found"
+            dfatal "Cannot find valid handler for squash. It requires one of: ${_modules[*]}"
             return 1
         fi
     fi
 
     echo "$_handler"
 }
-
-squash_install() {
-    local _busybox _dir
-    _busybox=$(find_binary busybox)
-
-    # Create mount points for squash loader and basic directories
-    mkdir -p "$initdir"/squash
-    for _dir in squash usr/bin usr/sbin usr/lib; do
-        mkdir -p "$squashdir/$_dir"
-        [[ $_dir == usr/* ]] && ln_r "/$_dir" "${_dir#usr}"
-    done
-
-    # Install required modules and binaries for the squash image init script.
-    if [[ $_busybox ]]; then
-        module_install "busybox"
-    else
-        DRACUT_RESOLVE_DEPS=1 inst_multiple sh mount modprobe mkdir switch_root grep umount
-
-        # libpthread workaround: pthread_cancel wants to dlopen libgcc_s.so
-        inst_libdir_file -o "libgcc_s.so*"
-
-        # FIPS workaround for Fedora/RHEL: libcrypto needs libssl when FIPS is enabled
-        [[ $DRACUT_FIPS_MODE ]] && inst_libdir_file -o "libssl.so*"
-    fi
-
-    hostonly="" instmods "loop" "overlay"
-    dracut_kernel_post
-
-    # Install squash image init script.
-    inst_simple "$moddir"/init-squash.sh /init
-
-    # make sure that library links are correct and up to date for squash loader
-    build_ld_cache
-}
-
-squash_installpost() {
-    local _file
-
-    DRACUT_SQUASH_POST_INST=1 module_install "$(squash_get_handler)"
-
-    # Rescue the dracut spec files so dracut rebuild and lsinitrd can work
-    for _file in "$initdir"/usr/lib/dracut/*; do
-        [[ -f $_file ]] || continue
-        DRACUT_RESOLVE_DEPS=1 dstdir=$squashdir inst "$_file" "${_file#"$initdir"}"
-    done
-
-    # Remove everything that got squashed into the image
-    for _file in "$initdir"/*; do
-        [[ $_file == "$squashdir" ]] && continue
-        rm -rf "$_file"
-    done
-    mv "$squashdir"/* "$initdir"
-}
-
-install() {
-
-    if [[ $DRACUT_SQUASH_POST_INST ]]; then
-        squash_installpost
-    else
-        dstdir="$squashdir" squash_install
-    fi
-}