Linux: Role and use of initrd [Quick Guide]

6:02 pm April 21, 20177807

I. introduction

one tends to forget, and yet this feature of our expensive Linux distributions is essential. I want to talk about initrd . The acronym shudder. Actually it comes to the abbreviation of Initial RamDisk which is nothing else than an image of a system operating minimum, initialized at the start-up of the system itself.

This type of file uses a special file system, called CRamFS , squashfs or more systematically initramfs . In reality, it is a system of files compressed in gzip format and archived via the command cpio . This image is then loaded into RAM, and will allow to have a minimal system, which will activate the main operating system, or systems without disks, called diskless.

reminder: the Linux kernel could, today, contain all the code of all devices and all the features necessary for systems to work. Therefore, distributions compile a minimum core with basic options and they charge (or discharge), will the cores required, content modules in archive of the initrd.

So, understandably, this file system or initramfs , as it is often called on Debian type distributions, is just essential to the proper functioning of the GNU/Linux distributions.

In short, here are the different phases of a Linux boot:

– the Linux kernel
– loading of initrd (then passed as a parameter to the kernel)
– launch of the linuxrc script, loading the modules needed to start
– start the task init on the device selected

This means that without the initrd , steps 2 and 3 might never work. In addition, the primary operating system would not have the all of its features, since the modules have not been loaded.

However, in case of architecture change disk, partition or material at the level of the starting system, it is imperative to recreate the initrd (or initramfs ), by mentioning the name of the partitions to/etc/fstab file, as appropriate:

 # mkinitrd-fstab = / etc/fstab/boot/initrd - $(uname_–r).img $(uname –r) 

Finally now that we are all convinced of the usefulness of this feature, you can perhaps explore my content, or even venture to change it. Just one last thing, before moving on to the practice, the initrd file is usually stored in the/boot directory , since it is part of start-up equipment and it is passed as a parameter to the kernel.

II. Limitations of the initrd file

Although this installation at the start-up method is efficient, it for still some limitations.

In the first place, the initrd file is based on a block device full who needs a file system full to operate, and, with a size fixed. If ever, you pick a size too small, so we can’t store all scripts or the necessary modules.

Note: Besides, in the other direction, if one chooses a size too large, wasting memory, as a part of the allocated space will not be used.

But as initrd is a static, real device, it consumes memory cache at the level of the Linux kernel and is therefore, in fact, able to manage files according to the traditional methods of the other file systems: paging, swap…

From the time, increases significantly the consumption of memory of the initrd file. To address these drawbacks, the initramfs system for replaced the original initrd file. But the basic principles remain the same.

III. Preparation of the handling on initrd

as for any operation a bit complicated, it is strongly advised to save the initrd file on which we will work. Mishandling arrived so fast!

 # cd/boot # cp - a initramfs - $(uname_–r).img initramfs - current.sav 

Note: on some distributions like CentOS or RedHat, the initrd file is created with the name initramfs. But it’s the same entity initrd.

Then, you must create a working directory, so you can easily manipulate the content of the initrd:

 # mkdir/work / # cd/work/initrd initrd 

IV. Treatments on initrd

you can now make sure, in one operation, to decompress the initrd of the directory boot, in the repertoire of work previously prepared while developing the cpio archive:

 # gunzip - c/boot/initrds - $(uname_–r).img | cpio - i 

ATTENTION : on the other hand, if handling an initramfs file: what is usually the case for CentOS and RedHat distributions version higher than 6, use the command below to unpack archive initramfs:

 # / usr/lib/dracut/skipcpio/boot/initramfs - $(uname_–r).img | gunzip - c | cpio - i - d 

at this stage , in the subdirectory/work/initrd, can then discover the full content of the initrd file (or initramfs ) developed:

you can change what you want, before you restore archive compressed initrd file.

 # find * | cpio - o - H recruiters | gzip-9 - c >/boot/initrd-$(uname –r) - new.img 

as well as for decompression, the reconstitution of archive an initramfs file goes through the following commands:

 # cd/work/initrd # find. | [cpio-create-format='recruiters'>/tmp/initramfs-new#cd/tmp#gzipinitramfs-new#mvinitramfs-newgz/boot/initramfs-newimg

Note: If you are very uncomfortable with these commands, you can, of course, directly overwrite current initrd, rather than create a file – new. Otherwise, also you need to change the charger to start GRUB menu.lst file, in the directory/boot/grub, in order to add an entry for this new initrd file, that one coming to generate.

V. use case

most of the time this type of amendment will allow to integrate a new module kernel, initrd file. This is what is done on distributions like Ubuntu (or Debian, more generally), because there while a text file containing the list of modules into the core of the main system, to change the level of items in the initrd file.