systemd: Optionally, include efivarsfs module
[dracut.git] / lsinitrd.sh
bloba697bc2b7570152d14e2696afd9fc63ee6d73dbd
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 "-f, --file <filename> print the contents of <filename>."
31 echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>."
32 echo
33 } >&2
37 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
39 sorted=0
40 declare -A filenames
42 unset POSIXLY_CORRECT
43 TEMP=$(getopt \
44 -o "shf:k:" \
45 --long kver: \
46 --long file: \
47 --long help \
48 --long size \
49 -- "$@")
51 if (( $? != 0 )); then
52 usage
53 exit 1
56 eval set -- "$TEMP"
58 while (($# > 0)); do
59 case $1 in
60 -k|--kver) KERNEL_VERSION="$2"; shift;;
61 -f|--file) filenames[${2#/}]=1; shift;;
62 -s|--size) sorted=1;;
63 -h|--help) usage; exit 0;;
64 --) shift;break;;
65 *) usage; exit 1;;
66 esac
67 shift
68 done
70 [[ $KERNEL_VERSION ]] || KERNEL_VERSION="$(uname -r)"
72 if [[ $1 ]]; then
73 image="$1"
74 if ! [[ -f "$image" ]]; then
76 echo "$image does not exist"
77 echo
78 } >&2
79 usage
80 exit 1
82 else
83 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
85 if [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \
86 && [[ $MACHINE_ID ]] \
87 && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
88 image="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
89 else
90 image="/boot/initramfs-${KERNEL_VERSION}.img"
94 shift
95 while (($# > 0)); do
96 filenames[${1#/}]=1;
97 shift
98 done
100 if ! [[ -f "$image" ]]; then
102 echo "No <initramfs file> specified and the default image '$image' cannot be accessed!"
103 echo
104 } >&2
105 usage
106 exit 1
109 extract_files()
111 (( ${#filenames[@]} == 1 )) && nofileinfo=1
112 for f in ${!filenames[@]}; do
113 [[ $nofileinfo ]] || echo "initramfs:/$f"
114 [[ $nofileinfo ]] || echo "========================================================================"
115 $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null
116 ((ret+=$?))
117 [[ $nofileinfo ]] || echo "========================================================================"
118 [[ $nofileinfo ]] || echo
119 done
122 list_files()
124 echo "========================================================================"
125 if [ "$sorted" -eq 1 ]; then
126 $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
127 else
128 $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9
130 ((ret+=$?))
131 echo "========================================================================"
135 if (( ${#filenames[@]} <= 0 )); then
136 echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)"
137 echo "========================================================================"
140 read -N 6 bin < "$image"
141 case $bin in
142 $'\x71\xc7'*|070701)
143 CAT="cat --"
144 is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null)
145 if [[ "$is_early" ]]; then
146 if (( ${#filenames[@]} > 0 )); then
147 extract_files
148 else
149 echo "Early CPIO image"
150 list_files
152 SKIP="$dracutbasedir/skipcpio"
153 if ! [[ -x $SKIP ]]; then
154 echo
155 echo "'$SKIP' not found, cannot display remaining contents!" >&2
156 echo
157 exit 0
161 esac
163 CAT=$({
164 if [[ $SKIP ]]; then
165 $SKIP "$image"
166 else
167 cat "$image"
168 fi } | {
169 read -N 6 bin
170 case $bin in
171 $'\x1f\x8b'*)
172 echo "zcat --"
174 BZh*)
175 echo "bzcat --"
177 $'\x71\xc7'*|070701)
178 echo "cat --"
180 $'\x02\x21'*)
181 echo "lz4 -d -c"
184 if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then
185 echo "xzcat --single-stream --"
186 else
187 echo "xzcat --"
190 esac
193 skipcpio()
195 $SKIP "$@" | $ORIG_CAT
198 if [[ $SKIP ]]; then
199 ORIG_CAT="$CAT"
200 CAT=skipcpio
203 ret=0
205 if (( ${#filenames[@]} > 0 )); then
206 extract_files
207 else
208 version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/dracut-*' 'usr/lib/dracut/dracut-*' 2>/dev/null)
209 ((ret+=$?))
210 echo "Version: $version"
211 echo
212 echo -n "Arguments: "
213 $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/build-parameter.txt' 'usr/lib/dracut/build-parameter.txt' 2>/dev/null
214 echo
215 echo "dracut modules:"
216 $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/modules.txt' 'usr/lib/dracut/modules.txt' 2>/dev/null
217 ((ret+=$?))
218 list_files
221 exit $ret