Linux Precision

Linux is so precise. I love it. I mean, those guys can totally do math right? I used Linux on my laptop for quite some time but never realized this. But today, an emergency happened, and I was so shocked when I saw this:

bash-3.00$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 19G 0 100% /
/dev/sda1 99M 15M 80M 16% /boot

I mean, 20 == 19 right? And 80 + 15 = 99. Awesome. The ‘man df’ page says ‘-h’ is for ‘human readable’. I guess the math really needs to be dumbed down for us humans to understand it.


11 thoughts on “Linux Precision

  1. Hey Sid,

    Alexandre is right… by default, when creating a new file system with mkfs.ext3, it will reserve 5% to root.

    This percentage is taken into account even when running df with root privileges.

    To recover your extra 1GB back, just run:

    sudo tune2fs -m 0 /dev/sda2

    BTW, it recovered 25GB on my half terabyte HD… :-P

    Take care.

    — deo

  2. What is happening here goes back far before Linux. A search in the literature will show references to “minfree” (which is the amount “reserved for root”). BSD’s tunefs(8) man page describes this in some more detail.

    Secondly, it is worth pointing out that you’re complaining not about a lack of “precision” but of accuracy. They aren’t the same thing. And once you know how to read the df(1) output, of course, you will see that there is no accuracy problem at all.

  3. I think the point is for a person who doesn’t care about df, those numbers don’t even make sense. It doesn’t even mention rounding.

    This is a perfect example of the program being ‘technically correct’, but not being useful. Well done.

  4. If a person doesn’t care about df, it doesn’t matter if the number make sense to them or not.

    df is merely reporting the values returned by the file system driver. The column headings even make sense, if you actually read them. The “size” is the size of the file system, the “used” is how much is used and the “avail” is how much is available for additional writing in normal operation. No where does it say that these need to add up to the same amounts, they are mostly completely unrelated values. A full disk is an exceptional condition, and the system is set up to avoid serious problems during an exceptional condition.

  5. Some appear to be forgetting what Sid is looking at is “human readable” output. Look up through the comments above and you see all the excuses and reasons why the output is correct… when it really isn’t!

    Waylon hits it on the head. ‘df’ might be doing what it is supposed to, but the output is useless to a regular user. You shouldn’t have to understand what is happening under the hood to understand the output.

    @Joe: Remember that is is all about the user, user, *user*! If something doesn’t make sense, it’s wrong.

  6. man df
    -h, –human-readable
    print sizes in human readable format (e.g., 1K 234M 2G)
    Examples show it’s rounding. Here’re the alternatives:
    18:58 [summer@numbat ~]$ df -h
    Filesystem Size Used Avail Use% Mounted on
    35G 32G 1.1G 97% /
    /dev/hda1 99M 61M 34M 65% /boot
    tmpfs 1.5G 0 1.5G 0% /dev/shm
    18:58 [summer@numbat ~]$ df
    Filesystem 1K-blocks Used Available Use% Mounted on
    35772016 32862740 1062800 97% /
    /dev/hda1 101086 62001 33866 65% /boot
    tmpfs 1481572 0 1481572 0% /dev/shm
    18:58 [summer@numbat ~]$
    Which is easier to read?

  7. Why not use du -hs / if you want to know the size of everything on your drive. Or better yet, use xdiskusage. I thought some of the “lost” space in the df output was from inodes.

  8. So, critics haven’t figured out that Avail != Size – Used ?

    Avail == Size – Used – Reserved

    Maybe instead of complaining, users should ask for the reserved space to be shown in the df output. Or, as end users, using a graphical tool (such as the properties dialog in Konqueror/Dolphin, which bases its values on the non-reserved ). For example, on one of my machines:

    $ df -P /home
    Filesystem 1024-blocks Used Available Capacity Mounted on
    /dev/mapper/VGsystem-home 35079261 33545678 1533583 96% /home
    $ df /home
    Filesystem 1K-blocks Used Available Use% Mounted on
    35079261 33545598 1533663 96% /home

    But, Konqueror shows:
    Free disk space: 1.5GB out of 33.5GB

    People complain that linux is like ‘DOS’, but then complain when df gives them an answer they can’t understand, while all the GUI tools give them the answer in the way they can understand it. I give up.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.