Proficient in initramfs build stepbystep (12)

Source: Internet
Author: User
Article Title: proficient in building initramfs stepbystep (12 ). 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.

35. Test it.

Through the content in the first 11 sections, we can say that we have fully mastered the init ramfs construction method. Now let's test it and analyze it with an actual init ramfs, check whether we can understand it.

We chose Debian 4.0 AMD64 version of init ramfs as the target for analysis, its init ramfs file is initrd. img-2.6.18-6-amd64. First, use the cpio command to unbind the init ramfs file, and then open the init script file for detailed analysis. Now, let's start with the knowledge in the previous sections.

As a reminder, I Will repost an article from http://blog.chinaunix.net/u/12679/showart_429816.html:

Initrd execution sequence

This is a note during the installation process. I hope it will be useful to you here. Correct the error.

(The system is debian etch, taking the default initrd. img-2.6.18-5 after installation as an example)

Unbind the initrd file:

For example, if you have an initrd file/boot/initrd. img, run the file command to see that this is a gzip compressed file. You can use the following command to unbind it:

Code:

Mkdir/boot/myinit

Cd/boot/myinit

Zcat ../initrd. img | cpio-id (Note: The cramfs format is generated by default using the mkinitrd command. If the file format is a compressed ramfs file system, you can directly mount it and view: mount-t cramfs/boot/initrd. img/mnt /)

If the kernel is 2.6 and cpio compression is used, the method is as follows:

Cp/boot/initrd-***. img initrd.img.gz

Gunzip initrd.img.gz

Mkdir initrd

Mv initrd. img initrd

Cd initrd

Cpio-mdiv <initrd. img

There are some directories and files in the current directory. The file init is the script executed after initrd is loaded at startup.

Directory structure:

/Bin/: the files include busybox, mknod, sh, uname, cat, mount, and cmdt_root.

--------/Sbin/: the files include modprobe, depmod, udevd, and udevdtrigger.

--------/Lib/: the files include:

---------------- (1) dynamic library required for executable files

---------------- (2) modules/: kernel module

---------------- (3) udev/: executable file required by udev

--------/Lib64/: file: x86_64 program loader

--------/Etc/: configuration file related to modprobe and udev

--------/Conf/: There are the following files

---------------- (1) modules: lists the modules to be loaded.

---------------- (2) arch. conf: Set the variable DPKG_ARCH = amd64

---------------- (3) initramfs. conf: defines some variables.

--------/Scripts /:

---------------- There are the following files:

---------------- Functions: defines some convenient functions.

---------------- Local and nfs: scripts executed when the root directory is mounted. Generally, the local system is mounted and the local

---------------- There are the following directories where the scripts executed in each stage are placed:

---------------- Init_top/

---------------- Init_premount/

---------------- Init_bottom/

---------------- Local_top/

---------------- Local_premount/

---------------- Local_bottom/

--------/Init: script executed after initrd is loaded at startup

Generate the initrd file:

Find. | cpio-o -- dereference-H newc | gzip-9>.../initrd. img

Init file execution process:

-------- 1) Create the directory/dev,/root,/sys,/proc,/tmp,/var/lock, where/root is the location of the following root file system to be mounted

-------- 2) mount System proc and sys

-------- 3) execute the script/etc/udev. conf and only define the variable

-------- 4) mount udev device: mount-t tmpfs-o size = udev/dev

-------- 5) Create/dev/console,/dev/null,/dev/. initramfs

-------- 6) import the initramfs in the/conf directory. conf,/conf. d/directory and the variables and functions defined by/scripts/functions, and set the corresponding variables according to the passed kernel parameters. The important variables include:

---------------- A) rootdelay = <时间> The waiting time before loading the root file system. If the root file system is on the USB flash drive, you must add this parameter here or after the grub kernel, and then mount the root file system after the USB flash drive is found, otherwise, the root file system cannot be found.

---------------- B) panic = <时间> After the system panic, how long will it take to reboot. When you test a new kernel or new initrd, you can add this parameter when you often use panic instead of pressing the power-on button.

-------- 7) depmod-a in/lib/modules/ <内核版本号> /Directory to generate the modules. dep File

-------- 8) execute the script file in the init_top directory. There is only one framebuffer. It processes kernel parameters such as video =, vga =, and splash. In addition, it creates a node/dev/tty [0-8].

-------- 9) Use modprobe to load modules listed in/conf/modules in sequence. Note that udev requires a unix module; otherwise, an error occurs: udevd [606]: error initializing udev socket.

-------- 10) execute the script file under/scripts/init-premount.

------------- 10.1) file thermal: it loads the required modules based on the different values of DPKG_ARCH and the fan and thermal modules.

------------- 10.2) file udev: execute the following process:

------------------------ A) mkdir-p/dev/. udev/db

------------------------ B) udevd -- daemon starts udevd in the form of daemon, which is probably used to monitor Hot Plug Device plugging.

------------------------ C) mkdir-p/dev/. udev/queue/(I do not know the usage of these two mkdir)

------------------------ D) udevtrigger triggers the uevents of the coldplug device (that is, the device inserted before startup) for Kernel processing.

------------------------ E) udevsettle waits until the kernel uevents event is processed

-------- 11) run/scripts/local to mount the root file system:

---------------- 11.1) first execute the script in the local-top/directory.

------------------------ 11.1.1) file udev_helper:

-------------------------------- A) loads the ide_generic module for root file system devices (such as/dev/sda1,/dev/sda2) that do not exist. I can load the modules aic94xx and sd_mod if I cannot find the hard disk.

---------------- 11.2) if the root file system device does not exist, wait for a period of time (180 s by default). After this period, the root file system device cannot be found.

---------------- 11.3) obtain the type of the root file system: first check whether the parameter rootfstype = is passed. If not, run/bin/fstype, if you do not know the file system type, run/lib/udev/vol_id to obtain the file system type.

---------------- 11.4) execute the script under local-premount:

------------------------- 11.4.1) file resume: (not understanding)

---------------------------- A) process the passed resume parameter, which specifies a partition in the format of resume = LABEL =/dev/sda1 or resume = UUID = xxx for suspend to disk

---------------- 11.5) load the corresponding modules according to the file system type. For example, if the root file system is ext2, load ext2 (if not compiled into the kernel ).

---------------- 11.6) mount the root file system to/root

---------------- 11.7) execute the script under local-bottom/(there is no script here ).

-------- 12) run the init-bottom/script:

----------------- 12.1) file udev:

------------------------ A) kill udevd

------------------------ B) nuke/dev/. udev/queue/(I do not know what it means)

------------------------ C) run/etc/udev. conf to set the variable tmpfs_size = 10 M

------------------------ D) mkdir/dev/. static/dev (note that this directory is not created on the hard disk)

------------------------ E) mount-n-o bind/root/dev /. static/dev bind the node (on the hard disk) in the/dev directory of the real file system to/dev /. static/dev/

------------------------ F) mount-n-o move/dev/root/dev move the tmpfs-type udev to the/dev directory of the real file system, (Note that udev is mounted on/dev at the beginning). udev is mounted on/dev of the real file system, the original node in the/dev directory of the hard disk went to/dev /. in static/dev mode, there is no/dev/on the hard disk /. static directory. (This is not easy to understand)

------------------------ G) nuke/dev (unknown)

------------------------ H) ln-s/root/dev before mount-o move, nothing under the directory/dev, then/root has not really become the root. This step makes it impossible to find the device files in/dev/for other scripts.

-------- 13) mount-n-o move/sys/root/sys

-------- 14) mount-n-o move/proc/root/proc

-------- 15) exec run-init/root/sbin/init "$ @"/root/dev/console this step should be to make the real file system the root, and execute its/sbin/init (not understood)

Note: When loading aic94xx, read firmware data from the directory/usr/lib/hotplug/firmware or/lib/udev/firmware, therefore, create the directory usr/lib/hotplug/firmware or lib/udev/firmware (in the root directory of initrd, that is,/boot/myinit). Then, copy A aic94xx-seq.fw to any directory. It can be seen that if aic94xx is compiled into the kernel, firmware data should also be put into the kernel, but this function has not yet been implemented. See the end of the kernel Documentation/firmware_class/README.

 

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.