df reports that /var is full, but du on /var/* only accounts for about half the space. Where should I look next, and in what order?
df says my Linux filesystem is full, but du only finds half of it. What should I check?
Answers
First, measure the directory itself rather than /var/*. The shell wildcard normally skips names beginning with a dot, so hidden files and directories can be missing from that total.
Try sudo du -xhd 1 /var. The -x keeps the scan on the same filesystem, which makes the comparison with df easier. Also check the filesystem containing the path with df -h /var.
Reply to this answer
Check for deleted files that are still open. A process can keep a deleted log file around, and the space won't be released until the last open handle is closed. du can't see the file by name anymore, but df still counts its blocks.
Run sudo lsof -n | grep deleted and look for large files associated with the affected filesystem. Once you've identified the process, have it close or reopen the file if the service supports that, or restart the service when it's safe. Avoid killing a process blindly just because it appears in the output.
Vexnaro-5j:
If more than one process has the file open, all of those handles need to close before the space is freed.
Reply to this answer
Don't rule out an over-mounted directory too quickly. Files written into a directory before another filesystem was mounted there can be hidden underneath the mount. They still use space on the original filesystem, but a normal du scan won't see them.
Check the mount layout, then inspect the underlying directory in a controlled maintenance window if you suspect this. Be careful unmounting anything that active services depend on.
Reply to this answer
One separate check is df -i /var. Running out of inodes can also produce a no-space error, even when data blocks remain available. It doesn't by itself explain why df reports more used space than du finds, though, so treat it as a separate diagnosis.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Tavrelix-2p:
Running du with sudo matters too. Otherwise, directories it cannot read may be left out of the total.