2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # Copyright 2005-2010 Harald Hoyer <harald@redhat.com>
6 # Copyright 2005-2010 Red Hat, Inc. All rights reserved.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]"
26 echo "Usage: ${0##*/} [options] -k <kernel version>"
28 echo "-h, --help print a help message and exit."
29 echo "-s, --size sort the contents of the initramfs by size."
30 echo "-f, --file <filename> print the contents of <filename>."
31 echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>."
48 if (( $?
!= 0 )); then
57 -k|
--kver) KERNEL_VERSION
="$2"; shift;;
58 -f|
--file) filenames
[${2#/}]=1; shift;;
60 -h|
--help) usage
; exit 0;;
67 [[ $KERNEL_VERSION ]] || KERNEL_VERSION
="$(uname -r)"
71 if ! [[ -f "$image" ]]; then
73 echo "$image does not exist"
80 [[ -f /etc
/machine-id
]] && read MACHINE_ID
< /etc
/machine-id
82 if [[ -d /boot
/loader
/entries ||
-L /boot
/loader
/entries
]] \
83 && [[ $MACHINE_ID ]] \
84 && [[ -d /boot
/${MACHINE_ID} ||
-L /boot
/${MACHINE_ID} ]] ; then
85 image
="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
87 image
="/boot/initramfs-${KERNEL_VERSION}.img"
97 if ! [[ -f "$image" ]]; then
99 echo "No <initramfs file> specified and the default image '$image' cannot be accessed!"
106 read -N 6 bin
< "$image"
116 if echo "test"|xz|xzcat
--single-stream >/dev
/null
2>&1; then
117 CAT
="xzcat --single-stream"
124 if (( ${#filenames[@]} > 0 )); then
125 (( ${#filenames[@]} == 1 )) && nofileinfo
=1
126 for f
in ${!filenames[@]}; do
127 [[ $nofileinfo ]] ||
echo "initramfs:/$f"
128 [[ $nofileinfo ]] ||
echo "========================================================================"
129 $CAT -- $image |
cpio --extract --verbose --quiet --to-stdout $f 2>/dev
/null
131 [[ $nofileinfo ]] ||
echo "========================================================================"
132 [[ $nofileinfo ]] ||
echo
135 echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)"
136 echo "========================================================================"
137 version
=$
($CAT -- "$image" |
cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/dracut-*' 2>/dev
/null
)
139 echo "$version with dracut modules:"
140 $CAT -- "$image" |
cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/modules.txt' 2>/dev
/null
142 echo "========================================================================"
143 if [ "$sorted" -eq 1 ]; then
144 $CAT -- "$image" |
cpio --extract --verbose --quiet --list |
sort -n -k5
146 $CAT -- "$image" |
cpio --extract --verbose --quiet --list |
sort -k9
149 echo "========================================================================"