Linux file system initialization process (3) --- load initrd (on)

First, the purpose

 

    This article mainly describes the second stage of the linux3.10 file system initialization process: loading initrd.

    initrd is a temporary file system, loaded into memory by bootload, which contains basic executable programs and drivers. In the initial stage of Linux initialization, it provides a basic operating environment. When the disk file system is successfully loaded, the system will switch to the disk file system and uninstall the initrd.

    If it is an embedded device, then the final file system is initrd.

 

 

Two, cpio file format

 

    The file format commonly used by initrd is cpio. The cpio format records the structure and content of the file system.

    The specific definition of cpio format is shown in Figure 1:

    The file in cpio format is composed of sections, the last section is special, the file name is "TRAILER!!!".

    Each segment is composed of file header, file name and file body; the length of file name and file body are specified by name_len and body_len in the file header, and the file name and file body need to be aligned according to the specified bytes, so the tail contains padding.

    The file header has a total of 110 bytes, the first 6 bytes are fixed at 070701, and the meaning of the remaining bytes are: inode number, file mode, user id, group id, number of links, timestamp, file body length, main Device number, minor device number, device number, file name length, reserved fields.

    For other details, please refer to the init/initramfs.c file, which will not be described here.

                                                   figure 1

 

 

Three, initrd file example

 

    In order to understand the initrd file in cpio format more intuitively, let's look at an example below.

    In the ubuntu environment, the compressed cpio format file initrd is stored in the boot directory.

    Copy the initrd file in the boot directory to any directory, rename it to initrd.gz, and decompress it with gunzip.

    In this way, we get an initrd file in cpio format. Use vi to view the content of the file as shown in Figure 2 (due to the size of the file, only part of the content is displayed):

    A simple analysis shows that the file contains script/nfs-top directory, script/nfs-top/ORDER file, script/nfs-top/udev file, run directory, and TRAILER!!! file marking the end of cpio.

                                                          figure 2

 

 

Fourth, unzip the initrd file

 

    After initrd is decompressed by gunzip, you can use the cpio tool to decompress files in cpio format. The command is as follows:

 

 

 

  1. root: cpio-idmv < initrd  

 

    After the decompression is successful, use the ls command to view the contents of the initrd file as shown in Figure 3:

    The bin and sbin directories contain basic executable programs; the conf and etc directories are configuration files; the lib directory is the dynamic library used by executable programs; the scripts directory is the script program; the init program. The initrd must provide an init program. Linux will jump to the init program after loading the initrd, and the init program is responsible for the subsequent initialization work.

                            image 3

 

 

Five, summary

 

    This article details the initrd file in cpio format and the meaning of each directory after decompression. The initrd file system provides the init program, which will jump to the init program in the later stage of the linux initialization stage, which is responsible for loading the driver and mounting the disk file system and other initialization tasks.

Guess you like

Origin blog.csdn.net/daocaokafei/article/details/114873073