2. The principle of the root file system

The following content originates from Zhu Youpeng's study of embedded courses. If there is any infringement, please inform and delete it.


1. The essence of linuxrc

1. /linuxrc is an executable application

(1) /linuxrc is the application layer and has nothing to do with the kernel source code;

(2) /linuxrc is executable under the current kernel system of the development board.

  • Under the linux system of ARM SoC, then this program is compiled and linked with arm-linux-gcc;
  • If it is under the PC linux system, then the program is compiled and linked with gcc.

(3) If /linuxrc is statically compiled and linked, it can be run directly; if it is dynamically compiled and linked, the necessary library files must be provided to run.

  • But in fact /linuxrc is directly called and executed by the kernel, so the user has no chance to export the path of the library file, so /linuxrc cannot be dynamically linked, and is generally statically linked .

2. Bring out the user interface when /linuxrc is executed

(1) The user interface is brought out by /linuxrc.

(2) The application is executed directly or indirectly by the /linuxrc call.

  • User interface programs and other applications are processes 2, 3, 4...
  • Process 1 (the init process, or /linuxrc) is the ancestor of all other application processes .

3. /linuxrc is responsible for the configuration after system startup

(1) After the operating system is started, it cannot be used directly and needs to be configured;

(2) The configuration of the application layer after the operating system starts (generally called runtime configuration, English abbreviation etc ) is to make our operating system more convenient and practical.

4. /linuxrc is usually busybox in embedded linux

(1) busybox is a project written in C language, which contains many .c files and .h files.

  • This project can be configured and compiled into applications that can run on various platforms.
  • If you compile busybox with arm-linux-gcc, you will get an application that can run on the linux kernel of our development board.

(2) busybox is developed to build rootfs in an embedded environment, that is, it is a specially developed init process application.

(3) busybox also provides a complete set of shell command assemblies for the current system.

  • For example vi, cd, mkdir, ls, etc. In desktop linux distributions (such as ubuntu, redhat, centOS, etc.) vi, cd, ls, etc. are all separate applications.
  • But in embedded linux, in order to save trouble, all common shell commands such as vi and cd are gathered together to form a shell command package, named busybox.


2. What are the directories in rootfs?

1. The most important thing is /linuxrc

2. Device files in the dev directory

  • In linux, everything is a file, so a hardware device is also virtualized into a device file to access. In the linux system /dev/xxx represents a hardware device. When we want to operate the hardware, we open the device file, and then read/write/ioctl operates on this device, and finally close closes the device.
  • The /dev directory is also indispensable in the minimum rootfs, and there are one or two device files that are necessary for the rootfs.

3. sys and proc directories

  • It is also indispensable in the minimum rootfs, but these two only need to create an empty folder, there is nothing in it, and there is no need for anything. These two directories are also related to drivers. It belongs to the virtual file system in linux.

4、usr

  • It is the storage place for some files owned by the user of the system. This thing will be automatically generated when busybox is installed in the future.

5. etc directory

  • It is a very critical and important one. All files in the directory are runtime configuration files.
  • All configuration files in the /etc directory will be called directly or indirectly by /linuxrc to complete the runtime configuration of the operating system.
  • The /etc directory is the key to making rootfs.

6. lib directory

  • A very critical one in rootfs, one that cannot be omitted. The lib directory contains the dynamic and static link library files in the current operating system. We are mainly for the dynamic link library in it.

3. Introduction to VFS

1. What is VFS?

VFS是linux内核的一种设计理念、设计机制。VFS就是vitrual file system,叫虚拟文件系统

  • 具体的一些文件系统如FAT、NTFS、ext2、ext3、jffs2、yaffs2、ubi等,它们的设计目的是为了管理块设备。
  • VFS借鉴文件系统的设计理念,将硬件设备的访问转化成对目录+文件的访问
  • 因此有了VFS之后,可以通过设备文件(目录+文件名,譬如/dev/mmcblk0p2)的方式来访问系统中的硬件设备。

2、VFS的意义

(1)将对硬件设备的访问和对普通文件的访问给接口统一化了(linux中一切届是文件)。

(2)将操作系统上层(应用层)对下层不同文件系统类型的访问细节给屏蔽掉了。


  • 如果没有VFS,写cp命令(其他命令也一样)时,需要考虑cp的这个文件在什么文件系统类型下,因此cp命令非常复杂。
  • 而VFS成了一个隔离层,隔离了下层的不同文件系统的差异性,对上层应用提供一个统一的接口。

(3)VFS将不同文件系统和下层硬件设备(块设备)驱动之间的细节也给屏蔽了。

  • 不同类型的文件系统在本身设计时,不用考虑各种不同的硬件设备的具体操作差异,这里有一个类似于VFS的设计理念。

3、VFS和我们学习的关系

(1)VFS机制和rootfs挂载,和其他文件系统的挂载都是有关联的。

(2)内核中有一些sys proc这种虚拟文件系统,这东西也是和VFS机制有关。

(3)/dev/目录下的设备文件都和VFS有关,所以学习驱动绕不开VFS

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325857623&siteId=291194637