Df command in Linux not updating actual diskspace, wrong data

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, November 26, 2010

Follow me on Twitter as @mattiasgeniar

This is an annoying problem on a lot of Linux distributions, and it can have several causes.

Caused by open file descriptors

If you delete files from the filesystem, the command “df -h” might not show the deleted space as being available. This is because the deleted files could still be held open by (defunct) processes, where the file descriptor handles still point to those files. As a result, the df command assumes the files are still there, and doesn’t clear the space.

Here are some ways you can track which processes still refer to the deleted files.

# lsof | grep 'deleted'
# ls -ld /proc/* | grep '(deleted)'

The solution is to either stop the process (kill , or the more agressive kill -9 ), or if that doesn’t work to restart the server in general.

Reserved space for journaling

Alternativaly, if you’re using a journaling filesystem (like EXT3), keep in mind that df will also count the space used for this journal log in the output.

Default block reservation for super-user

Also keep in mind that there will, by default, be a 5% block reservation for the super-user per blockdevice (in short: for every seperate partition on a hard disk in your system). You can check the amount of reserved space, by running the tune2fs -l command.

# tune2fs -l /dev/sda2 | grep -i reserved
Reserved block count:     208242
Reserved GDT blocks:      1016
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

As it’s described in the mkfs.ext3 manual, for the -m parameter.

-m: Specify the percentage of the filesystem blocks reserved for the super-user.  This avoids fragmentation, and allows root-owned daemons, such as syslogd(8), to continue to function  correctly  after  non-privileged processes are prevented from writing to the filesystem.  The default percentage is 5%.


Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.