3 # Copyright 2005-2010 Harald Hoyer <harald@redhat.com>
4 # Copyright 2005-2010 Red Hat, Inc. All rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]"
24 echo "Usage: ${0##*/} [options] -k <kernel version>"
26 echo "-h, --help print a help message and exit."
27 echo "-s, --size sort the contents of the initramfs by size."
28 echo "-m, --mod list modules."
29 echo "-f, --file <filename> print the contents of <filename>."
30 echo "--unpack unpack the initramfs, instead of displaying the contents."
31 echo " If optional filenames are given, will only unpack specified files,"
32 echo " else the whole image will be unpacked. Won't unpack anything from early cpio part."
33 echo "--unpackearly unpack the early microcode part of the initramfs."
34 echo " Same as --unpack, but only unpack files from early cpio part."
35 echo "-v, --verbose unpack verbosely."
36 echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>."
42 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
62 if (( $?
!= 0 )); then
71 -k|
--kver) KERNEL_VERSION
="$2"; shift;;
72 -f|
--file) filenames
[${2#/}]=1; shift;;
74 -h|
--help) usage
; exit 0;;
76 -v|
--verbose) verbose
="--verbose";;
78 --unpackearly) unpackearly
=1;;
85 [[ $KERNEL_VERSION ]] || KERNEL_VERSION
="$(uname -r)"
89 if ! [[ -f "$image" ]]; then
91 echo "$image does not exist"
98 [[ -f /etc
/machine-id
]] && read MACHINE_ID
< /etc
/machine-id
100 if [[ -d /boot
/loader
/entries ||
-L /boot
/loader
/entries
]] \
101 && [[ $MACHINE_ID ]] \
102 && [[ -d /boot
/${MACHINE_ID} ||
-L /boot
/${MACHINE_ID} ]] ; then
103 image
="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
105 image
="/boot/initramfs-${KERNEL_VERSION}.img"
115 if ! [[ -f "$image" ]]; then
117 echo "No <initramfs file> specified and the default image '$image' cannot be accessed!"
125 for d
in lib64
/dracut lib
/dracut usr
/lib64
/dracut usr
/lib
/dracut
; do
132 (( ${#filenames[@]} == 1 )) && nofileinfo
=1
133 for f
in "${!filenames[@]}"; do
134 [[ $nofileinfo ]] ||
echo "initramfs:/$f"
135 [[ $nofileinfo ]] ||
echo "========================================================================"
136 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --to-stdout "$f" 2>/dev
/null
138 [[ $nofileinfo ]] ||
echo "========================================================================"
139 [[ $nofileinfo ]] ||
echo
145 echo "dracut modules:"
146 $CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
147 $
(dracutlibdirs modules.txt
) 2>/dev
/null
153 echo "========================================================================"
154 if [ "$sorted" -eq 1 ]; then
155 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --list |
sort -n -k5
157 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --list |
sort -k9
160 echo "========================================================================"
165 if (( ${#filenames[@]} > 0 )); then
166 for f
in "${!filenames[@]}"; do
167 $CAT "$image" 2>/dev
/null |
cpio -id --quiet $verbose $f
171 $CAT "$image" 2>/dev
/null |
cpio -id --quiet $verbose
177 if (( ${#filenames[@]} <= 0 )) && [[ -z "$unpack" ]] && [[ -z "$unpackearly" ]]; then
178 echo "Image: $image: $(du -h $image | while read a b || [ -n "$a" ]; do echo $a;done)"
179 echo "========================================================================"
182 read -N 6 bin
< "$image"
186 is_early
=$
(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev
/null
)
187 if [[ "$is_early" ]]; then
188 if [[ -n "$unpack" ]]; then
189 # should use --unpackearly for early CPIO
191 elif [[ -n "$unpackearly" ]]; then
193 elif (( ${#filenames[@]} > 0 )); then
196 echo "Early CPIO image"
199 if [[ -d "$dracutbasedir/skipcpio" ]]; then
200 SKIP
="$dracutbasedir/skipcpio/skipcpio"
202 SKIP
="$dracutbasedir/skipcpio"
204 if ! [[ -x $SKIP ]]; then
206 echo "'$SKIP' not found, cannot display remaining contents!" >&2
214 if [[ $SKIP ]] ; then
215 bin
="$($SKIP "$image" | { read -N 6 bin && echo "$bin" ; })"
217 read -N 6 bin
< "$image"
235 $
'\x28\xB5\x2F\xFD'*)
239 if echo "test"|xz|xzcat
--single-stream >/dev
/null
2>&1; then
240 CAT
="xzcat --single-stream --"
249 $SKIP "$@" |
$ORIG_CAT
257 if (( ${#filenames[@]} > 1 )); then
258 TMPFILE
="$(mktemp -t --suffix=.cpio lsinitrd.XXXXXX)"
259 $CAT "$image" 2>/dev
/null
> $TMPFILE
260 trap "rm -f '$TMPFILE'" EXIT
270 if [[ -n "$unpack" ]]; then
272 elif (( ${#filenames[@]} > 0 )); then
275 version
=$
($CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
276 $
(dracutlibdirs
'dracut-*') 2>/dev
/null
)
278 echo "Version: $version"
280 if [ "$modules" -eq 1 ]; then
282 echo "========================================================================"
284 echo -n "Arguments: "
285 $CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
286 $
(dracutlibdirs build-parameter.txt
) 2>/dev
/null