]>
Commit | Line | Data |
---|---|---|
3b403b32 | 1 | #!/bin/bash |
cc02093d HH |
2 | # |
3 | # Copyright 2005-2010 Harald Hoyer <harald@redhat.com> | |
4 | # Copyright 2005-2010 Red Hat, Inc. All rights reserved. | |
5 | # | |
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. | |
10 | # | |
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. | |
15 | # | |
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/>. | |
18 | # | |
074d12c1 | 19 | |
f7bccf37 HH |
20 | usage() |
21 | { | |
dde2db3d | 22 | { |
7d9bb76a HH |
23 | echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]" |
24 | echo "Usage: ${0##*/} [options] -k <kernel version>" | |
dde2db3d | 25 | echo |
7d9bb76a HH |
26 | echo "-h, --help print a help message and exit." |
27 | echo "-s, --size sort the contents of the initramfs by size." | |
05d2a145 | 28 | echo "-m, --mod list modules." |
7d9bb76a HH |
29 | echo "-f, --file <filename> print the contents of <filename>." |
30 | echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>." | |
dde2db3d HH |
31 | echo |
32 | } >&2 | |
f7bccf37 HH |
33 | } |
34 | ||
b208aad5 HH |
35 | |
36 | [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut | |
37 | ||
3ea5d2e2 | 38 | sorted=0 |
05d2a145 | 39 | modules=0 |
7d9bb76a HH |
40 | declare -A filenames |
41 | ||
42 | unset POSIXLY_CORRECT | |
43 | TEMP=$(getopt \ | |
05d2a145 | 44 | -o "shmf:k:" \ |
7d9bb76a HH |
45 | --long kver: \ |
46 | --long file: \ | |
05d2a145 | 47 | --long mod \ |
7d9bb76a HH |
48 | --long help \ |
49 | --long size \ | |
50 | -- "$@") | |
51 | ||
52 | if (( $? != 0 )); then | |
53 | usage | |
54 | exit 1 | |
55 | fi | |
56 | ||
57 | eval set -- "$TEMP" | |
58 | ||
59 | while (($# > 0)); do | |
60 | case $1 in | |
61 | -k|--kver) KERNEL_VERSION="$2"; shift;; | |
62 | -f|--file) filenames[${2#/}]=1; shift;; | |
63 | -s|--size) sorted=1;; | |
64 | -h|--help) usage; exit 0;; | |
05d2a145 | 65 | -m|--mod) modules=1;; |
7d9bb76a HH |
66 | --) shift;break;; |
67 | *) usage; exit 1;; | |
3ea5d2e2 | 68 | esac |
7d9bb76a | 69 | shift |
3ea5d2e2 | 70 | done |
3ea5d2e2 | 71 | |
7d9bb76a | 72 | [[ $KERNEL_VERSION ]] || KERNEL_VERSION="$(uname -r)" |
dde2db3d | 73 | |
7d9bb76a | 74 | if [[ $1 ]]; then |
dde2db3d HH |
75 | image="$1" |
76 | if ! [[ -f "$image" ]]; then | |
77 | { | |
78 | echo "$image does not exist" | |
79 | echo | |
80 | } >&2 | |
81 | usage | |
82 | exit 1 | |
83 | fi | |
dde2db3d | 84 | else |
727e68d0 HH |
85 | [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id |
86 | ||
7d9bb76a HH |
87 | if [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \ |
88 | && [[ $MACHINE_ID ]] \ | |
89 | && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then | |
727e68d0 HH |
90 | image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd" |
91 | else | |
d928724c | 92 | image="/boot/initramfs-${KERNEL_VERSION}.img" |
727e68d0 | 93 | fi |
dde2db3d HH |
94 | fi |
95 | ||
7d9bb76a HH |
96 | shift |
97 | while (($# > 0)); do | |
98 | filenames[${1#/}]=1; | |
99 | shift | |
100 | done | |
727e68d0 | 101 | |
dde2db3d HH |
102 | if ! [[ -f "$image" ]]; then |
103 | { | |
104 | echo "No <initramfs file> specified and the default image '$image' cannot be accessed!" | |
105 | echo | |
106 | } >&2 | |
107 | usage | |
108 | exit 1 | |
109 | fi | |
074d12c1 | 110 | |
b208aad5 HH |
111 | extract_files() |
112 | { | |
113 | (( ${#filenames[@]} == 1 )) && nofileinfo=1 | |
114 | for f in ${!filenames[@]}; do | |
115 | [[ $nofileinfo ]] || echo "initramfs:/$f" | |
116 | [[ $nofileinfo ]] || echo "========================================================================" | |
117 | $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null | |
118 | ((ret+=$?)) | |
119 | [[ $nofileinfo ]] || echo "========================================================================" | |
120 | [[ $nofileinfo ]] || echo | |
121 | done | |
122 | } | |
123 | ||
05d2a145 HB |
124 | list_modules() |
125 | { | |
126 | echo "dracut modules:" | |
127 | $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/modules.txt' 'usr/lib/dracut/modules.txt' 2>/dev/null | |
128 | ((ret+=$?)) | |
129 | } | |
130 | ||
b208aad5 HH |
131 | list_files() |
132 | { | |
133 | echo "========================================================================" | |
134 | if [ "$sorted" -eq 1 ]; then | |
135 | $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5 | |
136 | else | |
137 | $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9 | |
138 | fi | |
139 | ((ret+=$?)) | |
140 | echo "========================================================================" | |
141 | } | |
142 | ||
143 | ||
144 | if (( ${#filenames[@]} <= 0 )); then | |
145 | echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)" | |
146 | echo "========================================================================" | |
147 | fi | |
148 | ||
884e1cda | 149 | read -N 6 bin < "$image" |
b208aad5 HH |
150 | case $bin in |
151 | $'\x71\xc7'*|070701) | |
152 | CAT="cat --" | |
153 | is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null) | |
154 | if [[ "$is_early" ]]; then | |
155 | if (( ${#filenames[@]} > 0 )); then | |
156 | extract_files | |
157 | else | |
158 | echo "Early CPIO image" | |
159 | list_files | |
160 | fi | |
161 | SKIP="$dracutbasedir/skipcpio" | |
162 | if ! [[ -x $SKIP ]]; then | |
163 | echo | |
164 | echo "'$SKIP' not found, cannot display remaining contents!" >&2 | |
165 | echo | |
166 | exit 0 | |
167 | fi | |
168 | fi | |
169 | ;; | |
170 | esac | |
171 | ||
fd9f9024 HH |
172 | CAT=$({ |
173 | if [[ $SKIP ]]; then | |
174 | $SKIP "$image" | |
175 | else | |
176 | cat "$image" | |
177 | fi } | { | |
178 | read -N 6 bin | |
179 | case $bin in | |
180 | $'\x1f\x8b'*) | |
181 | echo "zcat --" | |
182 | ;; | |
183 | BZh*) | |
184 | echo "bzcat --" | |
185 | ;; | |
186 | $'\x71\xc7'*|070701) | |
187 | echo "cat --" | |
188 | ;; | |
189 | $'\x02\x21'*) | |
190 | echo "lz4 -d -c" | |
191 | ;; | |
773d6a7d TG |
192 | $'\x89'LZO$'\0'*) |
193 | echo "lzop -d -c" | |
194 | ;; | |
fd9f9024 HH |
195 | *) |
196 | if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then | |
197 | echo "xzcat --single-stream --" | |
198 | else | |
199 | echo "xzcat --" | |
200 | fi | |
201 | ;; | |
202 | esac | |
203 | }) | |
66fe35eb | 204 | |
b208aad5 HH |
205 | skipcpio() |
206 | { | |
207 | $SKIP "$@" | $ORIG_CAT | |
208 | } | |
209 | ||
210 | if [[ $SKIP ]]; then | |
211 | ORIG_CAT="$CAT" | |
212 | CAT=skipcpio | |
213 | fi | |
214 | ||
884e1cda HH |
215 | ret=0 |
216 | ||
4460416a | 217 | if (( ${#filenames[@]} > 0 )); then |
b208aad5 | 218 | extract_files |
3ea5d2e2 | 219 | else |
b208aad5 | 220 | version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/dracut-*' 'usr/lib/dracut/dracut-*' 2>/dev/null) |
4460416a | 221 | ((ret+=$?)) |
ae01bd18 | 222 | echo "Version: $version" |
b208aad5 | 223 | echo |
05d2a145 HB |
224 | if [ "$modules" -eq 1 ]; then |
225 | list_modules | |
226 | echo "========================================================================" | |
227 | else | |
228 | echo -n "Arguments: " | |
229 | $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/build-parameter.txt' 'usr/lib/dracut/build-parameter.txt' 2>/dev/null | |
230 | echo | |
231 | list_modules | |
232 | list_files | |
233 | fi | |
3ea5d2e2 | 234 | fi |
4460416a | 235 | |
884e1cda | 236 | exit $ret |