1

I have tried different commands to see sizes of partitions and space used/left and it seems that they always differ in their results.

Here is my space used/left with from the command df -h:

Size  Used Avail Use% Mounted on
395G  355G   21G  95% /home

Notice that used and availabe only add up to 376G but size is 395G

polym
  • 10,852

2 Answers2

3

By default, a linux filesystem reserves 5% of the space for root (the user) usage and maintenance. If the device was 100% full, you couldn't even create the temporary files necessary to allow a user to log in... like perhaps.... root!

Total space:  395.00G  (from your example)
   minus 5%:   19.75G  (reserved space)
============  =======
 User space:  375.25G  (Available to users)

 Used space:  355.00G  (from your example)
Avail space:   21.00G
============  =======
      Total:  376.00G  (equals 'User Space' from above)

Since everything's being rounded due to the use of the -h (human sizes) option, these values are essentially equal.

For a filesystem holding a running linux system, you want SOME space reserved, 5% used to be a good value when disks were much (much!) smaller than today. 1% would be better today, and it's still overkill.

Filesystems used as storage can be formatted/setup with 0% reserved space if you wish, no harm there. It's the 'running system' filesystems that need some space.

During the format, you can specify how much space to reserve (in percentage), by using the -m option:

mkfs.ext4 -m 1 /dev/sdz3

(From the man page)

    -m reserved-blocks-percentage
           Specify the percentage of the filesystem blocks reserved for the super-user. This avoids fragmentation, and allows root-owned daemons, such as sys‐
           logd(8), to continue to function correctly after non-privileged processes are prevented from writing to the filesystem.  The default percentage is 5%.

You can also use tune2fs to adjust the reserved percentage on a filesystem after it's been formatted: (also -m option!)

 tune2fs -m 1 /dev/sdz2

Again, please don't set -m to 0 on a filesystem which holds an operating system, you may never encounter any problems, but if your drive fills up, it'll bite you because you can't even log in to fix things. (You'd need a live/rescue cd/usb-stick to fix it!)

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
lornix
  • 3,482
2

376 / 395 =~ 0.95. So you are missing approximately 5% of your disk. That sounds like the default value of disk space reserved by the system for system logs etc.

You can find out by running

tunefs -l

which will show you what your reserved blocks percentage is.

You can then retune your file system using

tunefs -m

See the man page for tunefs for more detail.

Warwick
  • 1,620