Df command in Linux not updating actual diskspace, wrong data

Df command in Linux not updating actual diskspace, wrong data

Mattias Geniar, Friday, November 26, 2010 - last modified: Wednesday, March 29, 2017

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 <PID>, or the more agressive kill -9 <PID>), 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%.
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
rabbitmq Troubleshooting TLS-enabled Connections
Viewed 3137 times since Sun, Dec 6, 2020
Inxi: Find System And Hardware Information On Linux
Viewed 2872 times since Sat, Jun 2, 2018
RHCS6: ’fencing’ basics
Viewed 2791 times since Sun, Jun 3, 2018
SSH ProxyCommand example: Going through one host to reach another server
Viewed 14417 times since Tue, Aug 6, 2019
CentOS / RHEL 7 : Configuring an NFS server and NFS client Linux NFS
Viewed 17338 times since Fri, Feb 21, 2020
15 Linux Yum Command Examples – Install, Uninstall, Update Packages
Viewed 4073 times since Thu, Oct 25, 2018
Need to set up yum repository for locally-mounted DVD on Red Hat Enterprise Linux 7
Viewed 3802 times since Mon, Oct 29, 2018
How to manage Linux password expiry with the chage command
Viewed 11775 times since Tue, Sep 11, 2018
Using etckeeper with git
Viewed 7464 times since Sun, Jun 3, 2018
Linux - How to get network speed and statistic of ethernet adapter in Linux
Viewed 2664 times since Fri, Jun 8, 2018