LinuxCommandLibrary

lsinitrd

Inspect the contents of initrd/initramfs images

TLDR

Show the contents of the initramfs image for the current kernel

$ lsinitrd
copy

Show the contents of the initramfs image for the specified kernel
$ lsinitrd --kver [kernel_version]
copy

Show the contents of the specified initramfs image
$ lsinitrd [path/to/initramfs.img]
copy

List modules included in the initramfs image
$ lsinitrd --mod
copy

Unpack the initramfs to the current directory
$ lsinitrd --unpack
copy

SYNOPSIS

lsinitrd [OPTIONS] [INITRAMFS_IMAGE [KERNEL_VERSION]]

PARAMETERS

INITRAMFS_IMAGE
    The path to the initramfs or initrd image file to inspect. If omitted, lsinitrd typically tries to locate the image for the current or latest kernel.

KERNEL_VERSION
    An optional argument specifying the kernel version string (e.g., '4.18.0-305.el8.x86_64') for which to find the initramfs image, if INITRAMFS_IMAGE is not explicitly provided.

--help, -h
    Display a help message and exit.

--file <initramfs_file>, -f <initramfs_file>
    Explicitly specify the initramfs or initrd image file to inspect.

--kver <kernel_version>, -k <kernel_version>
    Specify the kernel version string to locate the corresponding initramfs image.

--verbose, -v
    Provide more detailed output, which may include CPIO header information or file sizes.

--debug, -d
    Enable debug output for the lsinitrd script itself, useful for troubleshooting issues with the command's execution.

--show-modules, -s
    List only the kernel modules (drivers) found within the initramfs image.

--list-files, -l
    Explicitly list the files and directories inside the initramfs. This is often the default behavior if no other action is specified.

DESCRIPTION

The lsinitrd command is a crucial diagnostic utility used to inspect the contents of an initramfs (initial RAM filesystem) or initrd (initial RAM disk) image.
These images are integral to the Linux boot process, as they provide a minimal root filesystem in RAM, containing essential kernel modules (like filesystem drivers) and scripts needed to mount the actual root filesystem from the disk.

lsinitrd allows system administrators and developers to examine what's inside these compressed archives without actually booting the system with them. This is invaluable for troubleshooting boot failures, verifying included drivers, or understanding the exact sequence of operations before the main root filesystem is switched over. It typically works by decompressing the image on the fly and then using cpio to list its contents. The command can operate on a specified image file or, if no file is given, often defaults to the initramfs image corresponding to the currently running kernel or the latest installed kernel. Its output usually includes filenames, their permissions, and sometimes their sizes, providing a detailed view of the early boot environment.

CAVEATS

The lsinitrd command relies on standard decompression utilities (like gzip, xz, zstd) and cpio being available on the system to decompress and list the contents of the initramfs.
It is primarily a read-only inspection tool; it cannot modify or extract files from the initramfs image directly (for extraction, tools like unmkinitramfs or cpio itself are typically used).
The exact set of options and their behavior might slightly vary depending on the Linux distribution and the initramfs generation utility (dracut, mkinitramfs, etc.) it's associated with.

HOW IT WORKS

Internally, lsinitrd first identifies the compression format of the initramfs image (e.g., gzip, xz, zstd). It then pipes the decompressed stream to the cpio command, typically with the -t (list) and -v (verbose) options, to display the archive's contents.

IMPORTANCE IN BOOT PROCESS

The initramfs image is crucial for the Linux kernel to successfully boot and mount the real root filesystem. It contains essential device drivers (e.g., for NVMe, SCSI, software RAID, LVM), filesystem tools, and a minimal init program that sets up the environment before handing control over to the actual init process on the disk-based root filesystem. Troubleshooting issues in this early boot stage often requires inspecting the initramfs contents using lsinitrd.

HISTORY

The lsinitrd command emerged as a necessary companion to the utilities responsible for creating initial boot environments in Linux. Initially, systems used an initrd (initial RAM disk), a block device-based approach. Later, the more flexible initramfs (initial RAM filesystem), which uses a tmpfs (temporary file system) and a CPIO archive, became the standard. lsinitrd evolved alongside these changes, particularly gaining prominence with the adoption of dracut as a primary initramfs generator on many modern distributions. Its development has focused on providing a convenient, human-readable way to peek into these critical boot components, aiding in debugging and system understanding.

SEE ALSO

dracut(8), mkinitrd(8), cpio(1), unmkinitramfs(8), initramfs(7)

Copied to clipboard