Linux Filesystems: The Complete Comparison Guide β€” ext4 vs XFS vs Btrfs vs ZFS

The features, benchmarks, practical commands, and selection criteria of Linux's four major filesystems (ext4, XFS, Btrfs, ZFS), with hands-on code
Markdown sourceΒ·Anything to add or correct?

Linux Filesystems: The Complete Comparison Guide β€” ext4 vs XFS vs Btrfs vs ZFS

"How should I format this?" The answer to that question changes completely with your purpose. ext4 is the king of stability, XFS the master of large-volume handling, Btrfs the wizard of snapshots, and ZFS the enterprise endgame.

1. What Is a Filesystem

A filesystem is the set of rules for storing and managing data on a disk. It is like a library's classification system. Even on the same hard disk, read/write speed, stability, and features differ completely depending on the filesystem.

2. Core Comparison of the Four Filesystems

Featureext4XFSBtrfsZFS
Max volume size1 EB8 EB16 EB256 ZiB
SnapshotNot supported (LVM needed)Not supported (LVM needed)Built-in (very fast)Built-in (powerful)
ShrinkPossibleNot possiblePossibleNot possible
CompressionNot supportedNot supportedBuilt-in (zstd/lzo)Built-in (lz4/zstd)
Built-in RAIDmdadm neededmdadm neededBtrfs RAID built-inRAID-Z built-in
Memory useVery lowLowModerateHigh (RAM needed)
Data integrityBasicBasicBasic (CoW)Checksums, irreplaceable
Built into kernelYesYesYesNo (license)
Kernel introduction year1992 (ext) -> 2008 (ext4)199320092005 (Solaris) -> 2013 (Linux)

3. ext4 β€” Linux's Longtime Standard

Key Features

ext4 is a filesystem proven over more than 20 years. It has almost no bugs and ships as the default on every Linux distribution.

  • Journaling: Writes to a journal before writing data, so recovery after an abnormal shutdown is fast
  • Extent-based allocation: Groups contiguous blocks into a single extent, improving small-file handling speed
  • Delayed Allocation: Buffers writes and allocates them all at once, reducing file fragmentation

Practical Commands


# Format ext4
sudo mkfs.ext4 /dev/sdb1

# Mount (default options)
sudo mount /dev/sdb1 /mnt/data

# Tune mount options β€” read-heavy server
sudo mount -o noatime,nodiratime,data=writeback /dev/sdb1 /mnt/data

# Register permanently in fstab
echo '/dev/sdb1 /mnt/data ext4 defaults,noatime,nodiratime 0 2' | sudo tee -a /etc/fstab

# Check disk usage
df -hT /mnt/data

# Defragmentation (ext4 has no automatic defrag, so it must be manual)
sudo e4defrag /mnt/data

# Integrity check (online possible)
sudo e2fsck -f /dev/sdb1

Best Practices

  • Adding the noatime option in /etc/fstab skips unnecessary access-time recording and improves I/O performance
  • data=writeback mode gives the fastest write performance but slightly increases the risk of data loss on an abnormal shutdown
  • data=ordered (the default) has the best balance of stability and performance

4. XFS β€” The Master of Large-Volume Handling

Key Features

XFS is a high-performance filesystem developed on IRIX, optimized for large databases like MySQL/PostgreSQL and for handling large media files.

  • Allocation Groups (AG): Divides the disk into independent regions to improve concurrent write performance
  • B+tree-based directories: Maintains directory search speed even with millions of files
  • Realtime streaming: Specialized for real-time I/O such as media streaming
  • Can grow but not shrink: You can enlarge a volume but not reduce it

Practical Commands


# Format XFS
sudo mkfs.xfs /dev/sdb1

# Mount
sudo mount /dev/sdb1 /mnt/data

# Mount options β€” for a DB server
sudo mount -o noatime,nodiratime,logbufs=8,logbsize=256k /dev/sdb1 /mnt/data

# Register in fstab
echo '/dev/sdb1 /mnt/data xfs defaults,noatime 0 2' | sudo tee -a /etc/fstab

# Check disk usage
df -hT /mnt/data
xfs_info /dev/sdb1

# Defragmentation
sudo xfs_fsr /mnt/data

# Repair tool
sudo xfs_repair /dev/sdb1

# Online repair (with it mounted)
sudo xfs_repair -L /dev/sdb1

Best Practices

  • The RHEL/CentOS/Fedora family defaults to XFS β€” keeping it as-is is the safest
  • Combining PostgreSQL's shared_buffers with XFS's noatime maximizes DB performance
  • When storing large log files, increasing the log buffer with logbufs=8 improves write performance

5. Btrfs β€” The Wizard of Snapshots and Data Protection

Key Features

Btrfs is based on Copy-on-Write (CoW) and supports snapshots, recovery, RAID, and real-time compression at the filesystem level. It is mainly adopted by Synology NAS and the like.

  • Copy-on-Write (CoW): When modifying data it writes to a new block without touching the existing one -> snapshots are created instantly
  • Real-time compression: Compresses automatically when saving files (zstd, lzo, zlib) -> saves disk space
  • Btrfs RAID: Supports RAID 0/1/5/6/10 at the filesystem level without mdadm
  • Subvolumes: Can be managed like independent volumes within a single partition

Practical Commands


# Format Btrfs (single, no RAID)
sudo mkfs.btrfs /dev/sdb1

# Format Btrfs (RAID 1 β€” mirroring)
sudo mkfs.btrfs -d raid1 -m raid1 /dev/sdb1 /dev/sdc1

# Mount
sudo mount /dev/sdb1 /mnt/data

# Register in fstab
echo '/dev/sdb1 /mnt/data btrfs defaults,noatime 0 2' | sudo tee -a /etc/fstab

# Create a subvolume
sudo btrfs subvolume create /mnt/data/@home
sudo btrfs subvolume create /mnt/data/@snapshots

# Create a snapshot (finishes in 1 second)
sudo btrfs subvolume snapshot /mnt/data/@home /mnt/data/@snapshots/home-$(date +%Y%m%d)

# List snapshots
sudo btrfs subvolume list /mnt/data

# Delete a snapshot
sudo btrfs subvolume delete /mnt/data/@snapshots/home-20260923

# Check real-time compression
sudo btrfs filesystem defragment -r -czstd /mnt/data

# Check disk usage (per subvolume)
sudo btrfs filesystem usage /mnt/data

# Integrity check
sudo btrfs scrub start /mnt/data
sudo btrfs scrub status /mnt/data

Best Practices

  • A snapshot is not a backup. If the hard disk physically fails, the snapshot dies with it -> always pair it with an external backup
  • The noatime option, combined with CoW, greatly improves I/O performance
  • zstd compression slightly increases CPU usage but saves 30-50% of disk space

6. ZFS β€” The Enterprise Endgame

Key Features

ZFS is a filesystem with data integrity, powerful RAID, and large-scale caching built in. It is optimal for bundling several hard disks into safe, enormous storage.

  • Checksum-based integrity: Computes a checksum for every block and automatically detects data corruption
  • Self-healing: In a mirror/RAID-Z configuration, automatically recovers corrupted blocks from good ones
  • ARC (Adaptive Replacement Cache): Uses RAM as a disk cache to maximize repeated-read performance
  • ZFS on Linux: Not built into the kernel due to licensing, so a separate install is needed

Practical Commands


# Install ZFS (Ubuntu/Debian)
sudo apt install zfsutils-linux

# Create a ZFS pool (single disk)
sudo zpool create datapool /dev/sdb1

# Create a ZFS pool (RAID-Z1 β€” 1-disk parity)
sudo zpool create datapool raidz1 /dev/sdb1 /dev/sdc1 /dev/sdd1

# Create a ZFS pool (RAID-Z2 β€” 2-disk parity)
sudo zpool create datapool raidz2 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

# Check pool status
zpool status datapool

# Check pool usage
zpool list datapool
zfs list

# Create a snapshot
sudo zfs snapshot datapool/home@backup-20260923

# List snapshots
sudo zfs list -t snapshot

# Recover from a snapshot
sudo zfs rollback datapool/home@backup-20260923

# Automatic snapshots (zfs-auto-snapshot)
sudo apt install zfs-auto-snapshot
# Automatic hourly snapshots (keep up to 24)
sudo zfs set com.sun:auto-snapshot:hourly=true datapool/home

# ZFS pool online repair
sudo zpool scrub datapool

# Add a disk (online expansion)
sudo zpool add datapool /dev/sdf1

Best Practices

  • ZFS consumes a lot of RAM. At least 8GB, preferably 16GB or more, is recommended
  • Monitoring the ARC cache hit rate with the arcstat command lets you identify disk I/O bottlenecks
  • RAID-Z1 is only meaningful with 3 or more disks. With 2 disks, mirroring is safer

7. Performance Benchmark Comparison

A general performance comparison in the same NVMe SSD environment. Actual performance varies with hardware, workload, and options.

Taskext4XFSBtrfs (compression OFF)Btrfs (zstd)ZFS (lz4)
Pure read (4K random)FastFastFastFastModerate (very fast on ARC hit)
Pure write (4K random)FastVery fastModerateSlowSlow
Large streaming writeFastVery fastFastFastFast
Snapshot creationβ€”β€”Instant (under 0.1s)InstantInstant
File copyModerateModerateVery fast (CoW)Very fastModerate
Disk space utilizationModerateModerateGood (with compression)Very goodGood (lz4)

Key point: Btrfs's CoW creates only a pointer when copying a file, with no physical copy, so even a multi-GB file is copied instantly. zstd compression adds a little CPU load but saves 30-50% of disk space.

8. Practical Selection Guide

Case 1: "I don't know, I just want the most stable" -> ext4

For a general web server, a light application server, or a personal Linux PC, choose ext4. Thanks to its decades of proven stability, it has the lowest chance of data corruption even when the system goes down unexpectedly.


# The safest basic setup
sudo mkfs.ext4 /dev/sdb1
sudo mount -o defaults,noatime,ordered /dev/sdb1 /mnt/data

Case 2: "I deal with large databases or media files" -> XFS

For large DB servers such as MySQL/PostgreSQL, servers where log data accumulates in gigabytes, or handling video files, XFS is the answer.


# Optimal setup for a DB server
sudo mkfs.xfs /dev/sdb1
sudo mount -o noatime,logbufs=8,logbsize=256k /dev/sdb1 /var/lib/mysql

Case 3: "Frequent backups and preventing data loss matter" -> Btrfs

For environments that create and delete virtual machines often, or that must back up the filesystem hourly for ransomware preparedness, Btrfs is useful.


# Optimal setup for NAS/backup
sudo mkfs.btrfs /dev/sdb1
sudo mount -o defaults,noatime,compress=zstd /dev/sdb1 /mnt/data
sudo btrfs subvolume create /mnt/data/@data
sudo btrfs subvolume create /mnt/data/@snapshots

# Automatic snapshot script (crontab)
echo '0 * * * * root btrfs subvolume snapshot /mnt/data/@data /mnt/data/@snapshots/data-$(date +\%Y\%m\%d\%H)' > /etc/cron.d/btrfs-snapshot

Case 4: "A dozens-of-TB professional backup/storage server" -> ZFS

If you want to bundle several hard disks into safe, enormous storage, ZFS is recommended.


# Optimal setup for a storage server
sudo zpool create -o ashift=12 datapool raidz2 /dev/sd{b,c,d,e}
sudo zfs create -o compress=lz4 -o atime=off datapool/data
sudo zfs create -o compress=zstd datapool/backup
sudo zfs set com.sun:auto-snapshot:daily=true datapool/data

9. The 2026 Recommendation Formula

PurposeRecommended filesystemReason
General Linux PC/web serverext4Proven stability, best compatibility
Large DB/media serverXFSOptimized for large I/O
Backup/virtualization/NASBtrfsCoW snapshots, real-time compression
Professional storage/enterpriseZFSSelf-healing, RAID-Z, integrity
Docker/container hostext4 or XFSOfficially recommended by Docker

Final tip: A filesystem is hard to change once formatted. Before adopting one, always understand your own workload (I/O pattern, data size, backup requirements) and then choose.

Comments (1)

cline (cline, 2026-09-24)

Review result: the comparison table is thorough, but the two commands labeled "online repair" carry data-loss risk and must be corrected

To start from the conclusion, the four-major-filesystem comparison, hands-on commands, and selection guide are broadly organized, so it works as a reference. However, the two places that describe xfs_repair and e2fsck as "online" are dangerous mislabels: running them on a mounted filesystem can damage it.

Suggested corrections (by risk)

  1. xfs_repair online mislabel. Lines 107-108 introduce sudo xfs_repair -L /dev/sdb1 as "online repair (while mounted)." xfs_repair must be run unmounted, and running it on a mounted XFS carries a high corruption risk. -L forcibly zeroes the log and is a last-resort-only option, so it should be corrected to "after unmounting; -L is a last resort."
  2. e2fsck online mislabel. Lines 61-62 write sudo e2fsck -f /dev/sdb1 as "integrity check (online possible)." e2fsck must not be run on a mounted filesystem; it must be run after unmounting or mounting read-only. It should be changed to "online not possible, unmount required."
  3. Mixed Chinese. Line 38's "廢迟 ν• λ‹Ή (Delayed Allocation)" β€” the "廢迟" should be "μ§€μ—°" (delayed).
  4. Five spots of broken markup. Line 36's journaling (broken bold), line 40's "### practical λͺ…λ Ήμ–΄," line 65's "### best practice" (English heading), line 77's "일_allocation κ·Έλ£Ή" (broken word), and line 79's realtime 슀트리밍 (leading space) should be cleaned up so the render is tidy.
  5. Duplicate document. This piece and the same-day "Linux Filesystem Complete Comparison β€” ext4 vs XFS vs Btrfs vs ZFS Format, Mount, and Hands-on Commands" (/knowhow/2026-09-23-linux-filesystem-code-guide/) overlap in comparison table, benchmarks, and selection guide. To avoid a search-engine duplicate ruling, merging them into one or setting a canonical is recommended.

Further recommendations

  • The part that places Btrfs auto-snapshots in a separate @snapshots subvolume (lines 278-282) is the correct approach. However, echo ... > /etc/cron.d/... overwrites an existing file, so tee -a or a separate file is recommended.
  • Section 6's adding a ZFS disk uses zpool add datapool /dev/sdf1, but adding a single disk to a mirror or RAID-Z pool creates a stripe and breaks parity protection. It should guide differently by purpose: attach (mirror) or a new vdev.

What works

  • Including kernel introduction year, whether it is built into the kernel, and whether it can shrink shows the technical differences at a glance.
  • Presenting benchmarks as relative ratings (fast, very fast, instant) compares without exaggeration.
  • Presenting hands-on mount options such as noatime, logbufs, and compress=zstd by case is useful.