Linux file system initialization process (1) --- overview

Glossary:

struct task: process

struct mnt_namespace: namespace

struct mount: mount point

struct vfsmount: mount item

struct file: file

struct super_block: super block

struct dentry: directory

struct inode: index node

 

First, the purpose

    The linux file system is mainly divided into three parts: the file system call; the virtual file system (VFS); the actual file system mounted to the VFS.

    Among them, VFS is the core, and the essence of the linux file system is to create a VFS tree in memory. After the root directory is created, users can use system calls to create files, delete files, and mount various file systems on the VFS.

    This series of articles mainly analyzes the linux3.10 file system initialization process, which is divided into three stages:

    1. Mount the root file system (rootfs);

    2. Load initrd;

    3. Mount the disk file system;

 

Two, commonly used data structure

    Important data structures in the linux file system are: files, mount points, super blocks, directory entries, index nodes, etc. For the specific implementation of each data structure, please refer to the source code, which will not be described here.

    In order to visually show the relationship between the data structures, please refer to Figure 1: The figure contains two file systems (red and green), and the green file system is mounted in the red file system tmp directory. Generally speaking, each file system at the VFS layer is composed of mount points, super blocks, directories and index nodes; when a file system is mounted, it is actually the process of creating these four data structures, so these four The status of the data structure is very important, and the relationship is very close. Since VFS requires the actual file system to provide the above data structure, different file systems can access each other at the VFS layer.

    If a process opens a file, it will also create a file (file) data structure, so that the process can access the VFS file system through file.

    In addition, the figure only shows the main relationship structure, ignoring some details.

                               figure 1

 

Three, function call relationship

    Figure 2 describes the main function call relationships in the file system initialization process. The linux file system initialization process is mainly divided into three stages:

    1. vfs_caches_init() is responsible for mounting the rootfs file system and creating the first mount point directory:'/';

    2. rest_init() is responsible for loading the initrd file, expanding the VFS tree, and creating a basic file system directory topology;

    3. The init program is responsible for mounting the disk file system and switching the root directory of the file system from rootfs to the disk file system;

                   figure 2

 

Four, summary

    The linux file system initialization process is mainly divided into three stages: mount rootfs and provide the first mount point "/; load initrd to expand the VFS tree; execute the init program to complete the initialization of the linux system. The main content of each stage will be described in detail below.

 

Guess you like

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