From 815b9c16a4e90b67bab008da678d73faa74f8e0c Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 24 Jan 2014 15:30:22 +0100 Subject: [PATCH] lsinitrd.sh: make use of the skipcpio utility With the skipcpio utility, the whole contents of an initramfs with an early cpio image can be displayed. --- lsinitrd.sh | 96 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 21 deletions(-) diff --git a/lsinitrd.sh b/lsinitrd.sh index f9f243bb..70e12f81 100755 --- a/lsinitrd.sh +++ b/lsinitrd.sh @@ -33,6 +33,9 @@ usage() } >&2 } + +[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut + sorted=0 declare -A filenames @@ -103,14 +106,72 @@ if ! [[ -f "$image" ]]; then exit 1 fi +extract_files() +{ + (( ${#filenames[@]} == 1 )) && nofileinfo=1 + for f in ${!filenames[@]}; do + [[ $nofileinfo ]] || echo "initramfs:/$f" + [[ $nofileinfo ]] || echo "========================================================================" + $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null + ((ret+=$?)) + [[ $nofileinfo ]] || echo "========================================================================" + [[ $nofileinfo ]] || echo + done +} + +list_files() +{ + echo "========================================================================" + if [ "$sorted" -eq 1 ]; then + $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5 + else + $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9 + fi + ((ret+=$?)) + echo "========================================================================" +} + + +if (( ${#filenames[@]} <= 0 )); then + echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)" + echo "========================================================================" +fi + read -N 6 bin < "$image" +case $bin in + $'\x71\xc7'*|070701) + CAT="cat --" + is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null) + if [[ "$is_early" ]]; then + if (( ${#filenames[@]} > 0 )); then + extract_files + else + echo "Early CPIO image" + list_files + fi + SKIP="$dracutbasedir/skipcpio" + if ! [[ -x $SKIP ]]; then + echo + echo "'$SKIP' not found, cannot display remaining contents!" >&2 + echo + exit 0 + fi + fi + ;; +esac + +if [[ $SKIP ]]; then + read -N 6 bin < <($SKIP "$image") +fi + case $bin in $'\x1f\x8b'*) CAT="zcat --";; BZh*) CAT="bzcat --";; $'\x71\xc7'*|070701) - CAT="cat --";; + CAT="cat --" + ;; $'\x04\x22'*) CAT="lz4 -d -c";; *) @@ -121,34 +182,27 @@ case $bin in ;; esac +skipcpio() +{ + $SKIP "$@" | $ORIG_CAT +} + +if [[ $SKIP ]]; then + ORIG_CAT="$CAT" + CAT=skipcpio +fi + ret=0 if (( ${#filenames[@]} > 0 )); then - (( ${#filenames[@]} == 1 )) && nofileinfo=1 - for f in ${!filenames[@]}; do - [[ $nofileinfo ]] || echo "initramfs:/$f" - [[ $nofileinfo ]] || echo "========================================================================" - $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null - ((ret+=$?)) - [[ $nofileinfo ]] || echo "========================================================================" - [[ $nofileinfo ]] || echo - done + extract_files else - echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)" - echo "========================================================================" - version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/dracut-*' 2>/dev/null) + version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/dracut-*' 'usr/lib/dracut/dracut-*' 2>/dev/null) ((ret+=$?)) echo "$version with dracut modules:" $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/modules.txt' 2>/dev/null ((ret+=$?)) - echo "========================================================================" - if [ "$sorted" -eq 1 ]; then - $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5 - else - $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9 - fi - ((ret+=$?)) - echo "========================================================================" + list_files fi exit $ret