

The root filesystem is the first one that must be mounted during Linux startup; if the system cannot mount the root filesystem from the specified device, it will fail to start.Other filesystems can then be mounted automatically or manually.
Therefore, different filesystems can coexist within a system.Different types of filesystems have different characteristics, thus they are applied based on the hardware features of storage devices and system requirements.
In embedded Linux applications, the main storage devices are RAM (DRAM, SDRAM) and ROM (commonly using FLASH memory). Common filesystem types based on storage devices include: jffs2, yaffs, cramfs, romfs, ramdisk, ramfs/tmpfs, etc.
1. Flash-Based Filesystems
Flash memory, as the main storage medium in embedded systems, has its own characteristics. The write operation to Flash can only change a 1 to a 0 at the corresponding location, and it cannot change a 0 back to a 1 (erasing Flash restores the content of the corresponding storage block to 1).
Thus, generally, when writing content to Flash, the corresponding storage area needs to be erased first, and this erasure is done in blocks.
Flash primarily comes in NOR and NAND technologies. The number of erase/write cycles for Flash memory is limited, and NAND Flash has special hardware interfaces and read/write timing.
Therefore, filesystems must be designed to meet application requirements based on the hardware characteristics of Flash; traditional filesystems like ext2 have many drawbacks when used as Flash filesystems.
A Flash chip can be divided into multiple partitions, each of which can use different filesystems; two Flash chips can also be combined into one partition using a single filesystem. That is, filesystems are defined in terms of memory partitions, not storage chips.
In embedded Linux, MTD (Memory Technology Device) provides a unified abstract interface between the underlying hardware (Flash) and the upper layer (filesystem), meaning that Flash filesystems are based on the MTD driver layer (refer to the filesystem structure diagram under Linux above).
The main advantage of using the MTD driver is that it is specifically designed for various non-volatile memory (primarily Flash), thus it has better support, management, and sector-based erase, read/write operation interfaces for Flash.
The JFFS filesystem was originally developed by the Swedish company Axis Communications based on the Linux 2.0 kernel for embedded systems.
JFFS2 is a flash filesystem developed by RedHat based on JFFS, initially designed for RedHat’s embedded product eCos, so JFFS2 can also be used in Linux and uCLinux.
Jffs2: Journaling Flash FileSystem version 2
Mainly used for NOR type Flash, based on the MTD driver layer, it is characterized by being readable and writable, supporting data compression, being a log-structured filesystem based on hash tables, and providing crash/power failure safety protection, along with “write balancing” support.
The main drawback is that when the filesystem is full or nearly full, the speed of jffs2 significantly slows down due to garbage collection.
JFFS is not suitable for NAND Flash primarily because NAND Flash generally has a larger capacity, which leads to rapid increases in memory space occupied by maintaining log nodes.
Additionally, the jffs filesystem requires scanning the entire FLASH content during mounting to find all log nodes and establish the file structure, which can take a lot of time for large capacity NAND Flash.
(2) yaffs: Yet Another Flash File System
yaffs/yaffs2 is a log-structured filesystem designed specifically for embedded systems using NAND Flash. Compared to jffs2, it reduces some functions (e.g., it does not support data compression), resulting in faster speeds and shorter mounting times, with lower memory usage.
Moreover, it is a cross-platform filesystem, supporting not only Linux and eCos but also WinCE, pSOS, and ThreadX.
yaffs/yaffs2 comes with drivers for NAND chips and provides direct access APIs for the filesystem, allowing users to operate on the filesystem directly without using MTD and VFS in Linux.
Of course, yaffs can also work with MTD drivers.
The main difference between yaffs and yaffs2 is that the former only supports small page (512 Bytes) NAND Flash, while the latter supports large page (2KB) NAND Flash.
At the same time, yaffs2 has significantly improved memory space usage, garbage collection speed, read/write speed, etc.
(3) Cramfs: Compressed ROM File System
Cramfs is a read-only compressed filesystem developed with the involvement of Linux founder Linus Torvalds. It is also based on the MTD driver.
In the cramfs filesystem, each page (4KB) is compressed individually, allowing for random page access, with a compression ratio of up to 2:1, saving a significant amount of Flash storage space for embedded systems, enabling the system to store the same files using lower capacity FLASH, thereby reducing system costs.
The cramfs filesystem stores data in a compressed manner and decompresses it at runtime, so it does not support applications running in XIP (Execute In Place) mode; all applications must be copied to RAM to run. However, this does not mean it requires more RAM space than Ramfs, as cramfs uses a paging compression method to store files, allocating memory only for the parts currently being read, and not allocating memory for parts not yet read. When files are not in memory, the cramfs filesystem automatically calculates the location of the compressed data and decompresses it into RAM on demand.
Additionally, it is fast and efficient, and its read-only characteristic helps protect the filesystem from corruption, enhancing system reliability.
Due to these features, cramfs is widely used in embedded systems.
However, its read-only attribute is also a significant drawback, preventing users from expanding its contents.
Cramfs images are usually placed in Flash but can also be placed in other filesystems, and can be mounted in other filesystems using loopback devices.
The traditional Romfs filesystem is a simple, compact, read-only filesystem that does not support dynamic erase and save, storing data sequentially, thus supporting applications running in XIP (Execute In Place) mode, saving RAM space during system operation. The uClinux system typically uses the Romfs filesystem.
Other filesystems: fat/fat32 can also be used for the extended storage of actual embedded systems (such as SD cards for PDAs, Smartphones, digital cameras, etc.), primarily for better compatibility with the most popular Windows desktop operating systems.
ext2 can also be used as a filesystem for embedded Linux, but using it for FLASH has many drawbacks.
Ramdisk uses a fixed size portion of memory as a partition. It is not an actual filesystem but a mechanism to load an actual filesystem into memory, and can be used as the root filesystem.
By placing some frequently accessed and unchanging files (such as a read-only root filesystem) in memory via Ramdisk, the system’s performance can be significantly improved.
During the Linux startup phase, initrd provides a mechanism to load the kernel image and root filesystem into memory.
Ramfs is a memory-based filesystem developed by Linus Torvalds, operating at the virtual filesystem (VFS) layer, cannot be formatted, and can create multiple instances, specifying its maximum memory usage at creation.
(In fact, VFS can essentially be seen as a memory filesystem that unifies the representation of files in the kernel and buffers disk filesystems.)
Ramfs/tmpfs filesystems store all files in RAM, so read/write operations occur in RAM, and can be used to store temporary or frequently modified data, such as in /tmp and /var directories, thus avoiding read/write wear on Flash memory while improving data read/write speed.
The main difference between Ramfs/tmpfs and traditional Ramdisk is that it cannot be formatted, and the filesystem size can change based on the content size.
A disadvantage of tmpfs is that it loses all data when the system reboots.
3. Network File System NFS
(Network File System)
NFS is a technology developed by Sun for sharing files over a network between different machines and operating systems.
During the development and debugging phase of embedded Linux systems, this technology can be used to establish a root filesystem based on NFS on the host and mount it to the embedded device, allowing for easy modification of the root filesystem contents.
All the discussed filesystems are based on storage devices (memory-based file systems) and can serve as the root filesystem for Linux.
In fact, Linux also supports logical or pseudo filesystems (logical or pseudo file systems), such as procfs (proc filesystem), used for obtaining system information, as well as devfs (device filesystem) and sysfs, used for maintaining device files.
New Class Open for Three Networks!
The latest session of Red Hat Certified RHCE course will start on March 6! This new class is a Saturday-only class. For more course details, feel free to consult the course instructors at Three Networks~
– END –
Professional • Strength • Integrity • Value
WeChat ID:sannet-edu
Official Website:www.sannet.net
Consultation Hotline:0512-82289966
Address: Room 433, Heji Plaza, No. 666, Ganjiang East Road, Suzhou