How to Generate an initramfs file using the Root File System in Linux

Beaglebone black board






In this article, we show how to generate an initramfs file using the root file system in linux.

So, first, what is initramfs?

initramfs stands for initial RAM-based file system.

An initramfs is a file system hierarchy made ot live in the RAM of the device by compressing it. We use compression because RAM is precious; we cannot use the whole RAM space just to store the file system.

During the booting process, linux mounts this initramfs as the initial file system. This means that only RAM is needed to mount the file system and get going with the boot process.

Using an initramfs is optional and is not compulsory or used in every case. So when do we use an initramfs?

You would use an initramfs if you have a product with a wide range of peripherals, for example.

With a wide range of peripherals, device drivers must be in place and loaded into the kernel space. And along with the drivers some peripherals may require the firmware binaries to perate.

This is why we use initramfs, a minimal file system, where all the drivers and firmware are stored and load this file system into the RAM and ask linux to mount this file system during the booting process. Using kernel boot arguments, you can specify that the file system resides in RAM.

When the kernel mounts the file system from RAM, it loads all the required drivers for the product with all its peripherals, which will be ready to operate, because all the drivers and firmware are in place.

After this, we can get rid of this initial RAM-based file system and use (switch to) some other more advanced file system which resides on other memory devices such as eMMC/SD card or even from a network connection.

So basically, the initramfs represents the file system with all the peripheral drivers and firmware loaded at an early stage of the boot process, where it gives all the minimal requirements to boot the linux kernel successfully on the board from just RAM. What you should store in the initramfs depends on your product requirements. This may include the important drivers and firmware, product specific scripts, graphic display logos, etc.

An alternative way of doing this would be to make sure all the device drivers are incorporated into the kernel image, but this is not a good idea, because it would make the kernel image only specific to your product, as well as increase the linux kernel image size.

So the initramfs is the method that is frequently employed.

So the next thing is how do we generate the initramfs?

If you take the root filesystem from an SDK source such as Texas Instruments and extract it, you then need to get into this extracted folder.

In this folder, we're going to run a few commands.

The first command we need to run is to generate a cpio archive.

This is shown below.





This command run in the terminal produces the following output.


Creating an initramfs file- CPIO archive folder


Next we run the following command in order to generate a gz archive.

This is shown below.





This command run in the terminal produces the following output.


Creating an initramfs file- gz archive folder


Next, we need to make sure that we have u-boot-tools software installed in our linux system.

This software module will install all u-boot related tools along with the mkImage tool, which we use directly to create the initramfs file.

To install the u-boot-tools software, type in the following command shown below.





This is shown below.


Installing u-boot-tools in linux


u-boot-tools was already installed on my system, as you can see.

As stated before, this gives us the mkimage command, which is the command that directly creates the initramfs file.

Using the command below, we can create the initramfs file.





This creates an initramfs file with the name "Root Filesystem" at the load address of 0x80800000 that is of image type, Arm Linux RAMDisk Image.

All of this is shown below.


Creating an initramfs file in linux


You can see all of the metadata that was in the command.

This initramfs file will now be able to run on the boot of the linux disk image.

If we look in the Downloads folder, we should see the initramfs file.

This is shown below.


initramfs file in folder on linux operating system


This file should now be used when booting the linux system in certain cases when initramfs files are necessary.

So this is how to generate initramfs files using the root file system in linux.



Related Resources





HTML Comment Box is loading comments...