If df -h shows inadequate numbers...

by Denis Speranskiy -
Tags: #server #linux

It's a brief summary for the issue with different disk usage reports shown by df and du linux CLI utilities.

First of all if your device contains 100Gb and df shows 100% on 95Gb it's okay, because 5% of a disk is being reserved in order the system would able to run when the disk is "full"

If you stumbled upon a wierd issue when df and du commands show completely different results, in my case it was 100% usage from df and less than 40% from du most likely you have one of two issues:

  • you've removed a huge file, that was used by a process. The process keeps holding disk space so you will need to restart you machine (or just the process) in order to free the space. This command will show you how much is being hold by deleted files.
# lsof / | gawk -F" " '{ print $7}' |sort| uniq| awk '{ sum += $1} END { print sum/(1024*1024*1024) }'
  • you need to force fsck in order you FS being checked (I haven't found a root cause that is bein fixed by this, some people on the Internet is saying that it helped them)
# touch /forcefsck && reboot
  • and what was in my case: my script run by crontab created a backup in /mnt when a dedicated HDD was not mounted. Next day I've fixed the HDD and mounted it there as usual. Thus du is ingoring this mountpoint but df is not. To fix this just unmount you HDD, remove unwanted files and mount it back.

Happy troubleshooting!