]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat: warn in case 3cpio is present but not suitable
authorBenjamin Drung <benjamin.drung@canonical.com>
Fri, 23 Jan 2026 21:59:26 +0000 (22:59 +0100)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Fri, 23 Jan 2026 23:05:49 +0000 (18:05 -0500)
In case the 3cpio call fails, dracut will silently fall back to cpio.
This makes debugging harder.

So print a warning in case calling 3cpio fails. Print an info in case
3cpio does not support `--create`.

See also https://bugs.debian.org/1126301

dracut.sh
lsinitrd.sh

index 1f1de4df961cff5621934cc2e39d64a44483f9b6..99ac4543d7ea5c38972a98984a915a03e744932f 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -2076,8 +2076,19 @@ elif [[ -n $persistent_policy && ! -d "/dev/disk/${persistent_policy}" ]]; then
 fi
 
 CPIO=cpio
-if 3cpio --help 2> /dev/null | grep -q -- --create; then
-    CPIO=3cpio
+if command -v 3cpio > /dev/null; then
+    if help_output=$(3cpio --help); then
+        if echo "$help_output" | grep -q -- --create; then
+            CPIO=3cpio
+        else
+            dinfo "3cpio does not support --create. Falling back to cpio."
+        fi
+    elif command -v cpio > /dev/null; then
+        dwarning "Calling '3cpio --help' failed. Cannot check if 3cpio supports --create. Falling back to cpio."
+    else
+        dwarning "Calling '3cpio --help' failed. Cannot check if 3cpio supports --create."
+        CPIO=3cpio
+    fi
 fi
 
 if [[ $enhanced_cpio == "yes" ]]; then
index 7162e6d29dc480da3e36536f1c0439304d62fac1..32ee28dd4209a5bad7ed1f3529e55ab3af5a3edc 100755 (executable)
@@ -97,8 +97,17 @@ while (($# > 0)); do
 done
 
 CPIO=cpio
-if 3cpio --help 2> /dev/null | grep -q -- --make-directories; then
-    CPIO=3cpio
+if command -v 3cpio > /dev/null; then
+    if help_output=$(3cpio --help); then
+        if echo "$help_output" | grep -q -- --make-directories; then
+            CPIO=3cpio
+        fi
+    elif command -v cpio > /dev/null; then
+        echo "Warning: Calling '3cpio --help' failed. Cannot check if 3cpio supports --make-directories. Falling back to cpio."
+    else
+        echo "Warning: Calling '3cpio --help' failed. Cannot check if 3cpio supports --make-directories."
+        CPIO=3cpio
+    fi
 fi
 
 if ! [[ $KERNEL_VERSION ]]; then