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!"
124 TMPDIR
="$(mktemp -d -t lsinitrd.XXXXXX)"
125 trap "rm -rf '$TMPDIR'" EXIT
128 for d
in lib64
/dracut lib
/dracut usr
/lib64
/dracut usr
/lib
/dracut
; do
135 (( ${#filenames[@]} == 1 )) && nofileinfo
=1
136 for f
in "${!filenames[@]}"; do
137 [[ $nofileinfo ]] ||
echo "initramfs:/$f"
138 [[ $nofileinfo ]] ||
echo "========================================================================"
139 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --to-stdout "$f" 2>/dev
/null
141 [[ $nofileinfo ]] ||
echo "========================================================================"
142 [[ $nofileinfo ]] ||
echo
148 echo "dracut modules:"
149 $CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
150 $
(dracutlibdirs modules.txt
) 2>/dev
/null
156 echo "========================================================================"
157 if [ "$sorted" -eq 1 ]; then
158 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --list |
sort -n -k5
160 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --list |
sort -k9
163 echo "========================================================================"
166 list_squash_content
()
168 SQUASH_IMG
="squash/root.img"
169 SQUASH_TMPFILE
="$TMPDIR/initrd.root.sqsh"
171 $CAT "$image" 2>/dev
/null |
cpio --extract --verbose --quiet --to-stdout -- \
172 $SQUASH_IMG > "$SQUASH_TMPFILE" 2>/dev
/null
173 if [[ -s $SQUASH_TMPFILE ]]; then
174 echo "Squashed content ($SQUASH_IMG):"
175 echo "========================================================================"
176 unsquashfs
-ll "$SQUASH_TMPFILE" |
tail -n +4
177 echo "========================================================================"
183 if (( ${#filenames[@]} > 0 )); then
184 for f
in "${!filenames[@]}"; do
185 $CAT "$image" 2>/dev
/null |
cpio -id --quiet $verbose $f
189 $CAT "$image" 2>/dev
/null |
cpio -id --quiet $verbose
194 read -N 2 bin
< "$image"
195 if [ "$bin" = "MZ" ]; then
196 command -v objcopy
> /dev
/null ||
{ echo "Need 'objcopy' to unpack an UEFI executable."; exit 1; }
198 --dump-section .linux
="$TMPDIR/vmlinuz" \
199 --dump-section .initrd
="$TMPDIR/initrd.img" \
200 --dump-section .cmdline
="$TMPDIR/cmdline.txt" \
201 --dump-section .osrel
="$TMPDIR/osrel.txt" \
204 image
="$TMPDIR/initrd.img"
205 [ -f "$image" ] ||
exit 1
208 if (( ${#filenames[@]} <= 0 )) && [[ -z "$unpack" ]] && [[ -z "$unpackearly" ]]; then
209 if [ -n $uefi ]; then
210 echo -n "initrd in UEFI: $uefi: "
211 du
-h $image |
while read a b ||
[ -n "$a" ]; do echo $a;done
212 if [ -f "$TMPDIR/osrel.txt" ]; then
213 name
=$
(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
214 id
=$
(sed -En '/^ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
215 build
=$
(sed -En '/^BUILD_ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
216 echo "OS Release: $name (${id}-${build})"
218 if [ -f "$TMPDIR/vmlinuz" ]; then
219 version
=$
(strings -n 20 "$TMPDIR/vmlinuz" |
sed -En '/[0-9]+\.[0-9]+\.[0-9]+/ { p; q 0 }')
220 echo "Kernel Version: $version"
222 if [ -f "$TMPDIR/cmdline.txt" ]; then
224 sed -En 's/\s+/\n/g; s/\x00/\n/; p' "$TMPDIR/cmdline.txt"
227 echo -n "Image: $image: "
228 du
-h $image |
while read a b ||
[ -n "$a" ]; do echo $a;done
231 echo "========================================================================"
234 read -N 6 bin
< "$image"
238 is_early
=$
(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev
/null
)
239 if [[ "$is_early" ]]; then
240 if [[ -n "$unpack" ]]; then
241 # should use --unpackearly for early CPIO
243 elif [[ -n "$unpackearly" ]]; then
245 elif (( ${#filenames[@]} > 0 )); then
248 echo "Early CPIO image"
251 if [[ -d "$dracutbasedir/skipcpio" ]]; then
252 SKIP
="$dracutbasedir/skipcpio/skipcpio"
254 SKIP
="$dracutbasedir/skipcpio"
256 if ! [[ -x $SKIP ]]; then
258 echo "'$SKIP' not found, cannot display remaining contents!" >&2
266 if [[ $SKIP ]] ; then
267 bin
="$($SKIP "$image" | { read -N 6 bin && echo "$bin" ; })"
269 read -N 6 bin
< "$image"
287 $
'\x28\xB5\x2F\xFD'*)
291 if echo "test"|xz|xzcat
--single-stream >/dev
/null
2>&1; then
292 CAT
="xzcat --single-stream --"
301 $SKIP "$@" |
$ORIG_CAT
309 if (( ${#filenames[@]} > 1 )); then
310 TMPFILE
="$TMPDIR/initrd.cpio"
311 $CAT "$image" 2>/dev
/null
> $TMPFILE
321 if [[ -n "$unpack" ]]; then
323 elif (( ${#filenames[@]} > 0 )); then
326 version
=$
($CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
327 $
(dracutlibdirs
'dracut-*') 2>/dev
/null
)
329 echo "Version: $version"
331 if [ "$modules" -eq 1 ]; then
333 echo "========================================================================"
335 echo -n "Arguments: "
336 $CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
337 $
(dracutlibdirs build-parameter.txt
) 2>/dev
/null