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