Article Title: proficient in building initramfs stepbystep (2 ). 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.
4. What are rootfs and ramfs?
All linux kernels of version 2.6 have a special file system rootfs, which is the initial root file system started by the kernel. The init ramfs file will be copied to rootfs. If we compare init ramfs to a seed, rootfs is the soil where it grows. After most linux systems run normally, they will install other file systems and then ignore rootfs.
Rootfs is a special instance of the ramfs file system. Ramfs is a very simple file system and a memory-based file system. The ramfs file system has no capacity limit. It can dynamically increase the capacity as needed.
Ramfs directly utilizes the kernel's disk cache mechanism. The read and write data of all files will be cached in the memory. When the system uses the file data again, it can be read and written directly from the memory, to provide system I/O performance. Data written in the cache will be written back to the corresponding file system device (such as a disk) when appropriate, and its status will be marked as clean, in this way, the system can release the memory when necessary. Ramfs has no corresponding file system device, so its data will never be written back, and it will not be identified as clean. Therefore, the system will never release the memory occupied by ramfs.
Because ramfs directly uses the existing disk high-speed caching mechanism of the kernel, its implementation code is very small. Due to this reason, the ramfs feature cannot be deleted through Kernel configuration parameters. It is a natural feature of the kernel.
5. ramfs is not ramdisk
Ramdisk is a block device created in a memory area to store the file system. The ramdisk capacity is fixed and cannot grow dynamically like ramfs. Ramdisk requires the kernel's file system driver (such as ext2) to operate on its data, while ramfs is a natural feature of the kernel, without additional drivers. Like other file system devices, ramdisk needs to replicate data between Block devices and the disk cache in the memory, which is not necessary.
6. File System tmpfs derived from ramfs
One disadvantage of ramfs is that it may constantly grow until it consumes all of the system's memory, so only root or authorized users are allowed to use ramfs. To solve this problem, the tmpfs file system is derived from ramfs, which increases the capacity limit and allows data to be written into swap partitions. Because these two features are added, tmpfs allows common users to use them.
For more information about the tmpfs file system, see the Documentation/filesystems/tmpfs.txt file in the kernel source code.
To sum up, init ramfs is a ramfs file system. After the kernel is started, it is copied to rootfs as the initial root file system of the kernel, its task is to mount the real root file system of the system. This is the past and present of init ramfs.