Keeping filesystems intact
Keeping a filesystem healthy: how to see what is using space, how to check and repair, and what a journal does that makes a repair rarely necessary.
Lesson 2 of 6 in objective 104. Devices, Linux filesystems, filesystem hierarchy standard, part of LPIC-1 Exam 101-500.
Space, and the second thing that runs out
df reports free space per mounted filesystem — df -h in human units, df -i for inodes. That second one matters: a filesystem can be nowhere near full in bytes and still refuse to create a file, because every file needs an inode and the count was fixed when the filesystem was made. Millions of tiny files is how you get there, and df alone will not show it.
du reports usage by directory, walking the tree — du -sh DIR for one total, du -h --max-depth=1 to find which subdirectory is the problem. df and du can legitimately disagree: a deleted file still held open by a running process is gone from du's tree and still occupying space df counts, which is resolved by restarting whatever holds it.
Checking and repairing
fsck is the front end that dispatches to a filesystem-specific checker: e2fsck for the ext family, xfs_repair for XFS. The rule that matters more than any flag is that a filesystem must be UNMOUNTED, or mounted read-only, before it is checked — running a repair on a live filesystem corrupts it. Checks also run automatically at boot, driven by the mount count and interval in the superblock.
A journal is what makes most of that unnecessary. ext3, ext4 and XFS record what they are about to do before they do it, so after a power cut the filesystem replays or discards the incomplete records rather than scanning every inode. ext2 has no journal, which is precisely why an ext2 filesystem takes so long to check after an unclean shutdown.
tune2fs adjusts ext filesystem parameters after creation — the label, the reserved-blocks percentage, the check interval — and tune2fs -l prints the superblock. dumpe2fs prints far more detail. badblocks scans for physically bad sectors, and is the layer below all of this.
XFS answers with a family of separate programs rather than flags on one, and what separates them is which may run on a MOUNTED filesystem. xfs_repair checks and repairs, and demands the filesystem be unmounted, because it rewrites metadata the kernel also believes it owns. xfs_fsr reorganises the data of a filesystem that is mounted and in use — the defragmenter, and it is safe there precisely because it moves file contents through ordinary filesystem calls rather than going behind the kernel's back. xfs_db inspects metadata, xfs_info reports geometry and xfs_admin changes the label and UUID. The generalisation is worth carrying past XFS: a repair tool wants the filesystem offline, a reorganiser does not.
Worth carrying in
- df -h / df -i
- Free space by filesystem; -i for inodes, which run out separately.
- du -sh DIR
- Total usage of a directory tree.
- fsck -t ext4
- Check a filesystem. Unmount it first.
- e2fsck -f
- Force a check of an ext filesystem even if it looks clean.
- tune2fs -l
- Print the ext superblock. Also sets label, reserved blocks, check interval.
- dumpe2fs
- Full ext filesystem metadata.
- xfs_repair
- The XFS repair tool. Unmount first.
xfs_inforeports geometry,xfs_adminsets the label. - xfs_fsr
- Defragment an XFS filesystem while it stays mounted and in use.
- badblocks
- Scan for physically bad sectors.
What the exam does with this
- Never
fscka mounted read-write filesystem. Questions are built around candidates who forget to unmount. - Running out of inodes looks like a full disk that
dfsays is not full.df -iis the answer. - XFS uses
xfs_repair, not e2fsck. The ext tools do not work on it. xfs_repairneeds the filesystem unmounted andxfs_fsrdoes not. Same family, opposite requirement, and a question about fragmentation on a live server is asking for the second.
- Objective
- 104. Devices, Linux filesystems, filesystem hierarchy standard
- Share of the exam
- 25% (the whole objective)
- Questions in this lesson
- 11
- Signed for by a person
- 0
Partly checked. None of the 11 questions here has been read against the cited source by a person. 11 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
Drill this lesson
A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.
Practise Keeping filesystems intact
Questions in this lesson
- Why is it dangerous to run e2fsck against an ext4 filesystem that is currently mounted read-write? machine-checked
- On an ext4 filesystem at /dev/sda1 you want an automatic check to be forced after every 30 mounts. Which command sets that? machine-checked
- `df -h /var` reports the filesystem 100% full, but `du -sh /var` accounts for only about half that space. Nothing is hidden under a mount point. What is the most likely explanation? machine-checked
- An XFS filesystem on /dev/sdb1 was damaged by a power loss and must be checked and repaired. Which command is the right tool, and what state must the filesystem be in? machine-checked
- Type the command that reports the total disk space consumed by /var/log including everything beneath it, as one single human-readable figure. machine-checked
- A mail server writes thousands of tiny files into /var/spool. Deliveries start failing with 'No space left on device', yet `df -h /var/spool` shows the filesystem is only 40% full. Which command confirms the real cause? machine-checked
- An XFS filesystem that has held constantly appended log files for two years has become badly fragmented. Which command reorganises the files to reduce fragmentation while the filesystem stays mounted and in use? machine-checked
- A server has dropped into a maintenance shell because the unmounted ext4 filesystem on /dev/sdb1 has errors. You want the check to run unattended, answering yes to every question it asks. Which command does that? machine-checked
- e2fsck refuses to check /dev/sdb1, reporting that the superblock is corrupt or has a bad magic number. You know a backup superblock sits at block 32768. Which command restarts the check from that copy? machine-checked
- Before a maintenance window you want to know whether the unmounted XFS filesystem on /dev/sdb1 is damaged, without letting anything be modified. Type the complete command that checks it and reports what it would do, in no-modify mode. machine-checked
- You run `fsck /dev/sdb1` against an unmounted partition and never say what kind of filesystem it holds. What does fsck itself do with that request? machine-checked
Practise Keeping filesystems intact
The rest of objective 104
- Partitions and filesystems
- Keeping filesystems intact — you are here
- Mounting and unmounting filesystems
- File permissions, ownership and disk quotas
- Hard links and symbolic links
- Finding files and where they belong