Browse Source

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.
master
Harald Hoyer 11 years ago
parent
commit
b208aad51c
  1. 101
      lsinitrd.sh

101
lsinitrd.sh

@ -33,6 +33,9 @@ usage()
} >&2 } >&2
} }



[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut

sorted=0 sorted=0
declare -A filenames declare -A filenames


@ -103,14 +106,72 @@ if ! [[ -f "$image" ]]; then
exit 1 exit 1
fi 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" 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 case $bin in
$'\x1f\x8b'*) $'\x1f\x8b'*)
CAT="zcat --";; CAT="zcat --";;
BZh*) BZh*)
CAT="bzcat --";; CAT="bzcat --";;
$'\x71\xc7'*|070701) $'\x71\xc7'*|070701)
CAT="cat --";; CAT="cat --"
;;
$'\x04\x22'*) $'\x04\x22'*)
CAT="lz4 -d -c";; CAT="lz4 -d -c";;
*) *)
@ -121,38 +182,32 @@ case $bin in
;; ;;
esac esac


skipcpio()
{
$SKIP "$@" | $ORIG_CAT
}

if [[ $SKIP ]]; then
ORIG_CAT="$CAT"
CAT=skipcpio
fi

ret=0 ret=0


if (( ${#filenames[@]} > 0 )); then if (( ${#filenames[@]} > 0 )); then
(( ${#filenames[@]} == 1 )) && nofileinfo=1 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
((ret+=$?))
[[ $nofileinfo ]] || echo "========================================================================"
[[ $nofileinfo ]] || echo
done
else else
echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)" version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/dracut-*' 'usr/lib/dracut/dracut-*' 2>/dev/null)
echo "========================================================================"
version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/dracut-*' 2>/dev/null)
((ret+=$?)) ((ret+=$?))
echo "Version: $version" echo "Version: $version"
echo
echo -n "Arguments: " echo -n "Arguments: "
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/build-parameter.txt' 2>/dev/null $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/build-parameter.txt' 'usr/lib/dracut/build-parameter.txt' 2>/dev/null
echo echo
echo "dracut modules:" echo "dracut modules:"
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/modules.txt' 2>/dev/null $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/modules.txt' 'usr/lib/dracut/modules.txt' 2>/dev/null
((ret+=$?)) ((ret+=$?))
echo "========================================================================" list_files
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 "========================================================================"
fi fi


exit $ret exit $ret

Loading…
Cancel
Save