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.
XFS vs. EXT4 Comparison
Section titled “XFS vs. EXT4 Comparison”| Feature | XFS | EXT4 |
|---|---|---|
| Default in | RHEL 7+ / CentOS 7+ | Debian / Ubuntu |
| Maximum filesystem capacity | 8 EB | 1 EB |
| Maximum single file size | 8 EB | 16 TB |
| Online expansion | Supported (grow only) | Supported (grow only) |
| Online shrink | Not supported | Not supported online, but supported offline |
| Journal type | Metadata journal | Metadata + data journal |
| Defragmentation | xfs_fsr | e4defrag |
| Repair tool | xfs_repair | e2fsck |
| Best suited for | Large files, high-concurrency I/O | General purpose, many small files |
| File deletion performance | Excellent | Good |
Creating Filesystems
Section titled “Creating Filesystems”Creating an XFS Filesystem
Section titled “Creating an XFS Filesystem”Basic creation:
sudo mkfs.xfs /dev/sdb1Specifying a label and block size:
sudo mkfs.xfs -L appdata -b size=4096 /dev/sdb1Force re-format (overwrite an existing filesystem):
sudo mkfs.xfs -f /dev/sdb1Common mkfs.xfs parameters:
| Parameter | Description |
|---|---|
-f | Force format |
-L label | Set the filesystem label |
-b size=N | Set the block size (default 4096) |
-i size=N | Set the inode size |
-d agcount=N | Set the number of allocation groups |
Creating an EXT4 Filesystem
Section titled “Creating an EXT4 Filesystem”Basic creation:
sudo mkfs.ext4 /dev/sdb1Specifying a label, block size, and inode ratio:
sudo mkfs.ext4 -L appdata -b 4096 -i 8192 /dev/sdb1Common mkfs.ext4 parameters:
| Parameter | Description |
|---|---|
-L label | Set the filesystem label |
-b blocksize | Set the block size |
-i bytes-per-inode | Allocate one inode per this many bytes |
-N number | Specify the total number of inodes |
-m percentage | Percentage of space reserved for root (default 5%) |
-O feature | Enable a specified feature |
XFS Management Tools
Section titled “XFS Management Tools”xfs_info - Viewing XFS Filesystem Information
Section titled “xfs_info - Viewing XFS Filesystem Information”sudo xfs_info /dev/sdb1Or view via mount point:
sudo xfs_info /appExample 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=1data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0, ftype=1log =internal log bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0Key fields explained:
bsize: Block sizeblocks: Total number of blocksagcount: Number of allocation groupsisize: Inode size
xfs_repair - Repairing an XFS Filesystem
Section titled “xfs_repair - Repairing an XFS Filesystem”Basic repair procedure:
-
Unmount the filesystem:
Terminal window sudo umount /app -
First check whether the log can be replayed:
Terminal window sudo xfs_repair -n /dev/sdb1The
-nflag runs in check-only mode without making repairs. -
Perform the repair:
Terminal window sudo xfs_repair /dev/sdb1 -
If a corrupted log prevents repair, clear the log and retry:
Terminal window sudo xfs_repair -L /dev/sdb1-Ldiscards uncommitted transactions in the log, which may result in minor data loss. Use only when necessary. -
Remount:
Terminal window sudo mount /dev/sdb1 /app
xfs_growfs - Online XFS Expansion
Section titled “xfs_growfs - Online XFS Expansion”After a logical volume or partition has been enlarged, expand the XFS filesystem to use the new space:
# Expand to fill all available space on the device at the mount pointsudo xfs_growfs /appYou can also specify a new block count:
sudo xfs_growfs -D 26214400 /appOther XFS Tools
Section titled “Other XFS Tools”# Defragmentationsudo xfs_fsr /app
# Back up an XFS filesystemsudo xfsdump -l 0 -f /backup/app.dump /app
# Restore an XFS filesystemsudo xfsrestore -f /backup/app.dump /app
# Freeze a filesystem (for consistent snapshots)sudo xfs_freeze -f /app# Unfreezesudo xfs_freeze -u /appEXT4 Management Tools
Section titled “EXT4 Management Tools”tune2fs - Viewing and Adjusting EXT4 Parameters
Section titled “tune2fs - Viewing and Adjusting EXT4 Parameters”View detailed filesystem information:
sudo tune2fs -l /dev/sdb1Common adjustment operations:
# Change the filesystem labelsudo 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 featuresudo tune2fs -O has_journal /dev/sdb1
# View the UUIDsudo tune2fs -l /dev/sdb1 | grep UUIDe2fsck - Checking and Repairing EXT4
Section titled “e2fsck - Checking and Repairing EXT4”-
Unmount the filesystem:
Terminal window sudo umount /data -
Check the filesystem (without repairing):
Terminal window sudo e2fsck -n /dev/sdb1 -
Automatically repair all issues:
Terminal window sudo e2fsck -y /dev/sdb1 -
Force check (even if the filesystem is marked clean):
Terminal window sudo e2fsck -f /dev/sdb1 -
Remount:
Terminal window sudo mount /dev/sdb1 /data
Common e2fsck parameters:
| Parameter | Description |
|---|---|
-n | Check only, do not repair |
-y | Automatically answer yes to all questions |
-f | Force check |
-p | Automatically repair safe issues |
-v | Verbose output |
resize2fs - Resizing an EXT4 Filesystem
Section titled “resize2fs - Resizing an EXT4 Filesystem”Expanding an EXT4 Filesystem
Section titled “Expanding an EXT4 Filesystem”Online expansion (while the filesystem is mounted):
# First extend the logical volume or partitionsudo lvextend -L +20G /dev/vg_data/lv_data
# Then expand the filesystem to fill the entire devicesudo resize2fs /dev/vg_data/lv_dataExpand to a specific size:
sudo resize2fs /dev/vg_data/lv_data 80GShrinking an EXT4 Filesystem
Section titled “Shrinking an EXT4 Filesystem”-
Unmount the filesystem:
Terminal window sudo umount /data -
Force check the filesystem:
Terminal window sudo e2fsck -f /dev/vg_data/lv_data -
Shrink the filesystem:
Terminal window sudo resize2fs /dev/vg_data/lv_data 30G -
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 -
Remount and verify:
Terminal window sudo mount /dev/vg_data/lv_data /datadf -hT /data
Practical Tips
Section titled “Practical Tips”Checking the Filesystem Type
Section titled “Checking the Filesystem Type”# Method 1: lsblklsblk -f
# Method 2: blkidsudo blkid /dev/sdb1
# Method 3: df (for mounted filesystems)df -T /app
# Method 4: file commandsudo file -sL /dev/sdb1Checking Filesystem Usage
Section titled “Checking Filesystem Usage”# View usage of all mount pointsdf -hT
# View inode usagedf -i
# View disk usage for a specific directorydu -sh /app/*Changing a Filesystem Label
Section titled “Changing a Filesystem Label”# XFSsudo xfs_admin -L newlabel /dev/sdb1
# EXT4sudo tune2fs -L newlabel /dev/sdb1Changing a Filesystem UUID
Section titled “Changing a Filesystem UUID”# XFS (must be unmounted)sudo xfs_admin -U generate /dev/sdb1
# EXT4sudo tune2fs -U random /dev/sdb1Hands-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.
-
Create two partitions (assuming /dev/sdb is already partitioned):
Terminal window lsblk /dev/sdb# sdb1 - 50G (for XFS)# sdb2 - 50G (for EXT4) -
Create the filesystems:
Terminal window sudo mkfs.xfs -L xfs_data /dev/sdb1sudo mkfs.ext4 -L ext4_data -m 1 /dev/sdb2 -
Mount and verify:
Terminal window sudo mkdir -p /data/xfs /data/ext4sudo mount /dev/sdb1 /data/xfssudo mount /dev/sdb2 /data/ext4df -hT /data/xfs /data/ext4 -
View filesystem information:
Terminal window # XFS informationsudo xfs_info /data/xfs# EXT4 informationsudo tune2fs -l /dev/sdb2 | head -30 -
Configure auto-mounting:
Terminal window sudo cp /etc/fstab /etc/fstab.bakcat <<EOF | sudo tee -a /etc/fstabLABEL=xfs_data /data/xfs xfs defaults,noatime 0 0LABEL=ext4_data /data/ext4 ext4 defaults,noatime 0 0EOFsudo 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.