Skip to content

Filesystems (XFS/EXT4)

XFS and EXT4 are the two most commonly used filesystems in Enterprise Linux. The RHEL/CentOS family uses XFS by default, while EXT4 is more common in the Debian/Ubuntu family. Understanding their differences and respective management tools is essential for system administrators.

FeatureXFSEXT4
Default inRHEL 7+ / CentOS 7+Debian / Ubuntu
Maximum filesystem capacity8 EB1 EB
Maximum single file size8 EB16 TB
Online expansionSupported (grow only)Supported (grow only)
Online shrinkNot supportedNot supported online, but supported offline
Journal typeMetadata journalMetadata + data journal
Defragmentationxfs_fsre4defrag
Repair toolxfs_repaire2fsck
Best suited forLarge files, high-concurrency I/OGeneral purpose, many small files
File deletion performanceExcellentGood

Basic creation:

Terminal window
sudo mkfs.xfs /dev/sdb1

Specifying a label and block size:

Terminal window
sudo mkfs.xfs -L appdata -b size=4096 /dev/sdb1

Force re-format (overwrite an existing filesystem):

Terminal window
sudo mkfs.xfs -f /dev/sdb1

Common mkfs.xfs parameters:

ParameterDescription
-fForce format
-L labelSet the filesystem label
-b size=NSet the block size (default 4096)
-i size=NSet the inode size
-d agcount=NSet the number of allocation groups

Basic creation:

Terminal window
sudo mkfs.ext4 /dev/sdb1

Specifying a label, block size, and inode ratio:

Terminal window
sudo mkfs.ext4 -L appdata -b 4096 -i 8192 /dev/sdb1

Common mkfs.ext4 parameters:

ParameterDescription
-L labelSet the filesystem label
-b blocksizeSet the block size
-i bytes-per-inodeAllocate one inode per this many bytes
-N numberSpecify the total number of inodes
-m percentagePercentage of space reserved for root (default 5%)
-O featureEnable a specified feature

xfs_info - Viewing XFS Filesystem Information

Section titled “xfs_info - Viewing XFS Filesystem Information”
Terminal window
sudo xfs_info /dev/sdb1

Or view via mount point:

Terminal window
sudo xfs_info /app

Example output:

meta-data=/dev/sdb1 isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

Key fields explained:

  • bsize: Block size
  • blocks: Total number of blocks
  • agcount: Number of allocation groups
  • isize: Inode size

Basic repair procedure:

  1. Unmount the filesystem:

    Terminal window
    sudo umount /app
  2. First check whether the log can be replayed:

    Terminal window
    sudo xfs_repair -n /dev/sdb1

    The -n flag runs in check-only mode without making repairs.

  3. Perform the repair:

    Terminal window
    sudo xfs_repair /dev/sdb1
  4. If a corrupted log prevents repair, clear the log and retry:

    Terminal window
    sudo xfs_repair -L /dev/sdb1

    -L discards uncommitted transactions in the log, which may result in minor data loss. Use only when necessary.

  5. Remount:

    Terminal window
    sudo mount /dev/sdb1 /app

After a logical volume or partition has been enlarged, expand the XFS filesystem to use the new space:

Terminal window
# Expand to fill all available space on the device at the mount point
sudo xfs_growfs /app

You can also specify a new block count:

Terminal window
sudo xfs_growfs -D 26214400 /app
Terminal window
# Defragmentation
sudo xfs_fsr /app
# Back up an XFS filesystem
sudo xfsdump -l 0 -f /backup/app.dump /app
# Restore an XFS filesystem
sudo xfsrestore -f /backup/app.dump /app
# Freeze a filesystem (for consistent snapshots)
sudo xfs_freeze -f /app
# Unfreeze
sudo xfs_freeze -u /app

tune2fs - Viewing and Adjusting EXT4 Parameters

Section titled “tune2fs - Viewing and Adjusting EXT4 Parameters”

View detailed filesystem information:

Terminal window
sudo tune2fs -l /dev/sdb1

Common adjustment operations:

Terminal window
# Change the filesystem label
sudo tune2fs -L newlabel /dev/sdb1
# Adjust the reserved space percentage (from default 5% to 1%)
sudo tune2fs -m 1 /dev/sdb1
# Set maximum mount count before a forced check (0 to disable)
sudo tune2fs -c 0 /dev/sdb1
# Set the check interval (0 to disable time-based checks)
sudo tune2fs -i 0 /dev/sdb1
# Enable a filesystem feature
sudo tune2fs -O has_journal /dev/sdb1
# View the UUID
sudo tune2fs -l /dev/sdb1 | grep UUID
  1. Unmount the filesystem:

    Terminal window
    sudo umount /data
  2. Check the filesystem (without repairing):

    Terminal window
    sudo e2fsck -n /dev/sdb1
  3. Automatically repair all issues:

    Terminal window
    sudo e2fsck -y /dev/sdb1
  4. Force check (even if the filesystem is marked clean):

    Terminal window
    sudo e2fsck -f /dev/sdb1
  5. Remount:

    Terminal window
    sudo mount /dev/sdb1 /data

Common e2fsck parameters:

ParameterDescription
-nCheck only, do not repair
-yAutomatically answer yes to all questions
-fForce check
-pAutomatically repair safe issues
-vVerbose output

Online expansion (while the filesystem is mounted):

Terminal window
# First extend the logical volume or partition
sudo lvextend -L +20G /dev/vg_data/lv_data
# Then expand the filesystem to fill the entire device
sudo resize2fs /dev/vg_data/lv_data

Expand to a specific size:

Terminal window
sudo resize2fs /dev/vg_data/lv_data 80G
  1. Unmount the filesystem:

    Terminal window
    sudo umount /data
  2. Force check the filesystem:

    Terminal window
    sudo e2fsck -f /dev/vg_data/lv_data
  3. Shrink the filesystem:

    Terminal window
    sudo resize2fs /dev/vg_data/lv_data 30G
  4. Shrink the logical volume (must match or be slightly larger than the filesystem size):

    Terminal window
    sudo lvreduce -L 30G /dev/vg_data/lv_data
  5. Remount and verify:

    Terminal window
    sudo mount /dev/vg_data/lv_data /data
    df -hT /data
Terminal window
# Method 1: lsblk
lsblk -f
# Method 2: blkid
sudo blkid /dev/sdb1
# Method 3: df (for mounted filesystems)
df -T /app
# Method 4: file command
sudo file -sL /dev/sdb1
Terminal window
# View usage of all mount points
df -hT
# View inode usage
df -i
# View disk usage for a specific directory
du -sh /app/*
Terminal window
# XFS
sudo xfs_admin -L newlabel /dev/sdb1
# EXT4
sudo tune2fs -L newlabel /dev/sdb1
Terminal window
# XFS (must be unmounted)
sudo xfs_admin -U generate /dev/sdb1
# EXT4
sudo tune2fs -U random /dev/sdb1

Hands-On: Creating and Managing Dual Filesystems

Section titled “Hands-On: Creating and Managing Dual Filesystems”

The following example creates XFS and EXT4 filesystems on two partitions and performs basic management operations.

  1. Create two partitions (assuming /dev/sdb is already partitioned):

    Terminal window
    lsblk /dev/sdb
    # sdb1 - 50G (for XFS)
    # sdb2 - 50G (for EXT4)
  2. Create the filesystems:

    Terminal window
    sudo mkfs.xfs -L xfs_data /dev/sdb1
    sudo mkfs.ext4 -L ext4_data -m 1 /dev/sdb2
  3. Mount and verify:

    Terminal window
    sudo mkdir -p /data/xfs /data/ext4
    sudo mount /dev/sdb1 /data/xfs
    sudo mount /dev/sdb2 /data/ext4
    df -hT /data/xfs /data/ext4
  4. View filesystem information:

    Terminal window
    # XFS information
    sudo xfs_info /data/xfs
    # EXT4 information
    sudo tune2fs -l /dev/sdb2 | head -30
  5. Configure auto-mounting:

    Terminal window
    sudo cp /etc/fstab /etc/fstab.bak
    cat <<EOF | sudo tee -a /etc/fstab
    LABEL=xfs_data /data/xfs xfs defaults,noatime 0 0
    LABEL=ext4_data /data/ext4 ext4 defaults,noatime 0 0
    EOF
    sudo mount -a

Mastering XFS and EXT4 management tools is fundamental to Enterprise Linux operations. Choosing the right filesystem for your workload and making proper use of inspection and repair tools will effectively safeguard data integrity.