Re: df & du showing different usages for /var



After nearly running out of space on my /var partition recently, I went
in to clean things up and ensure that it didn't happen again. Using the
"du" command to look for offending directories and files, I wiped out a
bunch of old Apache and Qmail logs...and then found that I was still
using 90% of the partition. So I cd'd over to /var, and got this rather
surprising set of results:

[alex@tms /var]$ sudo du -sh
395M .
[alex@tms /var]$ df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/ad4s1a 484M 126M 320M 28% /
devfs 1.0K 1.0K 0B 100% /dev
/dev/ad4s1f 269G 40G 207G 16% /data
/dev/ad4s1d 9.7G 7.2G 1.7G 81% /usr
/dev/ad4s1e 1.9G 1.6G 173M 90% /var

These wildly different results have me confused. How in the world can
there be a ~1.2GB difference between the disk space in use as reported
by these two tools?

Because they calculate the space differently.

Which is right?

They're both right ... in the manner that they calculate it.

More importantly, how do I fix this?

Well, this depends on your definition of "fix".

If you mean fix du and dh, there's nothing to fix, they're doing their
job exactly correctly. du calculates the used space by looking at each
file in each directory. df calculates it by looking at low-level ffs
data.

If you have one program with a file open, and delete that file with
another program, you create a discrepancy between how df and du operate.
Since there is no longer a directory entry, du doesn't count the space,
but since the other program still has the file open, the filesystem still
has the space allocated and used, so df sees the space. This is the
correct behaviour.

If you mean, how do I actually free up space, the answer could come in
a number of ways. Generally, the easiest thing to do is just reboot the
system. Whatever program has space reserved will exit and the filesystem
will reclaim it. (If the space doesn't free up after a reboot, something
else is wrong)

If a reboot isn't an option, you can often figure out what's going on
by comparing the list of open files provided by fstat with a list of
files that you were deleting. You might then be able to free up the
space simply by restarting a single program: possibly Apache or qmail.

Thanks for such a thorough and prompt response. Given Erik's reply, it looks like I've inadverdently asked an FAQ...and reading the entry he pointed me to, it makes perfect sense what's going on, and a simple restart of Apache fixed things up.

Alex
_______________________________________________
freebsd-questions@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Cannot mount /sys and /dev
    ... filesystem with files and directories. ... You could boot to single user maintenance mode - see your bootloader ... have the contents of */tmp* living on the root filesystem. ... or reboot. ...
    (comp.os.linux.hardware)
  • Re: df & du showing different usages for /var
    ... Filesystem Size Used Avail Capacity Mounted on ... If you mean fix du and dh, there's nothing to fix, they're doing their ... the easiest thing to do is just reboot the ... space simply by restarting a single program: possibly Apache or qmail. ...
    (freebsd-questions)
  • Re: [Ext2-devel] Re: [RFD] FS behavior (I/O failure) in kernel summit
    ... >>it is regarding specified error conditions. ... However given the existence of USB drives and CDROMs with scratches I ... >users to read from rest of filesystem than to just reboot the node. ...
    (Linux-Kernel)
  • Re: prevent fs check after being up for a long time
    ... Issue was that i was told that as a particular filesystem has not been ... Another solution when you are going to reboot the system ... remount the file system 'read-only' and do a quicky fsck. ... Even the virtually unsupported RH9 has had two kernel errata ...
    (linux.redhat)
  • Re: kick off a post boot job
    ... But you're not going to truly resolve the actual problem of needing human input for a passphrase by having some other machine do something automatically. ... string using scp or some other secure transport and then using the decoded result to start up apache. ... I suppose you could use SSH from some remote trusted server to do an "apachectl startssl" and then feed it the passphrase, but then you've ended up putting the passphrase in cleartext on the trusted host, and you need to permit the trusted host to login to the webserver without needing human intervention via SSH keypairs, so you're just moving the problem from one place to another. ... most people leave the x.509 certs unsecured with a passphrase so that the webserver can be setup to start itself upon a reboot without manual intervention. ...
    (freebsd-questions)