The Linux file system is a component of the Linux operating system that is responsible for organizing, storing, and managing the data in a structured and efficient manner. Unlike Windows OS, Linux uses the root directory (/), where everything, files, directories, hardware devices, and even running processes, are treated as a file. In this blog, we will discuss the Linux file system with its architecture and types in detail.
What is the Linux File System?
The Linux file system is a hierarchical structure that organizes and stores files and directories on a Linux OS. Unlike Windows, Linux OS follows a tree-like structure, which is present at the core (root) and is denoted by /. From the root directory, all other directories are handled by the Linux OS. This type of structure ensures that all the files and directories are maintained in a structured way, making it easier to locate and manage them. Everything in Linux, files, folders, hardware devices, or even running processes, is treated as a file. So, your keyboard, hard disk, and even RAM have entries that look like files only.
Let us understand it with the help of an example. Imagine your computer as a big house. Inside the house, you have rooms (directories), and in each room, you keep different types of items (files).
Characteristics of the Linux File System
Below are the characteristics of the Linux file system.
- Hierarchical Directory Structure: Linux organizes the files in a tree-like structure, starting from the root directory.
- Everything Is a File: In Linux OS, everything is treated as a file, whether it is a regular document, a device, a process, or a network.
- Case Sensitive: The files in Linux are case sensitive, i.e., file.txt, File.txt, and FILE.txt are three different files.
- Permission-Based Security: Every file or folder in Linux has permissions, which allow access to the resources through a valid user.
- Inode-Based Architecture: Each file in a Linux system has a unique code called an Inode, which defines the information of
- File type and permissions
- Owner, group, and timestamps
- File size and data location on disk
- Multiple File System Support: Linux can work with multiple file system formats, like ext2, ext3, ext4, FAT32, exFAT, and many more.
- Support for Long File Names: The file names in Linux can have a maximum length of 255 characters, and also with any character in file names, except / (used for directories) and null characters.
- Virtual File Systems: Linux OS provides /proc and /sys, which are virtual directories that do not store data on disk but provide live system information.
Master DevOps Today - Accelerate Your Future
Enroll Now and Transform Your Future
Architecture of Linux File System
The Linux file system is designed in multiple layers, each with a specific role. The architecture mainly has three layers as below.
1. Logical File System (LFS)
The logical file system is the top layer of the Linux Architecture that directly interacts with the user applications, like text editors, browsers, or commands such as cat, ls, etc. It handles all the logical operations, i.e., files are organized, named, protected, and accessed, not how they are stored physically. It is responsible for
- Managing file names and directories
- Handling permissions and ownership
- Managing metadata, like file size, creation date, etc.
For the below-mentioned command.
cat /home/akshat/notes.txt
The Logical File System first checks if there is a file named notes.txt is present inside /home/akshat. Then it checks whether you have permission to read the file, and if the permission is granted, it asks the next layer to fetch the actual data from the disk.
2. Virtual File System (VFS)
The VFS acts as a bridge between the logical and physical layers. It provides a common interface between multiple types of file systems, like ext4, NTFS, etc, so that the user applications can access any of them without knowing their differences. It is responsible for
- Providing a standard API for all file systems
- Handling mounting and unmounting of different file systems
- Translating system calls (like open(), read(), write()) into file-system-specific operations
For the below-mentioned command.
cat /home/akshat/notes.txt
The LFS asks VFS to fetch this file. Then the VFS figures out which physical file system stores notes.txt (say, ext4) and translates the request into operations that the ext4 file system can handle to retrieve the actual data.
3. Physical File System (PFS)
The Physical File System is the bottom layer of the Linux File System Architecture, which directly interacts with the hardware (disk drives, SSDs, flash storage, etc.). It handles the actual storage and retrieval of data blocks on the disk and is responsible for
- Managing disk blocks and partitions
- Storing data in physical sectors of the disk
- Using device drivers to communicate with the hardware
For the below-mentioned command.
cat /home/akshat/notes.txt
After the Logical File System and VFS have processed your request, the PFS goes to the disk and fetches the actual data blocks of notes.txt from the storage device.
File Permissions and Ownership
Linux is a multi-user operating system, and every file and directory has permissions associated with it that determine who can read, write, or execute it. These permissions control how users can interact with the files and directories, as per the rules that are enforced on them by the Linux kernel.
There are the following types of permissions in Linux:
1. r (Read): The file or directory having the read permission can only view the file contents or list the directory contents.
2. w (Write): The file or directory having the write permission can modify the files or create or delete the items in a directory.
3. x (Execute): The file or directory having this type of permission can run the file as a program or enter a directory.
Important Terms in Linux Filesystems
Before discussing the file systems in Linux, let us first understand some important concepts.
1. Journaling
Journaling is the process by which the file system keeps a record (journal or log) of what the system plans to do before it actually performs it. It helps the system recover the data quickly after a crash or power failure has occurred while performing a task. For example, imagine you are doing important work on your computer, and suddenly the power goes off. After that, when you restart your computer, you might lose the last few lines, or the whole file might get corrupted because the system was not able to complete writing the changes to the disk. To prevent this kind of data loss, Linux uses a technique called “Journaling.”
2. Versioning
Versioning means that instead of keeping one version of the file, we are keeping multiple versions of it. Every time you make a change or save a file, the system can keep a record of that version, so you can go back to an older version when required. It is needed because, even if you make a mistake or accidentally delete something, it will not be gone forever, as you can go back to an earlier version of your file, compare the differences between the two versions, and recover the files that are lost.
Linux file systems themselves (like ext4 or XFS) do not have built-in versioning by default. However, it can be implemented at the software or snapshot level by:
- Application-Level Versioning
- File System-Level Versioning
- Manual Versioning by Naming Convention
3. Inode
An inode is a data structure that contains the following information
- File type
- Permissions
- Owner permissions
- Time stamps
- Pointer to data block, and many more.
In Linux, every file and directory is represented by an inode. You can think of an inode as an identity card for every file; it stores all the metadata, but not the actual file data or name. Inodes store the pointers (addresses) to the data blocks on the disk where the data of the file is present. An inode has 15 black pointers as follows:
- 1 triple indirect pointer that points three levels deep.
- 12 direct pointers, which point directly to a data block.
- 1 single indirect pointer that points to a block that contains addresses of the blocks that themselves point to data blocks.
- 1 double indirect pointer that points to a block containing addresses of blocks that themselves point to data blocks.
4. Mounting
In Linux, mounting is a process of making a storage device, like a USB or a hard drive, accessible to the system by attaching it to a specific point in the directory tree. This point is called a mount point, and it is usually an empty directory. The contents of the device will appear here once it is mounted. When you mount a device, Linux connects the file system present on that device to the overall directory structure of the device, which starts from the root directory (/). For example, if you mount a USB drive at /media/usb, then all files stored on the USB drive can be accessed from that location.
5. Unmounting
Unmounting is the process of detaching the mounted file system from the Linux directory structure. When a file system is unmounted, it is disconnected from the mount point, and the OS ensures that any pending read or write operations are completed. If you remove the storage device without unmounting,
- You may lose files or get incomplete data saved.
- Some data might still be in OS memory or cache and not yet written to disk.
- File system corruption may occur, which can make the disk unreadable.
Key Linux File Systems
Linux supports multiple types of file systems, each designed for different needs, storage devices, and performance requirements. Below are some of them.
1. ext (Extended File System)
ext was the first extended file system used in Linux and was developed to improve the older Minix file system. It introduced the ability to have longer filenames, better file management, and larger storage support. Ext was replaced by ext2, which eventually led to ext3 and ext4.
2. ext2
ext2 is a classic Linux file system that became the standard for many years.
3. Xiafs (Extended XIA File System)
Xiafs was developed as a replacement for ext, which tried to fix the limitations of ext and ext2. It provided better disk space management and improved performance. It was soon replaced with ext2 because ext2 was more stable and widely used as compared to Xiafs.
4. ext3 (Third Extended File System)
ext3 is essentially ext2 with journaling. It is fully backward compatible with ext2, hence you can upgrade a disk from ext2 to ext3 without losing data. It is commonly used in older Linux distributions where stability was prioritized over speed.
5. JFS (Journaled File System)
JFS is a high-performance journaling file system, and it was developed by IBM. It is designed to handle large files efficiently and also provides fast recovery of data after any crash occurs. It uses very little CPU resource, due to which it is widely used for servers.
6. ReiserFS
ReiserFS was one of the first Linux file systems mainly designed for storing many small files efficiently by using a tree-based structure for faster lookup and storage. It supports journaling, which makes it safer compared to ext2. It was popular in the early 2000s for desktop Linux, but it declined after Reiser4 development slowed.
7. XFS
XFS is a high-performance 64-bit journaling file system and was developed by Silicon Graphics. It is mainly designed for storing very large files, due to which it is ideal for enterprise storage, multimedia servers, and databases. It has features like fast recovery, scalable storage allocation, and high-performance I/O operations, and is commonly used in modern Linux distributions like CentOS and RHEL.
8. SquashFS
SquashFS is a compressed, read-only file system, and is mainly used in Live CDs, embedded systems, or Linux distributions where saving space is critical. The files are compressed, due to which allows you can store more data in less space. Since it is read-only, files cannot be modified directly on SquashFS.
9. Reiser4
Reiser4 is the updated version or next generation of ReiserFS, which provides better performance, advanced features, and support for very large files and directories. However, it hasn’t seen wide adoption due to development challenges and licensing issues.
10. ext4
ext4 is the most widely used Linux file system today. It addresses the disadvantages of ext3 by supporting larger files, utilizing contiguous blocks for faster access, and enabling faster file system checks. Nowadays, most modern Linux distributions, including Ubuntu, Fedora, and Debian, use ext4 as the default file system.
11. btrfs (Better/B-tree FS)
btrfs is the modern file system that mainly aims at data integrity. It is ideal for servers, backup systems, and environments where data reliability is critical. It supports snapshots, checksums for data, compression, and pooling of storage devices.
12. bcachefs
bcachefs is a modern Linux file system that is mainly designed for performance and reliability. It combines the speed of SSD caching with the data integrity of traditional file systems. It also supports copy-on-write, snapshots, compression, and checksums, which makes it similar to Btrfs but faster in many cases.
13. Other Linux File Systems
Apart from the ones above, Linux supports many specialized file systems:
- FAT32 / exFAT
- NTFS
- ISO 9660
- tmpfs
- ZFS
Get 100% Hike!
Master Most in Demand Skills Now!
| Parameters |
ext |
ext2 |
Xiafs |
ext3 |
JFS |
ReiserFS |
XFS |
SquashFS |
Reiser4 |
ext4 |
btrfs |
bcachefs |
| Max. filename length (bytes) | 255 | 255 | 248 | 255 | 255 | 4032 | 255 | 255 | 255 | 255 | 255 | 255 |
| Allowable characters in directory entries | Any byte except NUL | Any byte except NUL, / | Any byte except NUL | Any byte except NUL or / | Any Unicode except NUL | Any byte except NUL or / | Any byte except NUL | Any byte except NUL | Any byte except NUL, / | Any byte except NUL, / | Any byte except NUL, / | Any byte except NUL, / |
| Max. pathname length | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined | Undefined |
| Max. file size | 2 GB | 16GB – 2TB | 64MB | 16GB – 2TB | 4PB | 8TB | 8EB | – | 8TB (x86) | 16TB | 16EB | 16EB |
| Max. volume size | 2 GB | 2TB – 32TB | 2GB | 2TB – 32TB | 32PB | 16TB | 8EB | – | – | 1EB | 16EB | 16EB |
| Max. number of files | – | – | – | – | – | – | – | – | – | 2^32 | 2^64 | 2^64 |
| Metadata-only journaling | No | No | No | Yes | Yes | Yes | Yes | No | No | Yes | No | No |
| Compression | No | No | No | No | No | No | No | Yes | No | No | Yes | No |
| Block sub-allocation | No | No | No | No | Yes | Yes | No | No | Yes | No | Yes | Yes |
| Online grow | No | No | – | Yes | No | Yes | Yes | No | Yes | Yes | Yes | Yes |
| Encryption | No | No | No | No | No | No | No | No | Yes | Yes (experimental) | No | No |
| Checksum | No | No | No | No | No | No | Partial | No | No | Partial | Yes | Yes |
Special Files and Virtual Filesystems
In Linux, everything, i.e., hardware devices like keyboards, hard drives, etc, is treated as a file. Special files are the files that represent hardware devices instead of normal stored data. These files are usually found in the new /dev directory (short for “devices”). These files allow Linux programs to communicate with hardware using simple read and write operations.
Some of the special files are as follows.
1. Character Special Files: Character special files represent the devices that handle data one character at a time. They allow input or output to happen in a continuous stream, like typing on a keyboard or sending data to a printer.
2. Block Special Files: These files represent the devices that store the data in blocks, like hard drives, SSDs, or USB drives. They allow the system to read and write data in fixed-size blocks for faster access.
3. FIFO (Named Pipes): It allows the processes to communicate with each other by sending data through a pipe. When one process writes to the FIFO, another process can read from it in the same order.
4. Socket Files: These are the special files that are used for network communication or for the communication between local processes. They allow the programs to exchange data directly, even over the network.
The Linux Directory Structure
The Linux directory structure is like a well-organized library, where every file and folder has a specific place, which makes it easier to locate, manage, and maintain files.
- /: It is the root directory, which is the starting point of the file system. All other directories, files, and devices are located under this root directory.
- /bin: it is the essential user binaries that contain essential command-line programs like ls, cat, cp, mv, and bash. These commands are required for the system to boot and run in single-user mode.
- /root: This is the home directory for the root user, which is separate from the normal home directories of the user. Only the superuser (root) has complete access here.
- /boot: It is the boot loader file that contains kernel files, the bootloader, and the initial RAM disk. It is used to start the system.
- /dev: these are the device files that contain special files that represent devices like hard drives, USB drives, and printers. It is like a hardware control panel, allowing the system and users to interact with devices.
- /etc: It is the configuration files that store system-wide configuration files. For example, passwd, fstab, network, etc.
- /home: It is the user home directory for users, and each user can store documents, downloads, and personal files here. It contains personal directories for users, e.g., /home/akshat.
- /lib: It contains the shared libraries and kernel modules required by programs in /bin and /sbin.
- /opt: These are the optional software that contains third-party applications or optional software.
- /proc: It is a virtual file that provides information about the kernel and processes running on the system.
- /sys: It stands for system information and allows interaction with the kernel and hardware. It is another virtual filesystem used for device and kernel info.
- /tmp: These are temporary files that are created by applications and the system. These files in /tmp are usually deleted on reboot.
- /usr: it is the user programs and data, and contains applications, utilities, and documentation. It has further subdirectories like /usr/bin, /usr/lib, /usr/share, etc.
- /var: It is the variable data files that store data that changes frequently, like logs, mail, databases, or print queues.
- /run: It was introduced in 2010 as a new addition to the Linux directory structure, and is used to store runtime data, meaning information that is valid only while the system is running.
- /srv: It contains the data used for services provided by the system, like web servers (/srv/www) or FTP servers.
ext4 in Linux
ext4 is a modern Linux file system designed to improve the performance, scalability, and reliability of the system as compared to ext3 and ext2. It is present in most of the Linux distributions today.
- ext4 is fully backward compatible with its predecessor, ext3 and ext2, i.e., you do not have to reformat your old ext3 or ext2 partitions to start with new ext4 features.
- Traditionally, ext2 and ext3 used to store the files in small blocks, which could become fragmented. Nowadays, ext4 uses extents, which means large files (like videos or databases) are stored in continuous sections of the disk. These contiguous blocks of storage reduce fragmentation during read and write operations of large files.
- It does not write the data until the data is actually written, which helps to reduce the fragmentation because the system can allocate larger contiguous blocks.
- It allows the programs to reserve disk space in advance to get continuous storage for large data, which plays an important role for media files.
- ext4 can now store the exact moment of the time when a file was modified or created. It stores the time in nanoseconds, as compared to ext3, which takes the time in seconds.
- It allows files to be automatically encrypted, i.e., you do not have to manually run the encryption or decryption command, and the filesystem handles it behind the scenes. When you save a file, ext4 encrypts it automatically before writing to disk, and when you read the file, ext4 decrypts it automatically for you.
While ext4 is a powerful and reliable file system, it does have some limitations also. One key limitation is that ext4 cannot automatically detect or repair the files that have already become corrupted on the disk. This means that if a file is damaged due to any hardware issues or other problems, ext4 does not have a built-in mechanism to recover it. Another limitation is that when you delete a file in ext4, the data may still remain in the journal of the file system. This means sensitive information can be recovered by someone with access to the disk
Which Linux File System Should You Use?
The Linux System depends on the needs and the kind of environment you are working in. For most users, ext4 is the best choice as it is fast, stable, and widely supported across most Linux distributions. If you are setting up a server or a backup system, where data integrity is important, you should use Btrfs. It supports many features like checksums, compression, and snapshots.
For enterprise environments or for the systems that are handling very large files, like databases, you should choose XFS, as it has good scalability and efficient I/O operations. Bcachefs has some similar features to Btrfs, and is emerging as a modern alternative.
Linux File System Limitations
Below are some common limitations of the Linux File System.
- When you create a filesystem, a fixed number of inodes are created; each inode represents one file. Once all inodes are used, you cannot create new files.
- Each filesystem has its own limit on how large an entire partition it can have. For example, ext4 can have a max size of 16TB and a max partition size of 1EB.
- There is also a limit on how long a file or folder name can be; for example, the maximum file name can be 255 characters
- Linux handles fragmentation better than Windows, but when a disk gets full or the files are frequently deleted and rewritten, fragmentation can slow down your system a bit.
- File systems like trfs and xfs use a lot of extra information to use features like snapshots, checksums, and error detection, due to which they use more memory and CPU resources than simpler systems
- ems like ext4.
Practical Tips for Managing the Linux Filesystem
Below are some practical tips to efficiently manage the Linux file system.
- With time, the Linux system accumulates a lot of files, in the form of logs, temporary data, downloads, updates, and cache files. These files can fill up your storage and slow down your computer. Hence, you should regularly check how much disk space is being used.
- When you connect a new drive to your Linux system, Linux does not automatically use it for mounting; you have to mount it on your own.
- Whenever possible, use a journaling file system, which keeps track of all operations before actually making changes. If your system turns off suddenly, the journal will help you restore the files easily and prevent corruption.
- Every file and directory has permissions that control who can read, write, or execute it. Set the permissions according to the needs so that the right permissions prevent unauthorized users or programs from modifying important files.
When your disk becomes 100% full, Linux may not function properly, and some applications might crash. Hence, always keep at least 10–20% of free space available.
Unlock Your Future in Linux
Start Your Linux Journey Today
Conclusion
From the above article, we learned that the Linux file system is robust, flexible, and has a hierarchical structure that efficiently manages files and directories. It has a layered structure comprising three layers: LFS, VFS, and PFS. It also supports multiple file systems like ext2, ext3, XFS, btrfs, and many more. Modern file systems like ext4 provide high performance, scalability, and encryption, which makes Linux a reliable choice for desktops, servers, and enterprise environments. Overall, the Linux file system is efficient, stable, and flexible for users and administrators to manage data effectively across diverse computing environments.
Useful Resources:
Linux File System – FAQs
Q1. What is the Linux file system?
It is a hierarchical structure that organizes and stores files, directories, and devices in Linux.
Q2. Which file system is commonly used in Linux?
ext4 is the most commonly used file system in modern Linux distributions.
Q3. What is the latest file system in Linux?
btrfs and bcachefs are among the latest Linux file systems offering advanced features like snapshots and checksums.
Q4. What are the types of file systems in Linux?
Linux supports ext2, ext3, ext4, XFS, JFS, ReiserFS, btrfs, SquashFS, bcachefs, and others.
Q5. How does the Linux file system work?
It uses a layered architecture (LFS, VFS, PFS) to manage, access, and store files efficiently on storage devices.
Q6. What is an inode in Linux?
An inode is a data structure that stores metadata about a file, like permissions, ownership, timestamps, and pointers to data blocks.