Score:0

Difference between Volume Disk Space and Disk usage returned by ncdu

cn flag

My server has a 130 GB Volume attached.

To check the free disk psace, I run df -h -x tmpfs -x squashfs | grep -v /run/shared and I get :

Filesystem      Size  Used Avail Use% Mounted on
udev            965M     0  965M   0% /dev
/dev/xvda1      128G  111G   13G  90% /

However, when I want the details of the disk usage, by running ncdu on the root directory, I get :

.  55,7 GiB [######### ] /home                                                                                                                           
.  24,0 GiB [####      ] /var
.   2,4 GiB [          ] /usr
    1,0 GiB [          ]  swapfile
  598,6 MiB [          ] /lib
   63,0 MiB [          ] /boot
    9,4 MiB [          ] /sbin
    9,1 MiB [          ] /bin
.   8,1 MiB [          ] /etc
.   4,3 MiB [          ] /tmp
.   2,7 MiB [          ] /run
!  24,0 KiB [          ] /root
!  16,0 KiB [          ] /lost+found
    4,0 KiB [          ] /lib64
e   4,0 KiB [          ] /opt
e   4,0 KiB [          ] /mnt
e   4,0 KiB [          ] /media
!   4,0 KiB [          ] /gandi
.   0,0   B [          ] /proc
.   0,0   B [          ] /sys
    0,0   B [          ] /dev
@   0,0   B [          ]  initrd.img.old
@   0,0   B [          ]  initrd.img
@   0,0   B [          ]  vmlinuz.old
@   0,0   B [          ]  vmlinuz
e   0,0   B [          ] /srv

There is a difference of about 27 GB with the free disk space returned by the previous command (111 GB).

Where does this difference come from ?

Thanks.

Score:1
es flag

This question comes up quite often. The short answer is du and df use differect methods to get data.

The file system allocates disk blocks in the file system to record its data. This data is referred to as metadata which is not visible to most user-level programs (such as du). Examples of metadata are inodes, disk maps, indirect blocks, and superblocks.

The du command is a user-level program that isn't aware of filesystem metadata, while df looks at the filesystem disk allocation maps and is aware of file system metadata. df obtains true filesystem statistics, whereas du sees only a partial picture.

Maxime Freschard avatar
cn flag
Thanks @4snok. I also have another difference between the calculation made by `ncdu` and a calculation made with PHP with the Flysystem package ?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.