X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=lsinitrd.sh;h=0b42b9a48bc19d33c976691a2f37be2200874340;hb=42e004feb9ce333d3b1b624bea7d2389da2c87a6;hp=b19a66a036f9f8289adb7b856ce43d94cc2f3088;hpb=ad438af20753e18a9d7231aa88fce26332f90cf3;p=thirdparty%2Fdracut.git diff --git a/lsinitrd.sh b/lsinitrd.sh index b19a66a03..0b42b9a48 100755 --- a/lsinitrd.sh +++ b/lsinitrd.sh @@ -28,7 +28,10 @@ usage() echo "-m, --mod list modules." echo "-f, --file print the contents of ." echo "--unpack unpack the initramfs, instead of displaying the contents." + echo " If optional filenames are given, will only unpack specified files," + echo " else the whole image will be unpacked. Won't unpack anything from early cpio part." echo "--unpackearly unpack the early microcode part of the initramfs." + echo " Same as --unpack, but only unpack files from early cpio part." echo "-v, --verbose unpack verbosely." echo "-k, --kver inspect the initramfs of ." echo @@ -130,7 +133,7 @@ extract_files() for f in "${!filenames[@]}"; do [[ $nofileinfo ]] || echo "initramfs:/$f" [[ $nofileinfo ]] || echo "========================================================================" - $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null + $CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --to-stdout "$f" 2>/dev/null ((ret+=$?)) [[ $nofileinfo ]] || echo "========================================================================" [[ $nofileinfo ]] || echo @@ -149,18 +152,40 @@ list_files() { echo "========================================================================" if [ "$sorted" -eq 1 ]; then - $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5 + $CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --list | sort -n -k5 else - $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9 + $CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --list | sort -k9 fi ((ret+=$?)) echo "========================================================================" } +list_squash_content() +{ + SQUASH_IMG="squash/root.img" + SQUASH_TMPFILE="$(mktemp -t --suffix=.root.sqsh lsinitrd.XXXXXX)" + trap "rm -f '$SQUASH_TMPFILE'" EXIT + $CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --to-stdout -- \ + $SQUASH_IMG > "$SQUASH_TMPFILE" 2>/dev/null + if [[ -s $SQUASH_TMPFILE ]]; then + echo "Squashed content ($SQUASH_IMG):" + echo "========================================================================" + unsquashfs -ll "$SQUASH_TMPFILE" | tail -n +4 + echo "========================================================================" + fi +} + unpack_files() { - $CAT "$image" | cpio -id --quiet $verbose - ((ret+=$?)) + if (( ${#filenames[@]} > 0 )); then + for f in "${!filenames[@]}"; do + $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose $f + ((ret+=$?)) + done + else + $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose + ((ret+=$?)) + fi } @@ -175,7 +200,10 @@ case $bin in CAT="cat --" is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null) if [[ "$is_early" ]]; then - if [[ -n "$unpackearly" ]]; then + if [[ -n "$unpack" ]]; then + # should use --unpackearly for early CPIO + : + elif [[ -n "$unpackearly" ]]; then unpack_files elif (( ${#filenames[@]} > 0 )); then extract_files @@ -219,6 +247,9 @@ case $bin in $'\x89'LZO$'\0'*) CAT="lzop -d -c" ;; + $'\x28\xB5\x2F\xFD'*) + CAT="zstd -d -c" + ;; *) if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then CAT="xzcat --single-stream --" @@ -238,6 +269,17 @@ if [[ $SKIP ]]; then CAT=skipcpio fi +if (( ${#filenames[@]} > 1 )); then + TMPFILE="$(mktemp -t --suffix=.cpio lsinitrd.XXXXXX)" + $CAT "$image" 2>/dev/null > $TMPFILE + trap "rm -f '$TMPFILE'" EXIT + pre_decompress() + { + cat $TMPFILE + } + CAT=pre_decompress +fi + ret=0 if [[ -n "$unpack" ]]; then @@ -260,6 +302,7 @@ else echo list_modules list_files + list_squash_content fi fi