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/>.
22 echo "Usage: ${0##*/} [options] [<initramfs file> [<filename> [<filename> [...] ]]]"
23 echo "Usage: ${0##*/} [options] -k <kernel version>"
25 echo "-h, --help print a help message and exit."
26 echo "-s, --size sort the contents of the initramfs by size."
27 echo "-m, --mod list modules."
28 echo "-f, --file <filename> print the contents of <filename>."
29 echo "--unpack unpack the initramfs, instead of displaying the contents."
30 echo " If optional filenames are given, will only unpack specified files,"
31 echo " else the whole image will be unpacked. Won't unpack anything from early cpio part."
32 echo "--unpackearly unpack the early microcode part of the initramfs."
33 echo " Same as --unpack, but only unpack files from early cpio part."
34 echo "-v, --verbose unpack verbosely."
35 echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>."
40 [[ $dracutbasedir ]] || dracutbasedir
=/usr
/lib
/dracut
60 # shellcheck disable=SC2181
78 -s |
--size) sorted
=1 ;;
83 -m |
--mod) modules
=1 ;;
84 -v |
--verbose) verbose
="--verbose" ;;
86 --unpackearly) unpackearly
=1 ;;
99 [[ $KERNEL_VERSION ]] || KERNEL_VERSION
="$(uname -r)"
103 if ! [[ -f $image ]]; then
105 echo "$image does not exist"
112 [[ -f /etc
/machine-id
]] && read -r MACHINE_ID
< /etc
/machine-id
114 if [[ -d /efi
/loader
/entries ||
-L /efi
/loader
/entries
]] \
115 && [[ $MACHINE_ID ]] \
116 && [[ -d /efi
/${MACHINE_ID} ||
-L /efi
/${MACHINE_ID} ]]; then
117 image
="/efi/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
118 elif [[ -d /boot
/loader
/entries ||
-L /boot
/loader
/entries
]] \
119 && [[ $MACHINE_ID ]] \
120 && [[ -d /boot
/${MACHINE_ID} ||
-L /boot
/${MACHINE_ID} ]]; then
121 image
="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
123 image
="/boot/initramfs-${KERNEL_VERSION}.img"
133 if ! [[ -f $image ]]; then
135 echo "No <initramfs file> specified and the default image '$image' cannot be accessed!"
142 TMPDIR
="$(mktemp -d -t lsinitrd.XXXXXX)"
143 # shellcheck disable=SC2064
144 trap "rm -rf '$TMPDIR'" EXIT
147 for d
in lib64
/dracut lib
/dracut usr
/lib64
/dracut usr
/lib
/dracut
; do
153 ((${#filenames[@]} == 1)) && nofileinfo
=1
154 for f
in "${!filenames[@]}"; do
155 [[ $nofileinfo ]] ||
echo "initramfs:/$f"
156 [[ $nofileinfo ]] ||
echo "========================================================================"
157 $CAT "$image" 2> /dev
/null |
cpio --extract --verbose --quiet --to-stdout "$f" 2> /dev
/null
159 [[ $nofileinfo ]] ||
echo "========================================================================"
160 [[ $nofileinfo ]] ||
echo
165 echo "dracut modules:"
166 # shellcheck disable=SC2046
167 $CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
168 $
(dracutlibdirs modules.txt
) 2> /dev
/null
173 echo "========================================================================"
174 if [ "$sorted" -eq 1 ]; then
175 $CAT "$image" 2> /dev
/null |
cpio --extract --verbose --quiet --list |
sort -n -k5
177 $CAT "$image" 2> /dev
/null |
cpio --extract --verbose --quiet --list |
sort -k9
180 echo "========================================================================"
183 list_squash_content
() {
184 SQUASH_IMG
="squash-root.img"
185 SQUASH_TMPFILE
="$TMPDIR/initrd.root.sqsh"
187 $CAT "$image" 2> /dev
/null |
cpio --extract --verbose --quiet --to-stdout -- \
188 $SQUASH_IMG > "$SQUASH_TMPFILE" 2> /dev
/null
189 if [[ -s $SQUASH_TMPFILE ]]; then
190 echo "Squashed content ($SQUASH_IMG):"
191 echo "========================================================================"
192 unsquashfs
-ll "$SQUASH_TMPFILE" |
tail -n +4
193 echo "========================================================================"
198 if ((${#filenames[@]} > 0)); then
199 for f
in "${!filenames[@]}"; do
200 $CAT "$image" 2> /dev
/null |
cpio -id --quiet $verbose $f
204 $CAT "$image" 2> /dev
/null |
cpio -id --quiet $verbose
209 read -r -N 2 bin
< "$image"
210 if [ "$bin" = "MZ" ]; then
211 command -v objcopy
> /dev
/null ||
{
212 echo "Need 'objcopy' to unpack an UEFI executable."
216 --dump-section .linux
="$TMPDIR/vmlinuz" \
217 --dump-section .initrd
="$TMPDIR/initrd.img" \
218 --dump-section .cmdline
="$TMPDIR/cmdline.txt" \
219 --dump-section .osrel
="$TMPDIR/osrel.txt" \
222 image
="$TMPDIR/initrd.img"
223 [ -f "$image" ] ||
exit 1
226 if ((${#filenames[@]} <= 0)) && [[ -z $unpack ]] && [[ -z $unpackearly ]]; then
227 if [ -n "$uefi" ]; then
228 echo -n "initrd in UEFI: $uefi: "
229 du
-h "$image" |
while read -r a _ ||
[ -n "$a" ]; do echo "$a"; done
230 if [ -f "$TMPDIR/osrel.txt" ]; then
231 name
=$
(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
232 id
=$
(sed -En '/^ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
233 build
=$
(sed -En '/^BUILD_ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
234 echo "OS Release: $name (${id}-${build})"
236 if [ -f "$TMPDIR/vmlinuz" ]; then
237 version
=$
(strings -n 20 "$TMPDIR/vmlinuz" |
sed -En '/[0-9]+\.[0-9]+\.[0-9]+/ { p; q 0 }')
238 echo "Kernel Version: $version"
240 if [ -f "$TMPDIR/cmdline.txt" ]; then
242 sed -En 's/\s+/\n/g; s/\x00/\n/; p' "$TMPDIR/cmdline.txt"
245 echo -n "Image: $image: "
246 du
-h "$image" |
while read -r a _ ||
[ -n "$a" ]; do echo "$a"; done
249 echo "========================================================================"
252 read -r -N 6 bin
< "$image"
254 $
'\x71\xc7'* |
070701)
256 is_early
=$
(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2> /dev
/null
)
257 # Debian mkinitramfs does not create the file 'early_cpio', so let's check if firmware files exist
258 [[ "$is_early" ]] || is_early
=$
(cpio --list --verbose --quiet --to-stdout -- 'kernel/*/microcode/*.bin' < "$image" 2> /dev
/null
)
259 if [[ "$is_early" ]]; then
260 if [[ -n $unpack ]]; then
261 # should use --unpackearly for early CPIO
263 elif [[ -n $unpackearly ]]; then
265 elif ((${#filenames[@]} > 0)); then
268 echo "Early CPIO image"
271 if [[ -d "$dracutbasedir/skipcpio" ]]; then
272 SKIP
="$dracutbasedir/skipcpio/skipcpio"
274 SKIP
="$dracutbasedir/skipcpio"
276 if ! [[ -x $SKIP ]]; then
278 echo "'$SKIP' not found, cannot display remaining contents!" >&2
287 bin
="$($SKIP "$image" | { read -r -N 6 bin && echo "$bin"; })"
289 read -r -N 6 bin
< "$image"
298 $
'\x71\xc7'* |
070701)
307 $
'\x28\xB5\x2F\xFD'*)
311 if echo "test" | xz | xzcat
--single-stream > /dev
/null
2>&1; then
312 CAT
="xzcat --single-stream --"
320 $SKIP "$@" |
$ORIG_CAT
328 if ((${#filenames[@]} > 1)); then
329 TMPFILE
="$TMPDIR/initrd.cpio"
330 $CAT "$image" 2> /dev
/null
> "$TMPFILE"
339 if [[ -n $unpack ]]; then
341 elif ((${#filenames[@]} > 0)); then
344 # shellcheck disable=SC2046
345 version
=$
($CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
346 $
(dracutlibdirs
'dracut-*') 2> /dev
/null
)
348 echo "Version: $version"
350 if [ "$modules" -eq 1 ]; then
352 echo "========================================================================"
354 echo -n "Arguments: "
355 # shellcheck disable=SC2046
356 $CAT "$image" |
cpio --extract --verbose --quiet --to-stdout -- \
357 $
(dracutlibdirs build-parameter.txt
) 2> /dev
/null