How to extract the contents of an initrd.img file?

initrd is an acronym for ‘Initial Ramdisk’. Its is a Ramdisk image that is used while booting the kernel. The initrd image contains some basic utilities and essential drivers which allow the kernel to mount the root partition and invoke init.

In simpler terms, initrd.img file is used to boot the system to the state where the real kernel (vmlinuz) can take over the continue the boot process.

To extract the contents of the initrd.img file, follow the below steps. These steps are intended to be carried out in a Linux workstation. They are not compatible to a Microsoft® Windows machine.

Step 1: Copy the initrd.img from the Linux install disc to a temporary folder on your Linux machine.


mkdir /tmp/initrd
cp <Linux-install-media-mount-point>/isolinux/initrd.img /tmp/initrd

Step 2: initrd.img is basically a GZip image. Uncompress it to a specific folder.


cd/tmp/initrd
gunzip < /tmp/initrd/initrd.img

Step 3: The output of the above gunzip command is a file named ‘initrd’ located in /tmp/initrd folder. Mount this file on a custom directory.


mkdir /mnt/initrd
mount –ro loop /tmp/initrd/initrd /mnt/initrd
cd /mnt/initrd

Step 4: Create a folder where you prefer to save and later modify the contents of initrd. Copy the contents from the directory where initrd has been mounted to the newly created folder.


mkdir /tmp/initrd/contents
cp –r /mnt/initrd/* /tmp/initrd/contents


Resources:

 

About these ads

2 thoughts on “How to extract the contents of an initrd.img file?

  1. A simple alternative to extract the contents of initrd.img is the command: gzip -dc initrd.img | cpio -dui

    This command would extract the contents of initrd.img into the current folder and also will not delete the original initrd.img file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s