usable_root(): only check for ld-*.so
[dracut.git] / lsinitrd.sh
blob76d9f3e4390c5ee6afebadcd0ff01e74bd4695f3
1 #!/bin/bash
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/>.
22 usage()
25 echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]"
26 echo "Usage: ${0##*/} [options] -k <kernel version>"
27 echo
28 echo "-h, --help print a help message and exit."
29 echo "-s, --size sort the contents of the initramfs by size."
30 echo "-m, --mod list modules."
31 echo "-f, --file <filename> print the contents of <filename>."
32 echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>."
33 echo
34 } >&2
38 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
40 sorted=0
41 modules=0
42 declare -A filenames
44 unset POSIXLY_CORRECT
45 TEMP=$(getopt \
46 -o "shmf:k:" \
47 --long kver: \
48 --long file: \
49 --long mod \
50 --long help \
51 --long size \
52 -- "$@")
54 if (( $? != 0 )); then
55 usage
56 exit 1
59 eval set -- "$TEMP"
61 while (($# > 0)); do
62 case $1 in
63 -k|--kver) KERNEL_VERSION="$2"; shift;;
64 -f|--file) filenames[${2#/}]=1; shift;;
65 -s|--size) sorted=1;;
66 -h|--help) usage; exit 0;;
67 -m|--mod) modules=1;;
68 --) shift;break;;
69 *) usage; exit 1;;
70 esac
71 shift
72 done
74 [[ $KERNEL_VERSION ]] || KERNEL_VERSION="$(uname -r)"
76 if [[ $1 ]]; then
77 image="$1"
78 if ! [[ -f "$image" ]]; then
80 echo "$image does not exist"
81 echo
82 } >&2
83 usage
84 exit 1
86 else
87 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
89 if [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \
90 && [[ $MACHINE_ID ]] \
91 && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
92 image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
93 else
94 image="/boot/initramfs-${KERNEL_VERSION}.img"
98 shift
99 while (($# > 0)); do
100 filenames[${1#/}]=1;
101 shift
102 done
104 if ! [[ -f "$image" ]]; then
106 echo "No <initramfs file> specified and the default image '$image' cannot be accessed!"
107 echo
108 } >&2
109 usage
110 exit 1
113 extract_files()
115 (( ${#filenames[@]} == 1 )) && nofileinfo=1
116 for f in ${!filenames[@]}; do
117 [[ $nofileinfo ]] || echo "initramfs:/$f"
118 [[ $nofileinfo ]] || echo "========================================================================"
119 $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null
120 ((ret+=$?))
121 [[ $nofileinfo ]] || echo "========================================================================"
122 [[ $nofileinfo ]] || echo
123 done
126 list_modules()
128 echo "dracut modules:"
129 $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/modules.txt' 'usr/lib/dracut/modules.txt' 2>/dev/null
130 ((ret+=$?))
133 list_files()
135 echo "========================================================================"
136 if [ "$sorted" -eq 1 ]; then
137 $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
138 else
139 $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9
141 ((ret+=$?))
142 echo "========================================================================"
146 if (( ${#filenames[@]} <= 0 )); then
147 echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)"
148 echo "========================================================================"
151 read -N 6 bin < "$image"
152 case $bin in
153 $'\x71\xc7'*|070701)
154 CAT="cat --"
155 is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null)
156 if [[ "$is_early" ]]; then
157 if (( ${#filenames[@]} > 0 )); then
158 extract_files
159 else
160 echo "Early CPIO image"
161 list_files
163 SKIP="$dracutbasedir/skipcpio"
164 if ! [[ -x $SKIP ]]; then
165 echo
166 echo "'$SKIP' not found, cannot display remaining contents!" >&2
167 echo
168 exit 0
172 esac
174 CAT=$({
175 if [[ $SKIP ]]; then
176 $SKIP "$image"
177 else
178 cat "$image"
179 fi } | {
180 read -N 6 bin
181 case $bin in
182 $'\x1f\x8b'*)
183 echo "zcat --"
185 BZh*)
186 echo "bzcat --"
188 $'\x71\xc7'*|070701)
189 echo "cat --"
191 $'\x02\x21'*)
192 echo "lz4 -d -c"
194 $'\x89'LZO$'\0'*)
195 echo "lzop -d -c"
198 if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then
199 echo "xzcat --single-stream --"
200 else
201 echo "xzcat --"
204 esac
207 skipcpio()
209 $SKIP "$@" | $ORIG_CAT
212 if [[ $SKIP ]]; then
213 ORIG_CAT="$CAT"
214 CAT=skipcpio
217 ret=0
219 if (( ${#filenames[@]} > 0 )); then
220 extract_files
221 else
222 version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/dracut-*' 'usr/lib/dracut/dracut-*' 2>/dev/null)
223 ((ret+=$?))
224 echo "Version: $version"
225 echo
226 if [ "$modules" -eq 1 ]; then
227 list_modules
228 echo "========================================================================"
229 else
230 echo -n "Arguments: "
231 $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/build-parameter.txt' 'usr/lib/dracut/build-parameter.txt' 2>/dev/null
232 echo
233 list_modules
234 list_files
238 exit $ret