Lab 13: Filesystem Tuning — ext4, xfs, btrfs

Time: 40 minutes | Level: Advanced | Docker: docker run -it --rm --privileged ubuntu:22.04 bash

Filesystem choice and tuning have significant impacts on performance, reliability, and feature availability. This lab explores ext4's tunable parameters, XFS's architecture, and Btrfs's copy-on-write capabilities.


Prerequisites

docker run -it --rm --privileged ubuntu:22.04 bash
apt-get update -qq && apt-get install -y e2fsprogs xfsprogs btrfs-progs

Step 1: Create Loopback Devices

for i in 40 41 42; do mknod /dev/loop$i b 7 $i 2>/dev/null || true; done

dd if=/dev/zero of=/tmp/ext.img bs=1M count=200
dd if=/dev/zero of=/tmp/xfs.img bs=1M count=200
dd if=/dev/zero of=/tmp/btrfs.img bs=1M count=300

losetup /dev/loop40 /tmp/ext.img
losetup /dev/loop41 /tmp/xfs.img
losetup /dev/loop42 /tmp/btrfs.img

echo "Devices ready:"
losetup -a | grep "loop4[012]"

📸 Verified Output:


Step 2: ext4 — mkfs Options and tune2fs

📸 Verified Output:

📸 Verified Output:

💡 -m 5 (5% reserved) protects root-level processes from disk-full conditions. For data-only volumes, -m 1 or -m 0 recovers that space.


Step 3: dumpe2fs and e2fsck

📸 Verified Output:

💡 e2fsck -f forces a check even if the filesystem appears clean. Always unmount before checking!


Step 4: Mount Options for ext4

📸 Verified Output:

Common mount options:

Option
Effect

noatime

Skip updating access timestamps — significant I/O reduction

relatime

Update atime only if newer than mtime (Linux default)

data=writeback

Metadata journaling only — fastest, less safe

data=ordered

Default — ensures data written before metadata

data=journal

Safest — journals both data and metadata

barrier=0

Disable write barriers — risky, faster on battery-backed RAID


Step 5: XFS — Create and Inspect

📸 Verified Output:

💡 XFS uses Allocation Groups (AGs) for parallelism. More AGs = better multi-threaded performance on large filesystems. Tune with mkfs.xfs -d agcount=8.


Step 6: Btrfs — Subvolumes and Snapshots

📸 Verified Output:

📸 Verified Output:

💡 Btrfs snapshots are copy-on-write — they only store the differences from the original, making them nearly instant and very space-efficient.


Step 7: Filesystem Benchmarking with dd

📸 Verified Output:

💡 Use fio for production-grade I/O benchmarking — it can simulate random reads, async writes, and queue depths that dd can't.


Step 8: Capstone — Filesystem Tuning for a Use Case

Scenario: You're setting up storage for a high-traffic web server with the following requirements:

  • Fast metadata operations (many small files)

  • No need for POSIX access time tracking

  • Data integrity is critical

  • Need point-in-time snapshots for backups


Summary

Filesystem
Best For
Key Features
Resize

ext4

General-purpose, compatibility

Journaling, tune2fs, mature

Grow online, shrink offline

XFS

Large files, databases, parallel I/O

Allocation groups, reflink

Grow only

Btrfs

Snapshots, dedup, multi-device

CoW, subvolumes, checksums

Grow online

Command
Purpose

mkfs.ext4 -b 4096 -i 8192 -m 1

Create ext4 with custom block/inode/reserve

tune2fs -m 2 /dev/sda1

Change reserved block %

tune2fs -l /dev/sda1

Show ext4 parameters

dumpe2fs /dev/sda1

Full filesystem dump

e2fsck -f /dev/sda1

Force filesystem check

xfs_info /mnt/xfs

Show XFS parameters

xfs_repair /dev/sdb1

Repair XFS (unmounted)

btrfs subvolume create /mnt/data/vol

Create Btrfs subvolume

btrfs subvolume snapshot src dst

Create snapshot

mount -o noatime,data=writeback

Performance mount options

Last updated