Introduction
Filesystem tools are not interchangeable. An ext repair command can be wrong for XFS, and repair work is dangerous when a filesystem is mounted. Identify the type and preserve data before acting.
What you should be able to do after this lesson:
- Create and inspect common Linux filesystems.
- Select the correct consistency and repair utility.
- Tune ext filesystems and inspect metadata.
- Manage basic Btrfs subvolumes and snapshots.
- Inspect XFS and understand its backup tools.
- Read SMART health data without treating one attribute as a verdict.
Big Idea: Inspect First, Then Use the Filesystem-Specific Tool
The generic mkfs and fsck commands dispatch to helpers such as mkfs.ext4 or fsck.ext4. XFS and Btrfs have different consistency models and repair procedures. The command name must match both the on-disk format and whether the filesystem is mounted.
Identify Before Acting
lsblk -f
blkid
findmnt
file -s /dev/<device>
Confirm the device, filesystem type, mount state, and available backup. Never guess a device name during repair.
ext2, ext3, and ext4
mkfs.ext4 -L data /dev/<device>
e2fsck -f /dev/<device>
tune2fs -l /dev/<device>
dumpe2fs -h /dev/<device>
fsck is a dispatcher; e2fsck handles ext filesystems. The target should normally be unmounted. tune2fs adjusts parameters such as labels, reserved blocks, and check intervals. debugfs provides low-level inspection and must be used carefully.
XFS
mkfs.xfs /dev/<device>
xfs_info /mountpoint
xfs_repair /dev/<device>
xfs_growfs /mountpoint
XFS repair normally targets an unmounted filesystem. XFS grows while mounted and does not provide a general shrink operation. xfsdump and xfsrestore preserve XFS-specific metadata during backup and restore.
Older objective lists mention xfs_check; current administration normally uses xfs_repair -n for a no-modify examination. Know the historical command name, but follow the installed XFS tools and documentation on a real system.
Btrfs
Btrfs combines filesystem and volume-management features.
btrfs filesystem show
btrfs filesystem usage /data
btrfs subvolume create /data/projects
btrfs subvolume snapshot -r /data/projects /data/snapshots/projects-1
A snapshot initially shares data blocks with its source. It is not an independent backup when stored on the same device.
Useful maintenance commands include btrfs scrub, btrfs balance, and btrfs device stats. Understand the purpose before running an expensive balance.
btrfs-convert can convert selected ext filesystems to Btrfs under supported conditions. Conversion is a migration operation, not a routine repair; verify current support and keep an independent backup.
ZFS Awareness
ZFS provides pooled storage, checksums, snapshots, compression, and replication. It is not part of the mainline Linux kernel in the same way as ext4 or XFS, so installation and integration vary by distribution.
SMART Device Monitoring
smartctl -a /dev/sda
smartctl -t short /dev/sda
smartctl -l selftest /dev/sda
smartd monitors devices over time. Interpret trends, self-test results, media errors, and kernel I/O errors together. NVMe devices expose health through NVMe-specific logs and may also be handled by modern smartmontools.
Safe Repair Workflow
- Capture logs and current layout.
- Stop writes and unmount when required.
- Take a backup or image if the device is failing.
- Run the filesystem-specific check or repair tool.
- Remount and validate data and logs.
Guided Practice: Create and Check a Disposable ext Filesystem
Use an image file so no real device is at risk:
truncate -s 256M /tmp/lpic-ext4.img
mkfs.ext4 -L LPIC_EXT /tmp/lpic-ext4.img
tune2fs -l /tmp/lpic-ext4.img | head -n 20
dumpe2fs -h /tmp/lpic-ext4.img
e2fsck -f /tmp/lpic-ext4.img
Identify the label, UUID, block size, inode count, and last check time. Then create a separate swap image and inspect it without enabling it:
truncate -s 64M /tmp/lpic-swap.img
mkswap /tmp/lpic-swap.img
file /tmp/lpic-swap.img
This exercise demonstrates that filesystem creation and checking operate on unmounted storage. Remove only the disposable images you created after confirming their paths.
Troubleshooting Scenario
An XFS filesystem fails to mount after an outage. An administrator tries e2fsck because it is familiar.
Stop immediately: e2fsck is for ext filesystems. Confirm the type with lsblk -f or blkid, preserve a failing device before repair, and use xfs_repair -n to inspect before a modifying repair. Tool selection is part of the diagnosis.
Exam Focus
- Associate ext filesystems with
tune2fs,dumpe2fs,debugfs, ande2fsck. - Associate XFS with
xfs_info, historicalxfs_check,xfs_repair,xfsdump, andxfsrestore. - Know basic Btrfs subvolume, snapshot, scrub, and
btrfs-convertconcepts. - Use
smartctlandsmartdas evidence alongside kernel and filesystem errors.
Recap
- Filesystem type determines the correct maintenance tool.
- Repair and recovery are different from routine monitoring.
- Snapshots on the same storage do not replace backups.
- SMART is evidence about device health, not a guarantee against failure.
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
