Silly question regarding "du" and "df".

Marius Gedminas marius at pov.lt
Fri Jan 26 13:39:47 UTC 2007


On Fri, Jan 26, 2007 at 05:45:48PM +0800, Michael T. Richter wrote:
> Being who I am, I also run df and get this:
> 
> Filesystem             Size   Used  Avail Use% Mounted on
> /dev/sda1               79G    38G    38G  50% /media/Repository80GB
> 
> Now I cannot for the life of me make the numbers add up.

That's because by default 5% of disk space in ext3 partitions is
reserved and not included in the Avail column.  79G * 5% ~= 4G.  38G +
38G + 4G = 80G. The 1G difference is just rounding error, run df without
-h to see the exact block counts.

There are two reasons for reserving 5%:

  * It reduces disk fragmentation.

  * If a user fills up the partition, the superuser can still create
    files.

> Absolutely the
> only thing on the disk is this (partial) mirror.  Yet "du" reports that
> only 35GB is used up while df reports that 38GB is used up.

That's a bit more interesting.  Here's the du report I snipped above:

> 22G     pool/main
> 2.8G    pool/multiverse
> 591M    pool/restricted
> 9.2G    pool/universe
> 35G     total

The difference can consist of:

  * files/directories that are siblings of 'pool' (there may be hidden
    ones), but I think that's unlikely

  * deleted files that are still opened by some application (their space
    will be freed when all applications close them).

  * filesystem metadata (block usage bitmaps, inodes, the ext3 journal).

  * errors in accounting if the machine crashed and didn't unmount the
    filesystem, or if there's corruption of some sort.

I'm pretty certain that in your case those 3 gigs are in filesystem
metadata.

> Now perhaps
> I can see slack space making up the difference (although almost 10%
> slack space is pretty odd for such large files).

du includes slack space in its calculations.  Compare the files sizes
printed by du with those printed by ls -l.

> In case there's some kind of "quota only for root" thing going on (I
> know I can do this in other operating systems so I assume that even
> UNIXen can do it), I su -i and try again.  Same numbers all around.

Being root does not change the numbers shown by df.  You can see the
number of reserved blocks in a filesystem with tune2fs -l /dev/hdaX.
Midnight Commander also shows the whole available space, IIRC.

> So why do "du" and "df" report different amounts used?  And why do the
> numbers reported by "df" not add up?  (And why does System
> Monitor->Devices report for that drive a size of 73.4GB instead of 79
> but reports the same amount used as "df"?)

That may be a difference in units.  1G can mean 1000000000 bytes, or it
can mean 1073741824 bytes.  73.4 metric gigabytes = 78.8 binary
gigabytes (or "gibibytes", see http://en.wikipedia.org/wiki/Gibibyte).

> Is this a case of the man
> with two watches never knowing what time it is?

No, just historical legacy.

Marius Gedminas
-- 
The memory management on the PowerPC can be used to frighten small children.
		-- Linus Torvalds
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20070126/b1116787/attachment.pgp>


More information about the ubuntu-users mailing list