Stage 3 · Build
Storage & Filesystems
ext4, XFS, and Modern Filesystems
Journaling, delayed allocation, metadata checksums, and choosing between ext4 and XFS.
ext4 Overview
ext4 is the most widely used Linux filesystem. It supports volumes up to 1 EB, files up to 16 TB, and has been the default for most distributions for over a decade. ext4 is mature, well-tested, and optimized for general-purpose workloads.
# View filesystem type and mount options
mount | grep " / "
# /dev/sda2 on / type ext4 (rw,relatime,seclabel)
# Detailed filesystem stats
tune2fs -l /dev/sda1 | head -20
# Filesystem volume name: <none>
# Filesystem magic number: 0xEF53
# Filesystem features: has_journal extents huge_file dir_nlink extra_isize
# Block size: 4096
# Blocks per group: 32768
# Inodes per group: 8192
# Check filesystem usage
df -hT
# Filesystem Type Size Used Avail Use% Mounted on
# /dev/sda2 ext4 499G 45G 430G 10% /ext4 uses extents (contiguous block ranges) instead of indirect block mapping, significantly improving performance for large files.
XFS Overview
XFS is a high-performance 64-bit journaling filesystem designed for parallel I/O. It excels with large files and large directories. XFS is the default for RHEL/CentOS and is used by many databases and big data platforms.
# View XFS filesystem info
xfs_info /dev/sda1
# meta-data=/dev/sda1 isize=512 agcount=32, agsize=32768 blks
# = sectsz=512 attr=2, projid32bit=1
# data = bsize=4096 blocks=1048576, imaxpct=25
# = unit=1 blocks=1048576
# naming =version 2 bsize=4096 ascii-ci=0 ftype=1
# log =internal bsize=4096 blocks=1024, version=2
# = sectsz=512 sunit=0 blks, lazy-count=1
# XFS repair tool
xfs_repair -n /dev/sda1 # Dry runXFS allocates space in allocation groups (AGs). Multiple AGs allow parallel I/O across different parts of the filesystem, making XFS excellent for concurrent workloads.
Journaling
Journaling writes metadata changes to a log before applying them to the filesystem. If the system crashes, the journal replays uncommitted changes, ensuring consistency. ext4 and XFS both journal metadata by default.
# ext4 journal info
tune2fs -l /dev/sda1 | grep journal
# Journal inode: 8
# Journal backup: blocks
# Journal features: journal_incompat_revoke
# XFS log information
xfs_info /dev/sda1 | grep log
# log =internal bsize=4096 blocks=1024, version=2
# Disable journaling (DANGEROUS — data loss risk)
tune2fs -O ^has_journal /dev/sda1
# External journal for write-heavy workloads
mkfs.ext4 -J device=/dev/sdb1 /dev/sda1External journals on a separate device can improve performance for write-heavy workloads by reducing contention on the main device.
Delayed Allocation
Delayed allocation (delalloc) defers block allocation until data is flushed to disk. This allows the filesystem to make better allocation decisions and reduces fragmentation. It is enabled by default on both ext4 and XFS.
# ext4 delalloc is default (mount option: delalloc)
mount | grep " / "
# ... defaults,delalloc ...
# Disable delalloc for specific needs
mount -o nodelalloc /dev/sda1 /mnt
# Check allocation statistics
cat /proc/fs/ext4/sda2/session_write_kbytes
# 123456
# XFS also uses delayed allocation by default
# No mount option neededDelayed allocation can cause space issues if the system crashes before flushing. Applications that need guaranteed space (databases) may disable it.
Metadata Checksums
Modern filesystems compute checksums on metadata blocks to detect corruption. ext4 uses metadata_csum feature; XFS has always had metadata checksums. Data checksums are separate and available via dm-integrity or filesystem features.
# Check ext4 checksum feature
tune2fs -l /dev/sda1 | grep checksum
# Filesystem features: has_journal extents huge_file ...
# Enable data checksumming on ext4
tune2fs -O metadata_csum /dev/sda1
# XFS always has metadata checksums
xfs_info /dev/sda1 | grep crc
# sectsz=512 crc=1
# Check for filesystem errors
dmesg | grep -i "ext4|xfs|error|corrupt"Metadata checksums protect against silent corruption. Always enable them on new filesystems. For data integrity, use dm-integrity or application-level checksums.
Choosing Between ext4 and XFS
| Feature | ext4 | XFS |
|---|---|---|
| Max volume size | 1 EB | 8 EB |
| Max file size | 16 TB | 8 EB |
| Parallel I/O | Limited | Excellent |
| Small file performance | Good | Slower |
| Large file performance | Good | Excellent |
| Quota support | User/group/project | User/group/project |
| Online defrag | e4defrag | xfs_fsr |
| Default distribution | Debian/Ubuntu | RHEL/CentOS |
XFS handles large files and parallel I/O better than ext4. For databases, virtual machines, and container storage, XFS is often the better choice. ext4 excels for general-purpose desktop and small-file workloads.
The noatime mount option disables access time updates, reducing write I/O. Add it to /etc/fstab for any database or I/O-heavy workload. Example: /dev/sda1 / ext4 defaults,noatime 0 1
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.