Introduction to lsinitrd Command (with examples)

Introduction to lsinitrd Command (with examples)

Motivation

When working with Linux, there may be situations where you need to analyze the contents of an initramfs image. This can be useful for troubleshooting boot issues, understanding the modules included in the image, or inspecting specific elements within the image itself. In such cases, the lsinitrd command comes in handy, allowing you to view the contents of an initramfs image.

This article will guide you through various use cases of the lsinitrd command, providing code examples, explanations, and sample outputs for each scenario.

1: Show the contents of the initramfs image for the current kernel

Code:

lsinitrd

Explanation: Executing the lsinitrd command without any options will display the contents of the initramfs image for the current kernel. The initramfs image contains various files, directories, and modules required during the early boot process.

Example Output:

Image: /boot/initramfs-5.4.0-81-generic.img
========================================================================
dr-xr-xr-x   7 root     root        0 Jun 28 14:30 .
drwxr-xr-x  22 root     root        0 Jun 28 14:30 ..
-rw-r--r--   1 root     root   987040 Jun 28 14:30 base.tar.gz
-rw-r--r--   1 root     root    13081 Jun 28 14:30 blockdev.console-from
-rw-r--r--   1 root     root    57188 Jun 28 14:30 blockdev.console-to
...

2: Show the contents of the initramfs image for the specified kernel

Code:

lsinitrd --kver 5.10.0-12-generic

Explanation: If you have multiple kernel versions installed on your system, you can specify a particular kernel version using the --kver option to display the contents of the respective initramfs image. This option is useful when troubleshooting boot issues related to a specific kernel version.

Example Output:

Image: /boot/initramfs-5.10.0-12-generic.img
========================================================================
dr-xr-xr-x   7 root     root        0 Oct  7 14:30 .
drwxr-xr-x  22 root     root        0 Oct  7 14:30 ..
-rw-r--r--   1 root     root   987040 Oct  7 14:30 base.tar.gz
-rw-r--r--   1 root     root    13096 Oct  7 14:30 blockdev.console-from
-rw-r--r--   1 root     root    57368 Oct  7 14:30 blockdev.console-to
...

3: Show the contents of the specified initramfs image

Code:

lsinitrd path/to/initramfs.img

Explanation: In certain scenarios, you may want to analyze an initramfs image located at a specific path. By providing the path to the lsinitrd command, you can view the contents of the specified initramfs image directly, regardless of the currently running kernel.

Example Output:

Image: path/to/initramfs.img
========================================================================
dr-xr-xr-x   7 root     root        0 Sep 20 16:30 .
drwxr-xr-x  22 root     root        0 Sep 20 16:30 ..
-rw-r--r--   1 root     root   987040 Sep 20 16:30 base.tar.gz
-rw-r--r--   1 root     root    13105 Sep 20 16:30 blockdev.console-from
-rw-r--r--   1 root     root    57648 Sep 20 16:30 blockdev.console-to
...

4: List modules included in the initramfs image

Code:

lsinitrd --mod

Explanation: When troubleshooting boot-related issues, it can be helpful to obtain a list of modules included in the initramfs image. The --mod option, when used with lsinitrd, prints the names of these modules.

Example Output:

Module List:
========================================================================
fuse
ext4
ahci
...

5: Unpack the initramfs to the current directory

Code:

lsinitrd --unpack

Explanation: Sometimes, analyzing the internal contents of an initramfs image requires extracting its files and directories. The --unpack option allows you to unpack the initramfs image, extracting its contents to the current working directory.

Example Output:

Unpacking: /boot/initramfs-5.10.0-12-generic.img
========================================================================
Extracting: usr
Extracting: usr/lib
Extracting: usr/lib/x86_64-linux-gnu
...

Related Posts

How to use the command "nyxt" (with examples)

How to use the command "nyxt" (with examples)

“nyxt” is a keyboard-driven web browser designed for power users. It provides a more efficient and streamlined web browsing experience through its keyboard-centric navigation and customization options.

Read More
How to use the command 'say' (with examples)

How to use the command 'say' (with examples)

The ‘say’ command is a powerful text-to-speech tool in macOS that allows users to convert text into spoken words.

Read More
How to use the command webinspectord (with examples)

How to use the command webinspectord (with examples)

The webinspectord command relays commands between Web Inspector and remote targets like WKWebView.

Read More