What are the different file systems in Linux?

Linux supports a wide variety of file systems that each have their own advantages and disadvantages. Choosing the right file system can optimize performance for different use cases. This article provides an overview of the most common file systems used in Linux and guidance on selecting the best option.

File System Basics

A file system is responsible for organizing and managing files on a storage device. It defines how data is stored, accessed and updated on a physical storage medium like a hard drive or SSD. Key responsibilities include:

  • Structuring the storage medium into files and directories
  • Keeping track of which areas are in use and allocating free space
  • Providing access to files via an API
  • Managing metadata like permissions, timestamps and attributes
  • Implementing policies like permissions and quotas
  • Optimizing performance by caching frequently used data

The file system interfaces with the Linux kernel which interacts with hardware. Different file systems use different structures to organize files on disk, resulting in trade-offs in capabilities.

Types of File Systems

The main file system families used in Linux include:

Disk-Based File Systems

  • EXT – The most widely used Linux file system. There are four generations: EXT, EXT2, EXT3 and EXT4 with newer versions providing added features and improvements.
  • XFS – A high performance filesystem created by SGI. It supports very large files and filesystems.
  • Btrfs – A newer filesystem that incorporates advanced features like snapshots, data integrity checks and automatic defragmentation.

Network File Systems

  • NFS – Allows remote filesystems to be mounted on a client across a network. Part of Sun’s ONC RPC system.
  • SMB/CIFS – The standard Windows file sharing protocol. Enables Linux to interact with Windows file servers.

Special Use File Systems

  • procfs – Provides access to kernel and process information. Used for debugging.
  • sysfs – Provides a virtual filesystem for kernel objects like devices, modules, keys, etc.
  • tmpfs – Stores temporary files in RAM for better performance.

Optical Disc File Systems

  • ISO9660 – The standard CD-ROM filesystem.
  • UDF – An updated filesystem for optical media like DVDs and Blu-Ray.

Flash Storage File Systems

  • FAT32 – Optimized for flash storage like USB drives. Supported across platforms.
  • exFAT – An updated version of FAT32 without file size limits.

The EXT Family

The EXT filesystems are the original and most widely used Linux filesystems. They were designed specifically for Linux and have broad kernel support.

EXT

EXT was the first filesystem created for Linux in 1992. It superseded the earlier Minix filesystem by adding important features like support for 2 terabyte file sizes and 2 terabyte partitions. However, it lacked journaling which made it susceptible to corruption after crashes.

EXT2

Introduced in 1993, EXT2 represented a major advance in performance and capabilities. Key features included:

  • Faster throughput for many operations
  • Support for larger file sizes up to 2 TB
  • Better block and inode allocation algorithms
  • Support for 2 TB partitions with a maximum of 32,000 subdirectories

However, like EXT, EXT2 still did not have a journal which limited its reliability.

EXT3

EXT3 added journaling to EXT2, making it much more reliable and resistant to corruption after crashes or power losses. It tracks file system changes in a circular log to apply those changes after a restart. It remains very popular today, balancing reliability with good performance.

EXT4

The latest iteration, EXT4, adds several performance optimizations like delayed allocation to improve large file write speeds. It also supports larger volumes, up to 1 exabyte, and individual files up to 16 terabytes. Additional improvements include:

  • Faster filesystem checks
  • Extents for tracking contiguous blocks
  • Sparse superblocks for scalability
  • Persistent preallocation for performance

EXT4 is the default filesystem for most Linux distributions today. It offers great performance while being mature and battle-tested.

XFS

Developed by SGI in 1993, XFS was one of the first commercial-grade journaling filesystems for Linux. It was designed for high performance and large filesystems, targeting applications like video creation and scientific computing.

Key features include:

  • Supports filesystems up to 8 exabytes and files up to 8 exabytes
  • High throughput for large files with concurrent IO
  • Metadata journaling to protect filesystem integrity
  • Designed for RAID arrays and high performance storage
  • Sparse inode allocation for scalability
  • Bandwidth reservation for applications

XFS excels with very large files. However, deleting lots of small files can be slower compared to EXT4. Overall, it’s a great choice for large storage deployments like file servers and NAS.

Btrfs

Btrfs (B-tree FS) is a more recent copy-on-write filesystem for Linux aimed at implementing advanced features. Development began at Oracle in 2007 before being contributed to the Linux kernel in 2009.

Key capabilities include:

  • Snapshots – Saving state at a point in time for backups
  • Copy-on-write – Faster copies by only writing modified blocks
  • Checksums – Data and metadata checksums to detect corruption
  • Online defragmentation – Automatically defrag while filesystem is mounted
  • Root disk drive pools – Combining multiple disks into a larger pool
  • Subvolumes – Separate internal filesystem roots
  • Compression – Compress data to save space
  • seed file-based on:
    Filesystem Year Introduced Max File Size Max Volume Size Features
    EXT 1992 2TB 2TB Basic UNIX filesystem
    EXT2 1993 2TB 2TB Performance improvements
    EXT3 2001 2TB 2TB Journaling
    EXT4 2008 16TB 1EB Delayed allocation, extents, sparse superblocks
    XFS 1993 8EB 8EB High performance, large files, metadata journaling
    Btrfs 2009 8EB 8EB Snapshots, copy-on-write, checksums, compression

Btrfs is well suited for backups, snapshots and large storage pools. However, it’s still maturing so thorough testing is recommended before deploying it in production.

Network File Systems

Network file systems allow files to be accessed across a network as if they were on a local disk. This enables central file storage to be shared between multiple systems.

NFS

NFS (Network File System) was originally developed by Sun in the 1980s and has become the most common standard for network file sharing on Linux and UNIX networks. Some key points:

  • Transparent remote access – Remote files are accessed similar to local ones
  • UNIX permissions model – File permissions are maintained across the network
  • Stateless protocol – All metadata is handled by the server
  • Locking for read/write consistency
  • Works across different platforms

NFS is great for sharing files between Linux hosts, though performance can bottleneck under heavy loads. It competes with SMB for cross-platform file sharing.

SMB/CIFS

SMB (Server Message Block) and CIFS (Common Internet File System) are the Windows file sharing protocols. SMB1 is very old, while SMB2 and SMB3 represent newer implementations. Key attributes:

  • Enables Windows/Linux interoperability
  • Supports AD authentication and permissions
  • High performance file transfers
  • Works across networks and the Internet
  • Supports snapshots and replication

SMB can be easier to set up compared to NFS in heterogeneous environments. However, it is more complex and may not be as efficient.

Use Case Comparisons

So which filesystem should you choose? Here are some general guidelines for common scenarios:

General Purpose

For general purpose Linux installations, EXT4 provides the best balance of stability, performance and features for most use cases. It works well on everything from desktops to servers.

Shared Storage

If you need to share storage between multiple systems, NFS would be the standard choice for Linux-only environments, while SMB is better for cross-platform support.

Large Files

XFS and Btrfs are optimized for efficiency and performance with very large files and filesystems. They are great for large media files or scientific data.

Backups

Btrfs features like snapshots, compression and integrity checks make it a good choice for backup storage and archives.

Legacy Systems

EXT2 can be a good option for older Linux systems that may not support newer filesystems like EXT4. It provides better stability and compatibility.

Flash Storage

For USB drives or memory cards, FAT32 works across all major operating systems. exFAT improves support for larger flash drives.

Filesystem Benchmarks

Various benchmarks can test how different filesystems perform with different types of workloads. Here are sample results from some popular filesystem benchmarking tools:

Iozone Filesystem Benchmark

Filesystem Sequential Write Sequential Read Random Write Random Read
EXT4 153 MB/sec 584 MB/sec 282 IOPS 768 IOPS
XFS 253 MB/sec 586 MB/sec 264 IOPS 2,893 IOPS
Btrfs 191 MB/sec 467 MB/sec 305 IOPS 2,646 IOPS

This shows XFS with faster large file sequential IO, while Btrfs and XFS substantially outperform EXT4 on random small read IO.

Linux Foundation Filesystem Benchmark

Filesystem Create Files Stat Files Delete Files
EXT4 16,772 files/sec 74,900 ops/sec 10,520 deletes/sec
XFS 17,284 files/sec 51,844 ops/sec 12,940 deletes/sec
Btrfs 13,177 files/sec 51,517 ops/sec 9,075 deletes/sec

Here we see EXT4 has faster file creation rates, while XFS is faster at deleting lots of small files.

Takeaways from Benchmarks

These benchmarks demonstrate a few key points:

  • Different filesystems can optimize for specific workloads
  • There is no universally fastest filesystem
  • Newer filesystems like XFS and Btrfs are competitive or better for some tasks
  • EXT4 provides excellent all-round performance

Filesystem selection depends on assessing the IO patterns and performance needs of your specific use case.

Conclusion

Linux offers a diverse set of file system options to match various use cases. For general purpose use, EXT4 provides an excellent blend of stability, performance and compatibility. For shared storage, NFS and SMB have complementary strengths. When optimizing for large files or big data, XFS and Btrfs have compelling advantages.

By selecting the right filesystem for your workload, you can maximize performance and capabilities. However, filesystems also continue to evolve so it pays to keep up with new developments. The filesystem landscape changes over time with new innovations like ZFS and CephFS also competing for enterprise workloads.

Understanding the core characteristics of the main Linux filesystems gives you flexibility to tailor them to your storage needs. Match your specific workloads to the strengths of each system. With knowledge and testing, you can select optimal filesystems for your Linux environment.