Diagnose a Full or Filling Disk From df, du, and Deleted-but-Open Files Before Deleting Anything
You are helping me diagnose a server or container whose disk is full or filling up. Work like an on-call engineer: rank hypotheses, ask for the cheapest command that splits them, and never suggest deleting anything before we know what it is.
Here is what I have:
- Symptom (error message, alert, or what broke): {{SYMPTOM}}
- Output of `df -h` and `df -i`: {{DF_OUTPUT}}
- Output of `du -xh --max-depth=2 /` (or the mount in question), sorted: {{DU_OUTPUT}}
- What runs on this host (services, containers, cron jobs) and any recent deploys: {{CONTEXT}}
Do the following, in order:
1. State whether this is a block exhaustion problem (df -h at 100%) or an inode exhaustion problem (df -i at 100%), or neither. They have different causes.
2. Compare df and du. If df reports much more used space than du can account for, explain the likely reason: files deleted while a process still holds them open, data hidden under a mount point, or reserved blocks. Give the command to confirm each (for example `lsof +L1` or `lsof | grep deleted` for deleted-but-open files).
3. Rank the most likely causes for this specific host: runaway logs, log rotation that never signals the process, container images and stopped containers, build or package caches, core dumps, temp files from a crashed job, a database or queue growing, many tiny files exhausting inodes.
4. For the top cause, give the safe, reversible first action (for example truncating a log the process holds open with `: > file` rather than `rm`, or restarting the process that holds a deleted file) and what to check afterward to confirm space was freed.
5. Propose the change that prevents recurrence (rotation config, retention limits, alert at 80%, separate volume for logs).
Mark anything destructive clearly and explain what is lost if I run it.
---
When to use it: during an incident or a "disk 90%" alert, when you have shell access and a few minutes to collect evidence before acting.
How to adapt it: for Kubernetes, replace the du step with node and pod ephemeral-storage usage and container log sizes; for a database host, add the database's own size and WAL/binlog views. Remove commands your environment doesn't have.
Example input: df -h shows / at 100%, du accounts for only 12 GB of a 50 GB disk, the host runs a Java service, and logrotate was changed last week.
What good output looks like: it identifies the df/du gap as the key clue, suspects the service still writing to a rotated-and-deleted log, gives `lsof +L1` to confirm, recommends restarting the service or adding `copytruncate`/a postrotate signal instead of deleting files, and suggests a disk alert. Weak output jumps straight to `rm -rf /var/log/*`.
Sign in to upvote this prompt.