Linux File System

Linux-file-system.jpg

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
quiz-icon

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.

The Architecture of a File System

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.

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.

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)2552552482552554032255255255255255255
Allowable characters in directory entriesAny byte except NULAny byte except NUL, /Any byte except NULAny byte except NUL or /Any Unicode except NULAny byte except NUL or /Any byte except NULAny byte except NULAny byte except NUL, /Any byte except NUL, /Any byte except NUL, /Any byte except NUL, /
Max. pathname lengthUndefinedUndefinedUndefinedUndefinedUndefinedUndefinedUndefinedUndefinedUndefinedUndefinedUndefinedUndefined
Max. file size2 GB16GB – 2TB64MB16GB – 2TB4PB8TB8EB8TB (x86)16TB16EB16EB
Max. volume size2 GB2TB – 32TB2GB2TB – 32TB32PB16TB8EB1EB16EB16EB
Max. number of files2^322^642^64
Metadata-only journalingNoNoNoYesYesYesYesNoNoYesNoNo
CompressionNoNoNoNoNoNoNoYesNoNoYesNo
Block sub-allocationNoNoNoNoYesYesNoNoYesNoYesYes
Online growNoNoYesNoYesYesNoYesYesYesYes
EncryptionNoNoNoNoNoNoNoNoYesYes (experimental)NoNo
ChecksumNoNoNoNoNoNoPartialNoNoPartialYesYes

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

Unlock Your Future in Linux
Start Your Linux Journey Today
quiz-icon

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.

About the Author

Technical Content Lead | Software Developer

Anisha is an experienced Software Developer and Technical Content Lead with over 6.5 years of expertise in Full Stack Development. She excels at crafting clear, accurate, and engaging content that translates complex technical concepts into practical insights. With a strong passion for technology and education, Anisha writes on a wide range of IT topics, empowering learners and professionals to stay ahead in today’s fast-evolving digital landscape.

fullstack