2.6.24 kernel compilation-Analysis of initrd-2.6.24.img

Source: Internet
Author: User
2.6.24 kernel compilation-initrd-2.6.24.img analysis-Linux general technology-Linux programming and kernel information, the following is a detailed reading. The English meaning of initrd is boot loader initialized RAM disk, which is the memory disk initialized by boot loader. Before the Linux kernel is started, bootloader loads the initrd file in the storage medium to the memory. When the kernel is started, it accesses the initrd File System in the memory before accessing the real root file system. 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. img is an important file during Linux Startup. If initrd is not specified. img or specified initrd. if the img does not contain the correct driver module, the system will be suspended at startup and the error "kernel panic: VFS: Unable to mount root fs on" will be reported .)

It divides kernel startup into two phases: retaining the least basic startup code in the kernel, and then placing support for various hardware devices in the initrd module, in this way, the required modules can be loaded from the root file system mounted by initrd during the startup process. One advantage of this is that you can flexibly support different hardware by modifying the content in initrd without changing the kernel. At the end of the startup, the root file system can be mounted to another device.
Initrd. img is not like the ramdisk cramfs file with the. img extension. It is a ramdisk file compressed with gzip-9. Here is my analysis process.

First copy the initrd-2.6.24.img to the operating Directory: (test environment: redflag6.0)

Cp initrd-2.6.24.img/home/kernel/initrd.gz

Decompress:

Gunzip initrd.gz

After decompression, you can see an initrd file without the gz suffix.

Here we can use "file initrd" to view the file type.

Here we can use another method to analyze and view the content in initrd. However, since this method has not been tested, it is not described in detail, but this method is also listed.

Mount? O loop initrd/mnt

Cd/mnt

Now you can see the content in initrd.

Here is how I tested it on my machine. The environment is redflag6.0.

Cp initrd-2.6.24.img/home/kernel/initrd.gz

Cd/home/kernel/

Gunzip-dc initrd | cpio? Idmv

In this case, you can see the content in initrd in the folder before the ticket.

Here we can see some of the following directories and files (of course, excluding initrd.gz, which was originally cp ):

Bin:

There are three files: insmod modprobe, and nash. insmod is used to load the inland river module. We can also see that modprobe points to the nash program. What is nash? Nash (not a shell) is not a SHELL, but a simple command interpreter designed as small as possible. It is mainly used to explain the RC or init simple scripts in the initialization of ram disk. Common build commands for nash are as follows:

Echo outputs the string to the standard output, but it does not function as much as echo in the system.

Find displays the files with the matched names in the specified path, that is, only the-name parameter in the find command in linux is supported.

Losetup helps set the file to the loopdev/dev/loopdev device.

Mkdevices specifies the path for storing the created block device files, for example, mkdevices/dev.

Mknod

Mkrootdev creates the device node of the root file system and creates the node corresponding to the device according to "root =" in the parameter passed by the kernel. The node name is/dev/root, it not only generates the corresponding device node according to root =/dev/xxx, but also detects all hard disk partitions in case of root = LABEL =, to find the partition corresponding to the volume marked.

T_t_root converts the root file system and mounts the temporary root file system.

Raidautorun automatically detects all raid Devices

Showlabels: displays the LABEL and UUID sw of the device.

The itchroot and pivot_root functions are similar to those used to convert the root file system. But it can only be used for 2.6 or later cores.

Bootsplash: Graphical Startup Process of the kernel.

Dev: when the system starts, some required device files are character devices, but there is a folder, I do not know how to use it?

Etc: As we all know, this is a directory for storing configuration files. This directory is very common in embedded systems. The user programs or configuration commands to be executed after the system is started are written in the form of shell programs. It is not described here.

Init: init is the core file it directs. In initrd of cpio format, the file name can only be init. Init is a script file that can be executed by nash. It is responsible for loading the driver required by the kernel to access the root file system and loading the root file system.

Proc:

Sbin: it points to the bin

Sys, Sysroot, User: That's not much to say.

Content in the Init file.

#! /Bin/nash



Mount-t proc/proc

Setquiet

Echo Mounting proc filesystem

Echo Mounting sysfs filesystem

Mount-t sysfs/sys

Echo>/sys/power/suspend2/do_resume

Echo Creating/dev

Mount-o mode = 0755-t tmpfs/dev

Mkdir/dev/pts

Mount-t devpts-o gid = 5, mode = 620/dev/pts

Mkdir/dev/shm

Mkdir/dev/mapper

Echo Creating initial device nodes

Mknod/dev/null c 1 3

Mknod/dev/zero c 1 5

Mknod/dev/cmdty c 4 0

Mknod/dev/tty c 5 0

Mknod/dev/console c 5 1

Mknod/dev/ptmx c 5 2

Mknod/dev/rtc c 10 10 135

Mknod/dev/tty0 c 4 0

Mknod/dev/tty1 c 4 1

Mknod/dev/tty2 c 4 2

Mknod/dev/tty3 c 4 3

Mknod/dev/tty4 c 4 4

Mknod/dev/tty5 c 4 5

Mknod/dev/tty6 c 4 6

Mknod/dev/tty7 c 4 7

Mknod/dev/tty8 c 4 8

Mknod/dev/tty9 c 4 9

Mknod/dev/tty10 c 4 10

Mknod/dev/tty11 c 4 11

Mknod/dev/tty12 c 4 12

Mknod/dev/ttyS0 c 4 64

Mknod/dev/ttyS1 c 4 65

Mknod/dev/ttyS2 c 4 66

Mknod/dev/ttyS3 c 4 67

Echo Setting up hotplug.

Hotplug

Echo Creating block device nodes.

Mkblkdevs

Echo "Loading uhci-hcd.ko module"

Insmod/lib/uhci-hcd.ko

Echo "Loading ohci-hcd.ko module"

Insmod/lib/ohci-hcd.ko

Echo "Loading ehci-hcd.ko module"

Insmod/lib/ehci-hcd.ko

Mount-t usb fs/proc/bus/usb

Echo "Loading jbd. ko module"

Insmod/lib/jbd. ko

Echo "Loading ext3.ko module"

Insmod/lib/ext3.ko

Echo "Loading scsi_mod.ko module"

Insmod/lib/scsi_mod.ko

Echo "Loading sd_mod.ko module"

Insmod/lib/sd_mod.ko

Echo "Loading libata. ko module"

Insmod/lib/libata. ko

Echo "Loading ata_generic.ko module"

Insmod/lib/ata_generic.ko

Echo "Loading ata_piix.ko module"

Insmod/lib/ata_piix.ko

Echo Waiting for driver initialization.

Stabilized -- hash -- interval 250/proc/scsi

Echo "Loading mptbase. ko module"

Insmod/lib/mptbase. ko

Echo "Loading mptscsih. ko module"

Insmod/lib/mptscsih. ko

Mkblkdevs

Resume LABEL = SWAP-hda3

Echo Creating root device.

Mkrootdev-t ext3-o defaults, ro hda2

Echo Mounting root filesystem.

Mount/sysroot

Echo Setting up other filesystems.

Setuproot

Echo Switching to new root and running init.

Switchroot
Related Article

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.