Video in progress

An alert says the server disk is 100% full, but du finds no big file. What could it be?

$ df -h /var
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        50G   50G     0 100% /var
$ sudo du -sh /var
12G     /var

Most likely a file that was deleted but is still held open by some process, usually a log. df counts that space as used, while du does not see the file. Find it with lsof +L1, then restart the process or truncate the file.

📖 Answer

On Linux, when you rm a file, only the directory entry is removed. If the Java process is still writing to that log file, the inode and blocks stay allocated. du walks the directories and does not see the file, while df shows the real state of the file system. The difference is 38G of "invisible" file.

The classic case: someone ran rm app.log to free a full disk, but logrotate or the application did not reopen the file.

sudo lsof +L1 | grep deleted
# java  1234  app  12w  REG ... 40G ... /var/log/app/app.log (deleted)

# reclaim the space without a restart:
sudo truncate -s 0 /proc/1234/fd/12

Then fix the root cause:

  • copytruncate in logrotate, or signal the app so it reopens the file;
  • a RollingFileAppender in Logback with maxFileSize and totalSizeCap;
  • in containers, write to stdout and not to a file at all.

Another cause is running out of inodes: if df -i shows 100%, there are millions of tiny files (temp or session files, for example). There is space, but you cannot create a new file.