Enquire Now
Linux Opensource

The Linux file system is a structured way to store, organize, and access files on a computer. It starts with the root directory ("/"), which branches out to other folders, like /home for personal files or /bin for essential programs. Each folder has a specific purpose to keep files organized and secure, helping users and programs find what they need. For example, when you save a document in Linux, it might go to /home/username/Documents, making it easy to locate later.

The Linux file system has three main layers. The Logical File System interfaces with user applications, managing actions like opening and reading files. Above it, the Virtual File System allows multiple file systems to work together, creating a common interface for compatibility. Lastly, the Physical File System handles the actual storage of data on the disk, managing memory blocks for efficient access. Together, these layers organize and manage data in Linux.

/root

It is the top-level filesystem directory. It must include every file needed to boot the Linux system before another filesystem is mounted. Every other filesystem is mounted on a well-defined and standard mount point because of the root filesystem directories after the system is started.
 

/boot

Directory in Linux contains essential files needed for the system to boot, including the Linux kernel, initial RAM disk (initrd), and bootloader configuration files like GRUB. These files are critical for the startup process, as they load the operating system into memory and hand over control to the kernel.
 

/bin 

This directory includes user executable files.It contains essential system binaries that are typically used for system administration and maintenance tasks. The commands and programs stored in /sbin are mostly intended to be run by the system administrator (root user) rather than regular users.(eg.init,ifconfig,fsck,mount..)
 

/dev 

The /dev folder in Linux is a special directory that contains device files, which are interfaces for kernel drivers to communicate with hardware devices.it contains device files. Understanding the structure and purpose of /dev is essential for system administration, device management, and troubleshooting in a Linux environment. eg. /dev/sda: The first SATA or SCSI hard disk./dev/sda1The first partition on the first hard disk /dev/tty0: The first virtual console.
 

/etc 

The /etc directory in a Linux system is a critical part of the filesystem hierarchy. It contains system-wide configuration files and directories that are essential for the operating system and various services to function properly.Configuration Files,System Administration,Hierarchical Structure,Text Files,User,Group Information files, System Application Files ( Appache )
 

/lib 

This folder in a Unix-like operating system contains essential shared libraries and kernel modules required for system functionality and running applications.Understanding its role is essential for system administrators, developers, and users who want to manage or troubleshoot their Linux environment effectively It Contains 1. /lib/x86_64-linux-gnu/: Contains 64-bit libraries for x86_64 architecture 2. /lib/i386-linux-gnu/: Contains 32-bit libraries for i386 architecture.
 

/home 

The home directory storage is available for user files.The /home directory is a crucial part of the Linux file system, providing a dedicated and organized space for user data and configurations, thereby enhancing the multi-user capabilities of Linux. It helps create a user-friendly environment by separating user data from system files and ensuring that each user's data is secure and private.


├── user1
│   ├── Documents
│   ├── Downloads
│   ├── Music
│   ├── Pictures
│   ├── Videos
│   └── .bashrc
├── user2
│   ├── Documents
│   ├── Downloads
│   ├── Music
│   ├── Pictures
│   ├── Videos
│   └── .bashrc
└── ...
 

/mnt 

 It serves as a mount point for mounting external storage devices such as USB drives, CD-ROMs, network shares, and other types of filesystems.The /mnt directory is a crucial part of the Linux filesystem for mounting temporary filesystems and external storage devices. It provides a dedicated space for this purpose, facilitating the management of different filesystems on the system.

example : 

sudo mount /dev/sdb1 /mnt/my_usb
 

/media 

This is typically used for removable media, the /mnt directory is more traditionally used for manually mounted file systems, often for temporary mounts by system administrators.standard location used to mount removable media devices such as USB flash drives, external hard drives, CDs, DVDs, and more. 
 

/opt 

The /opt directory is a useful location for organizing software that doesn't fit neatly into the standard distribution paths, allowing for easier management of third-party applications and ensuring that they are kept separate from essential system software.

Typical Structure

/opt
├── myapplication
│   ├── bin         (executables)
│   ├── lib         (libraries specific to the application)
│   ├── doc         (documentation)
│   └── share       (shared data)
└── anotherapp
   ├── bin
   ├── lib
   └── share
 

/tmp 

Common uses for /tmp include storing temporary files created by software installations, application caches, or intermediary files for programs (like text editors or web browsers). It's also used in scenarios where applications need to create and manipulate temporary files that do not need to persist after the application has finished running.The /tmp directory typically has world-writable permissions (typically 1777), meaning that any user can read, write, and execute files in this directory. 
 

/sbin 

The /sbin directory contains essential system binaries that are primarily intended for system administration tasks. These binaries are executable files that are critical for booting, repairing, or recovering the system. For example, system administration commands like ifconfig, reboot, shutdown, and fsck can usually be found here.
 

/usr 

The name "usr" originally stood for "user system resources" but is now generally interpreted as "Unix System Resources" or "User." The /usr directory contains software, libraries, documentation, and other files intended for user programs and applications.is an important part of the Linux file system hierarchy that houses the majority of user-level applications and resources, helping to keep the system organized and manageable.
 

/var 

The /var directory plays a crucial role in the Unix/Linux filesystem structure for maintaining dynamic data that evolves during operations. Proper management of the files and data within /var is essential for system stability, performance, and resource management. Regular monitoring and cleanup of large or old files, especially in subdirectories such as /var/log, can help prevent disk space exhaustion.It will contain log files, other database files (PostgreSQL, MySQL), email inboxes, web server data files, and much more.

What is the Linux FileSystem

The Linux filesystem is a multifaceted structure comprised of three essential layers. At its foundation, the Logical FileSystem serves as the interface between user applications and the filesystem, managing operations like opening, reading, and closing files. 

Above this, the Virtual FileSystem facilitates the concurrent operation of multiple physical filesystems, providing a standardized interface for compatibility. Finally, the Physical FileSystem is responsible for the tangible management and storage of physical memory blocks on the disk, ensuring efficient data allocation and retrieval. Together, these layers form a cohesive architecture, orchestrating the organized and efficient handling of data in the Linux operating system.

In this article, we will be focusing on the filesystem for hard disks on a Linux OS and discuss which type of filesystem is suitable. 

Linux FileSystem Structure

A filesystem mainly consists of 3 layers.

Logical FileSystem:

The Logical FileSystem acts as the interface between the user applications and the filesystem itself. It facilitates essential operations such as opening, reading, and closing files. Essentially, it serves as the user-friendly front-end, ensuring that applications can interact with the filesystem in a way that aligns with user expectations.

Virtual FileSystem:

The Virtual FileSystem (VFS) is a crucial layer that enables the concurrent operation of multiple instances of physical filesystems. It provides a standardized interface, allowing different filesystems to coexist and operate simultaneously. This layer abstracts the underlying complexities, ensuring compatibility and cohesion between various filesystem implementations.

Physical FileSystem:

The Physical FileSystem is responsible for the tangible management and storage of physical memory blocks on the disk. It handles the low-level details of storing and retrieving data, interacting directly with the hardware components. This layer ensures the efficient allocation and utilization of physical storage resources, contributing to the overall performance and reliability of the filesystem.

When we install the Linux operating system, Linux offers many file systems such as Ext, Ext2, Ext3, Ext4, JFS, ReiserFS, XFS, btrfs, and swap.

 

Ext, Ext2, Ext3 and Ext4 file system

The file system Ext stands for Extended File System. It was primarily developed for MINIX OS. The Ext file system is an older version, and is no longer used due to some limitations.

Ext2 is the first Linux file system that allows managing two terabytes of data. 

Ext3 is developed through Ext2; it is an upgraded version of Ext2 and contains backward compatibility. The major drawback of Ext3 is that it does not support servers because this file system does not support file recovery and disk snapshot.

Ext4 file system is the faster file system among all the Ext file systems. It is a very compatible option for the SSD (solid-state drive) disks, and it is the default file system in Linux distribution.

JFS File System

JFS stands for Journaled File System, and it is developed by IBM for AIX Unix. It is an alternative to the Ext file system. It can also be used in place of Ext4, where stability is needed with few resources. It is a handy file system when CPU power is limited.

ReiserFS File System

ReiserFS is an alternative to the Ext3 file system. It has improved performance and advanced features. In the earlier time, the ReiserFS was used as the default file system in SUSE Linux, but later it changed some policies, so SUSE returned to Ext3. This file system dynamically supports the file extension, but it has some drawbacks in performance.

XFS File System

XFS file system was considered as high-speed JFS, which is developed for parallel I/O processing. NASA still using this file system with its high storage server (300+ Terabyte server).

Btrfs File System

Btrfs stands for the B tree file system. It is used for fault tolerance, repair system, fun administration, extensive storage configuration, and more. It is not a good suit for the production system.

Swap File System

The swap file system is used for memory paging in Linux operating systems during the system hibernation. A system that never goes in hibernate state is required to have swap space equal to its RAM size.

ReiserFS: 

It is a journal file system developed in 2001. Despite its earlier issues, it has tail packing as a scheme to reduce internal fragmentation. It uses a B+ Tree that gives less than linear time in directory lookup and updates. It was the default file system in SUSE Linux till version 6.4, until switching to ext3 in 2006 for version 10.2.

btrfs (Better/Butter/B-tree FS): 

It was developed in 2007. It provides many features such as snapshotting, drive pooling, data scrubbing, self-healing and online defragmentation. It is the default file system for Fedora Workstation.

bcachefs: 

This is a copy-on-write file system that was first announced in 2015 with the goal of performing better than btrfs and ext4. Its features include full file system encryption, native compression, snapshots, and 64-bit check summing.

Other File Systems

Linux also has support for file systems of operating systems such as NTFS and exFAT, but these do not support standard Unix permission settings. They are mostly used for interoperability with other operating systems.

Ext4 in Linux File System

EXt4 was designed to be backward compatible with ext3 and ext2, its previous generations. It’s better than the previous generations in the following ways:

It provides a large file system as described in the table above.Utilizes extents that improve large file performance and reduces fragmentation.Provides persistent pre-allocation which guarantees space allocation and contiguous memory.

Delayed allocation improves performance and reduces fragmentation by effectively allocating larger amounts of data at a time.It uses HTree indices to allow unlimited number of subdirectories.

Performs journal checksumming which allows the file system to realize that some of its entries are invalid or out of order after a crash.Support for time-of-creation timestamps and improved timestamps to induce granularity.

Transparent encryption.

Allows cleaning of inode tables in background which in turn speeds initialization. The process is called lazy initialization. Enables writing barriers by default. Which ensures that file system metadata is correctly written and ordered on disk, even when write caches lose power.

There are still some features in the process of developing like metadata check summing, first-class quota supports, and large allocation blocks.

However, ext4 has some limitations. Ext4 does not guarantee the integrity of your data, if the data is corrupted while already on disk then it has no way of detecting or repairing such corruption. The ext4 file system cannot secure deletion of files, which is supposed to cause overwriting of files upon deletion. It results in sensitive data ending up in the file-system journal.

XFS performs highly well for large file systems and high degrees of concurrency. So XFS is stable, yet there’s not a solid borderline that would make you choose it over ext4 since both work about the same. Unless you want a file system that directly solves a problem of ext4 like having capacity > 50TiB.

Btrfs on the other hand, despite offering features like multiple device management, per-block check summing, asynchronous replication and inline compression, does not perform the best in many common use cases as compared to Ext4 and XFS. Several of its features can be buggy and result in reduced performance and data loss.

Sridhar S

Author

Sridhar S

Server Admin - Chadura Tech Pvt Ltd

Related Posts

Comments (0)