2

I'm having a trouble understanding how df reports the size of filesystems:

$ df
Filesystem     1K-blocks     Used     Available   Use%   Mounted on
/dev/sda3      924815840     63819748 813948260   8%        /
--snip--

For the root partition here's how I interpret the results:

1K-blocks column this is the total size of the filesystem in 1K-block units. In other words, for /dev/sda3:

Total size of the filesystem (in bytes) = 1024 * 924815840

Reserved blocks size (in 1K units) = 924815840 - (63819748 + 813948260)

<Used> and <Available> columns only list the used blocks of regular users, excluding the reserved ones. Let's run df -h now to check results:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       882G   61G  777G   8% /

I was puzzled by the G, df reports in Gib though, not sure why they choose Gib suffix instead of Gib. Same for the 1K, it's really 1Kib. Now, I don't want to play smart here, who got the time for human intelligence these days! If you convert the units as I computed them above, you'll see that the values match, hence my interpretation of the size reported by df is right. The problem starts when you run fdisk which reports totally different filysystem sizes:

Device        Start        End    Sectors   Size Type
/dev/sda3  72265728 1953523711 1881257984 897.1G Linux filesystem

The size is substantially higher here (897.1G) as opposed to the one reported by df (882G), thank's fdisk for giving me more space! But I would like to know which command is telling the truth?

3

They’re all telling the truth, they’re just measuring different quantities.

fdisk shows your partition’s size: this measures raw sectors on your drive.

df shows usable space. Starting with the 897.1GiB of your partition, you lose some space to your file system’s data structures, resulting in df’s reported 882GiB total. Then you “lose” the reserved space, which you accounted for.

  • That's the 882GiB is the total size of the data blocks within the filesystem? And this 882GiB does not account for the filesystem's structure (superblocks, inode tables, ...). – direprobs Aug 16 '17 at 16:44
  • 1
    That’s right. You can store up to 882GiB of files in your file system; the file system’s data structures make up the difference to 897.1GiB. – Stephen Kitt Aug 16 '17 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.