Analysis of Initrd mechanism in Linux2.6 Kernel

Source: Internet
Author: User
Article Title: Analysis of Initrd mechanism in Linux2.6 kernel. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

1. What is Initrd?

The English meaning of initrd is boot loader initialized RAM disk, which is the memory disk initialized by boot loader. Before the Linux kernel starts, boot loader loads the initrd file in the storage medium to the memory. When the kernel starts, it accesses the initrd File System in the memory before accessing the real root file system. When boot loader is configured with initrd, the kernel startup is divided into two phases. In the first phase, the system executes "a file" in the initrd File System to load the driver module and other tasks, the second stage will execute the/sbin/init process in the real root file system. The "file" mentioned here, the Linux kernel is different from the previous kernel version, so the "file" is used for the time being, which will be detailed later. The purpose of Phase 1 startup is to clear all obstacles for Phase 2 startup. The most important thing is to load the driver module of the root file system storage medium. We know that the root file system can be stored on a variety of media, including IDE, SCSI, and USB. If we compile the drivers of these devices into the kernel, we can imagine how huge and bloated the kernel will be.

Initrd has the following functions:

1. essential components of the linux release

The linux release must adapt to different hardware architectures. It is unrealistic to compile all drivers into the kernel. The initrd technology is the key technology to solve this problem. The Linux release only compiles the basic hardware driver in the kernel. During the installation process, it detects the system hardware and generates the initrd that includes the system hardware driver, it is nothing more than a flexible solution.

2. essential components of livecd

Compared with the linux release, livecd may face more complex hardware environments, so initrd must also be used.

3. initrd must be used to create a Linux usb boot disk.

A usb device is a device that is relatively slow to start. It takes several seconds to load the driver to make the device available. If the usb driver is compiled into the kernel, the kernel usually cannot successfully access the file system on the usb device. Because the usb device is not initialized when the kernel accesses the usb device. Therefore, the general practice is to load the usb driver in initrd, then sleep for a few seconds, wait until the usb device is initialized and then mount the file system in the usb device.

4. You can easily enable personalized bootsplash in the linuxrc script.

2. Process of Initrd processed by Linux2.4 Kernel

To give readers a clear understanding of the changes in the initrd mechanism of the Linux2.6 kernel, before focusing on the initrd of the Linux2.6 kernel, let's give a brief introduction to the initrd of the linux2.4 kernel. The initrd format of the Linux2.4 kernel is a file system image file. This document calls it image-initrd to differentiate initrd in the cpio format of the linux2.6 kernel described later. the initrd processing process of the linux2.4 kernel is as follows:

1. boot loader loads kernel and/dev/initrd content to the memory./dev/initrd is a device initialized by boot loader and stores initrd.

2. During kernel initialization, the kernel decompress the/dev/initrd device and copy it to the/dev/ram0 device.

3. the kernel can read and write the/dev/ram0 device as the original root file system.

4. If/dev/ram0 is specified as the real root file system, the kernel will be started normally until the last step.

5. Run the/linuxrc file on initrd. linuxrc is usually a script file that loads the drivers required to access the root file system by the kernel and loads the root file system.

6./after executing linuxrc, the real root file system is mounted.

7. If the real root file system has the/initrd directory,/dev/ram0 will be moved from/to/initrd. Otherwise,/dev/ram0 will be uninstalled if the/initrd directory does not exist.

8. run/sbin/init. the initrd execution of the linux2.4 kernel is an intermediate stage of kernel startup. That is to say, after the initrd/linuxrc is executed, the kernel will continue to execute the initialization code, we will see that this is a significant difference between the initrd processing process of the linux2.4 kernel and the 2.6 kernel.

[1] [2] [3] [4] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.