2

When I run 'df -ha' on my system for an empty partition it is reporting that 33 MB is used:

/dev/sdb2        16G   33M   16G   1% /mypartition

Yet there are no files on the partition:

ls -lha /mypartition/
total 0
drwx------ 2 root root  6 Feb 16 21:09 .
drwxr-xr-x 5 root root 57 Feb 17 06:26 ..

What could be causing 'df' to report some space as used?

binarylegit
  • 127
  • 1
  • 4

1 Answers1

4

This is perfectly normal. When we create a filesystem (say ext4) it creates a lot of overhead before any files are created. This is Reserved Space and serves the purposes to lower the fragmentation chances and to have some space for fsck, mainly for root user as to assure that services using files on that partition cannot be ruled out of space by some local user filling all the space. Different filesystem reserve different space.

form man tune2fs

-m reserved-blocks-percentage

          Set the percentage of the filesystem which may only be allocated
          by  privileged  processes.   Reserving some number of filesystem
          blocks for use by privileged processes is done to avoid filesys‐
          tem  fragmentation,  and  to  allow system daemons, such as sys‐
          logd(8), to continue to function correctly after  non-privileged
          processes  are  prevented  from writing to the filesystem.  Nor‐
          mally, the default percentage of reserved blocks is 5%.

So when you create a filesystem then default is 5% reserved blocks. You can adjust this reserve block according to your need during filesystem creation mkfs.ext4 -m <X> /dev/sdaX. You can also adjust this value after creating filesystem using tune2fs -m <X> </dev/sdaX> command.

Like if you want to remove reserved blocks:

tune2fs -m 0 /dev/sdaX

I strongly recommend against using -m 0. Reserved space is there for a reason. Even with no reserved blocks (-m 0) there is always a part of the space used for filesystem internal management.

Also, overhead comes from the inode tables and it is purely depends on how many inodes you allocate in a filesystem. Default size of inode is 256 bytes.

And there is no way to confirm this on CLI. What you can do is create different filesystem with different size and reserved space on different Linux Distributions and compare the result.

To confirm Reserved space is for root user only

Reserved Space

  • It is very strange that basically all of its filesystem space is reserved for root... – shodanshok Feb 19 '16 at 08:15
  • This is beacuse no regular Unix user can fill your filesystem up to 100%, and so it's always going to have enough free space to continue normal function. – Siddharth sharma Feb 19 '16 at 08:20
  • Oh, I **totally** misunderstand what the OP asked. I read it as "I have only 33 MB free on my empty filesystem"... You are correct, +1 – shodanshok Feb 19 '16 at 08:40