Linucate
~ Linucate_

104.2 Maintain the integrity of filesystems

All Levels

Introduction

This lesson is about checking whether filesystems are healthy and have enough space.

The main question is:

How do you notice problems early and repair simple filesystem issues safely?

What you should be able to do after this lesson:

  • Check free space and inode usage.
  • Use fsck and e2fsck carefully.
  • Recognize tune2fs, xfs_repair, xfs_fsr, and xfs_db.

Before you start:

  • space problems and corruption problems are related, but they are not the same thing
  • first inspect usage safely before you think about repair commands
  • filesystem repair commands can be risky on mounted filesystems

First Checks: Space and Inodes

Disk space

df -h

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2   49G   32G   15G  69% /
tmpfs            14G     0   14G   0% /dev
efivarfs        148K  113K   31K  79% /sys/firmware/efi/efivars
run              14G  2.1M   14G   1% /run
tmpfs            14G   68M   14G   1% /tmp

What this shows:

  • df -h reports usage per mounted filesystem
  • Use% is often the quickest field to check first

Inodes

df -i

Example output:

Filesystem       Inodes   IUsed    IFree IUse% Mounted on
/dev/nvme0n1p2  3276800  581432  2695368   18% /
tmpfs           3550554      15  3550539    1% /dev
run             3550554    1200  3549354    1% /run
tmpfs           1048576      67  1048509    1% /tmp

What this shows:

  • inode exhaustion is separate from normal disk space
  • a filesystem can have free space but still run out of inodes

Why both matter:

  • you can run out of normal space
  • or run out of inodes even when some space remains

Directory usage

du -sh /var
du -sh ./*

Example output from du -sh /var/log /var/cache:

538M	/var/log
5.4G	/var/cache

What this shows:

  • du helps identify which paths are actually using the space
  • this is often the next step after df

df answers "how full is the filesystem?" du answers "what is using the space?"

Filesystem Integrity Checks

Generic tool

sudo fsck /dev/sdX1

ext-family tool

sudo e2fsck /dev/sdX1

Very important beginner rule:

  • checking an unmounted filesystem is safer
  • running repair on a mounted filesystem can be dangerous

This is why a safe workflow usually starts with inspection, not repair.

ext Filesystem Tools

mke2fs

Create ext-family filesystems.

tune2fs

Change or inspect ext filesystem settings.

For LPIC, just know the purpose.

Journaling Awareness

The objective explicitly mentions extra data associated with journaling filesystems.

Simple idea:

  • a journaling filesystem tracks metadata changes in a journal
  • that helps recovery after crashes or unclean shutdowns
  • ext3, ext4, and XFS are common journaling examples

XFS Awareness

Repair

sudo xfs_repair /dev/sdX1

Defragment-style tool

xfs_fsr

Debug tool

xfs_db

You do not need deep XFS internals here. The key point is that XFS has its own maintenance tools.

A Safe Troubleshooting Flow

  1. Check df -h.
  2. Check df -i.
  3. Use du to find large paths.
  4. If you suspect corruption, plan an unmounted filesystem check.
  5. Use the right repair tool for the filesystem type.

Practice Step by Step

1) Find out why a filesystem is "full"
  1. Check overall space: df -h
  2. Check inodes: df -i
  3. Find large directories: du -sh /var/* 2>/dev/null | sort -h
2) Think safely before running a repair
  1. Identify filesystem type: lsblk -f
  2. Ask: is it mounted?
  3. If repair is needed, prefer checking it unmounted from rescue media or maintenance mode.

Cheat Sheet

  • df -h = human-readable filesystem space
  • df -i = inode usage
  • du -sh = directory size
  • fsck = generic filesystem check
  • e2fsck = ext-family check/repair
  • mke2fs = create ext filesystem
  • tune2fs = ext filesystem tuning
  • xfs_repair = XFS repair
  • xfs_fsr and xfs_db = XFS maintenance/debug awareness
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.