How To Uncompress and List An Initramfs Content On Linux
How To Uncompress and List An Initramfs Content On Linux
Menu
Suppose we have our Linux system setup with an almost-full disk encryption, with only
the /boot partition unencrypted. Assuming we achieved encryption by using a LUKS
container, we need the appropriate software to unlock it at boot. This software,
however, is part of the encrypted system. Since the Linux 2.6 series, the solution to this,
and other similar problems, is called initramfs (Initial ramfs). In this article we see
how an initramfs is composed and how to extract or list its content.
What is an initramfs
How to extract/inspect an initramfs with basic tools
How to list the content of an initramfs with lsinitrd/lsinitramfs
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 1/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
System Distribution-independent
Software All the software mentioned in this tutorial should be already installed
Other None
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 2/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
Conventions
$ – requires given linux-commands to be executed as a regular non-
privileged user
What is an initramfs?
We saw the “why” of an initramfs: make required software and kernel modules
available at an early boot stage. But what is an initramfs, and where it is stored? An
initramfs is basically a compressed cpio archive. Normally it is stored in the /boot
partition, together with the kernel image it is associated with, and named after (e.g
initramfs-5.14.14-300.fc35.x86_64.img ). In certain situations it would be useful to
know how to check its content and/or extract it. Let’s see how to do it.
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 3/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
early_cpio
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/GenuineIntel.bin
10 blocks
The command above is prefixed with sudo just because the initramfs file I am working
with, for the sake of this tutorial, on Fedora, is owned by root and has 600 as
permissions set. Once the command is executed, the following files and directories are
created in the working directory:
├── early_cpio
└── kernel
└── x86
└── microcode
└── GenuineIntel.bin
3 directories, 2 files
All there is, is basically intel kernel microcode. Is that all there is inside the initramfs?
Actually, it is not. If we observe the output of the command we ran in the previous
example, we can see cpio stopped after 10 blocks of 512 Bytes (5120 Bytes); if we check
the total size of the archive, however, we can see it is bigger than that:
$ sudo ls -l /boot/initramfs-5.14.14-300.fc35.x86_64.img
From the output of ls we can see that the total size of the initramfs is of 34594545
Bytes. What happened to the rest of the initramfs content? Sometimes, as in this case,
an initramfs can be actually composed by two parts or segments:
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 4/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
In the previous example what we extracted was the content of the first, small cpio
archive. How can we extract the content of the second, compressed archive which
contains the actual filesystem mounted during the early stages of boot? First of all we
should isolate it.
In this case, we know that the first cpio archive is composed by 10 blocks of 512 Bytes,
therefore we can use dd to start reading from that point onward, and save the result to
a file which we will call main_archive . We can achieve that using the skip option of
dd , which, as its name suggests, let us skip the given number of blocks from input (by
default each block is considered to be 512 Bytes). We run:
Once dd finishes running, we will find the main_archive file created in our working
directory. Now, what we have to do, is to find what type of compression was used for it.
We can do it using the file utility, which in this case returns the following result:
$ file main_archive
From the output of the command we can clearly see that the file was compressed using
gzip. Now we know everything we need to uncompress and extract the cpio archive. We
can do everything with just one command and some shell piping. Before we do it, let’s
create a directory called initramfs_filesystem and extract all the content of the
compressed archive inside of it:
$ mkdir initramfs_filesystem
To extract the archive into a directory other than our working one, as you can notice,
we used the -D option of the cpio command, and passed the path of the directory as
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 5/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
argument. Once the extraction takes place, if we take a look at the extracted initramfs
content, we can see it resembles the real root filesystem:
$ ls initramfs_filesystem
bin dev etc init lib lib64 proc root run sbin shutdown sys sysr
What if we just want to obtain a list of the files and directories contained in the
initramfs without actually extracting them? Very simple. We can run cpio with the -t
option:
The command above would produce an output similar to the one below (truncated):
bin
dev
dev/console
dev/kmsg
dev/null
dev/random
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 6/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
dev/urandom
etc
etc/authselect
etc/authselect/nsswitch.conf
etc/block_uuid.map
etc/cmdline.d
etc/conf.d
etc/conf.d/systemd.conf
etc/crypttab
[...]
Inspecting or extracting the initramfs the way we did it above can be a little tedious;
luckily there are some specific utilities designed to achieve the same results. Let’s take
a look at them.
To list the content of an initramfs, for example, we can use the lsinitrd and
lsinitramfs scripts. The former is used on Fedora and the Red Hat family of
distributions, the latter on Debian and Debian-based distributions. The lsinitrd is a
little bit misleading, since an initrd was basically what was used before initramfs was
adopted, but so it is. The use of the script is really simple. We invoke it and pass it the
path of the initramfs image we want to inspect as argument:
The script produces an output which includes both the content of the “early”,
uncompressed cpio archive, the dracut modules used to generate the initramfs (dracut
is the program used to create the initramfs on Fedora), and the content of the main,
compressed, cpio archive (output is truncated for obvious reasons):
=======================================================================
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 7/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
drwxr-xr-x 3 root root 0 Oct 28 21:55 .
dracut modules:
systemd
systemd-initrd
systemd-sysusers
nss-softokn
dbus-broker
dbus
i18n
network-manager
network
ifcfg
drm
plymouth
crypt
dm
kernel-modules
kernel-modules-extra
kernel-network-modules
lvm
rootfs-block
terminfo
udev-rules
dracut-systemd
usrmount
base
fs-lib
shutdown
=======================================================================
drwxr-xr-x 12 root root 0 Oct 28 21:55 .
[...]
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 8/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
The lsinitramfs script works basically the same way. It is part of the “initramfs-tools-
core” package on Debian, so there is no need to install it. By default it just outputs the
list of the files in the initramfs; if the -l option is used, however, files and directories
permissions are also reported:
lsinitramfs -l /boot/initrd.img-5.10.0-8-amd64
[...]
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 9/14
7/11/22, 11:42 How to uncompress and list an initramfs content on Linux - Linux Tutorials - Learn Linux Configuration
$ unmkinitramfs /boot/initrd.img-5.10.0-8-amd64 .
Conclusions
In this tutorial we learned what is an initramfs and what is its purpose on modern
Linux distributions. We saw how sometimes it is composed by two cpio archives: the
first, uncompressed and really small, which usually contains cpu microcode, and the
second, compressed, which contains the rest of the content (software, kernel modules
etc…). We saw how to extract an initramfs using basic tools and dedicated scripts, and
how to list its content.
System Administration
administration, commands, filesystem, installation
How to install PipeWire on Ubuntu Linux
How to build an initramfs using Dracut on Linux
https://linuxconfig.org/how-to-uncompress-and-list-an-initramfs-content-on-linux 10/14