Skip to content
Troubleshooting · 12 min

Disk pressure: when df and du disagree

A full root filesystem is one of the most common troubleshooting prompts because the obvious first command gives a misleading answer. This lesson walks through why, and what a strong candidate says out loud while they work.

Why disks fill up silently

Disks rarely fill up because of the thing you expect. The usual culprits are a log that stopped rotating, a core dump directory nobody looks at, a package cache, or a process writing into a path that was unmounted and is now on the root volume. The service keeps working until the last block is gone, so the first symptom is often a write error deep inside a dependency, like the log_writer check in the scenario health endpoint.

Two commands answer "is the disk full": df -h for bytes per filesystem and df -i for inodes. Run both before anything else. The candidate who runs du first is already guessing where the space went.

Deleted but still open

When a process holds a file descriptor to a file that has been unlinked, the blocks stay allocated. du walks the directory tree and can't see it; df asks the filesystem and can.

$ lsof +L1
COMMAND   PID USER FD  SIZE/OFF    NLINK NAME
checkout 2214 app  7w  44023414784     0 /var/log/app/checkout.log (deleted)
$ : > /proc/2214/fd/7   # truncate without restart

lsof +L1 lists open files with a link count below one, which is exactly the set of deleted-but-open files. The SIZE/OFF column tells you how much you will get back. Truncating through /proc//fd/ frees the blocks immediately and the process keeps its descriptor, so nothing restarts and no in-flight requests drop.

Linked exercise · needs a computer · 14 minDisk full on a log-heavy nodeRead it here, do it on a computer

Inodes vs bytes

A filesystem can report free bytes and still refuse writes because it has run out of inodes. Check with df -i before you start deleting anything.

Inode exhaustion comes from millions of small files: session stores, mail queues, a cache with one file per key, a cron job creating a temp file per run and never cleaning up. find / -xdev -printf '%h\n' | sort | uniq -c | sort -rn | head shows which directories hold the most files. The fix is almost always to delete in bulk from the offending directory and then fix the producer.

Safe ways to free space

  • Truncate, don't delete, when a process holds the file. Deleting frees nothing and loses the handle you need.
  • Prefer reversible actions: move a large file to another mount before removing it.
  • Rotate logs with the tool that owns them (logrotate -f, journalctl --vacuum-size) rather than rm.
  • Never rm -rf a directory you have not listed first. The interviewer will stop you.
  • After freeing space, confirm with df and watch the service recover before you declare mitigation.
Why rm -rf /var/log/app/* is the wrong moveThe 41 GB file is already unlinked; removing the directory's other entries frees 300 MB and destroys evidence. It also tells the interviewer you did not check what was holding the space.

What interviewers listen for

The rubric for this scenario weights three things: a hypothesis stated before each command ("df and du disagree, so I suspect an open deleted file; I'll check with lsof"), a status update within five minutes that names impact, hypothesis, next step and next update time, and a mitigation whose blast radius matches the problem. Speed matters less than you think; a candidate who mitigates in six minutes with a destructive step scores below one who takes nine and does not.

Say your reasoning out loud even when it feels obvious. The interviewer cannot grade the thought you did not voice.