first, the purpose
After the kernel has loaded the initrd file, the necessary preparations are made for mounting the disk file system, including mounting the Sysfs,proc file system, loading the disk driver driver, and so on. Next, the kernel jumps to the INIT program of the user space, which is done by init to create the disk device files, load the disk file system, switch from Rootfs to the disk root file system, and so on.
Since Init is implemented differently in different Linux distributions andcannot be parsed for all distributions, this article chooses the ubuntu12.04 release to describe how to switch from Rootfs to the disk root filesystem.
ii. Creating disk device Files
The INIT program uses udev tools to dynamically create disk device files. Udev works by creating the appropriate device files in the/dev directory based on the device information in the SYSFS, so the Sysfs file system needs to be prepared in advance.
First, create the necessary mount point directories,/ Dev,/root,/sys,/proc, andso on, and then mount the Sysfs in the VFS to Rootfs's /sys directory and Tmpfs mounts to the /dev directory (the file system type of/dev is tmpfs), and finally, /dev/console,/dev/null Two special device files are created in order to output printing information.
Once these necessary information is ready, the udev daemon process can be started and the disk device files are dynamically created by udev based on Sysfs. Udev startup code is in Scripts/init-top/udev.
three, Mount disk file system
There are generally two ways to mount a disk file system: Local and network mode. Based on the value of the boot variable,Init chooses to perform a local load or a network load, execute a/scripts/local script if it is loaded locally, or execute a/SCRIPTS/NFS script if it is a network load . Personal PCs are typically loaded locally, and servers in the datacenter are typically NFS loaded.
Finally, the init program calls the /scripts/local script to mount the disk file system.
Iv. Switching the root file system
After successfully mounting the disk file system, you need to migrate the important directories such as/sys,/proc,/dev, etc. under Rootfsto the disk file system.
Finally, the root file system of the kernel is switched from Rootfs to the root of the disk file system by calling the/sbin/run-init program.
v. Final
VFS
View
At this point, the kernel file system initialization process is complete, and the final VFS view is given below (because the file system is too large, only the key topologies are given):
Vi. Summary
The main task of the INIT program is to load the disk file system, migrate the important directory under Rootfs to the disk file system, and finally switch the kernel root directory from rootfs to the root directory of the disk file system.
Linux File System-initialization (III)