]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(lsinitrd): support 3cpio
authorBenjamin Drung <benjamin.drung@canonical.com>
Mon, 22 Sep 2025 13:13:17 +0000 (15:13 +0200)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Sun, 28 Sep 2025 00:54:51 +0000 (20:54 -0400)
`3cpio` is written in Rust and faster than `cpio`. Use `3cpio` in
`lsinitrd` in case it is available.

lsinitrd.sh

index 7892c5f6431a7e2b34749b538699c407d7edcae1..540f451f6cc64c9e888a42c7966fc8a118e2f558 100755 (executable)
@@ -96,6 +96,11 @@ while (($# > 0)); do
     shift
 done
 
+CPIO=cpio
+if 3cpio --help 2> /dev/null | grep -q -- --make-directories; then
+    CPIO=3cpio
+fi
+
 if ! [[ $KERNEL_VERSION ]]; then
     if type -P systemd-detect-virt &> /dev/null && ! systemd-detect-virt -c &> /dev/null && ! systemd-detect-virt -r &> /dev/null; then
         KERNEL_VERSION="$(uname -r)"
@@ -189,17 +194,29 @@ SQUASH_EXTRACT="$TMPDIR/squash-extract"
 
 # Takes optional pattern arguments
 cpio_extract() {
-    $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose -- "$@"
+    if [ "$CPIO" = 3cpio ]; then
+        3cpio --extract --make-directories --parts "$parts" $verbose "$image" -- "$@"
+    else
+        $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose -- "$@"
+    fi
 }
 
 # Takes optional pattern arguments
 cpio_extract_to_stdout() {
-    $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --to-stdout -- "$@" 2> /dev/null
+    if [ "$CPIO" = 3cpio ]; then
+        3cpio --extract --parts "$parts" --to-stdout "$image" -- "$@"
+    else
+        $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --to-stdout -- "$@" 2> /dev/null
+    fi
 }
 
 # Takes optional pattern arguments
 cpio_list() {
-    $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --list -- "$@"
+    if [ "$CPIO" = 3cpio ]; then
+        3cpio --list --parts "$parts" --verbose "$image" -- "$@"
+    else
+        $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --list -- "$@"
+    fi
 }
 
 extract_squash_img() {
@@ -413,6 +430,7 @@ read -r -N 6 bin < "$image"
 case $bin in
     $'\x71\xc7'* | 070701)
         CAT="cat --"
+        parts=1
         is_early=$(cpio_extract_to_stdout early_cpio 2> /dev/null)
         # Debian mkinitramfs does not create the file 'early_cpio', so let's check if firmware files exist
         [[ "$is_early" ]] || is_early=$(cpio_list 'kernel/*/microcode/*.bin' 2> /dev/null)
@@ -486,9 +504,11 @@ skipcpio() {
     $skip "$@" | $ORIG_CAT
 }
 
+parts="1-"
 if [[ $skip ]]; then
     ORIG_CAT="$CAT"
     CAT=skipcpio
+    parts="2-"
 fi
 
 if ((${#filenames[@]} > 1)); then