Du -skh * in / returns a significantly different size from df on centos 5.5

I have vps slice running centos 5.5 It is assumed that I have 15 disks of disk space, but according to df, it seems that it doubles the use of my disk space.

when I run du -skh * in / as root, I get:

 [ root@yardvps1 /]# du -skh * 0 aquota.group 0 aquota.user 5.2M bin 4.0K boot 4.0K dev 4.9M etc 2.5G home 12M lib 14M lib64 4.0K media 4.0K mnt 299M opt 0 proc 692K root 23M sbin 4.0K selinux 4.0K srv 0 sys 48K tmp 2.0G usr 121M var 

this is consistent with what I downloaded to the machine, and adds up to 5 gigs.

BUT, when I run df , I get:

 [ root@yardvps1 /]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/simfs 15728640 11659048 4069592 75% / none 262144 4 262140 1% /dev 

he shows me using almost 12 concerts.

what causes this discrepancy, and is there anything I can do about it, I planned a server based on 15 concerts, but now it only allows me to have about 7 concerts on it.

thanks.

+4
source share
3 answers

The most common cause of this effect is open files that have been deleted.

The kernel will only free disk blocks of the deleted file if it is not used during its deletion. Otherwise, it is delayed until the file is closed or the system reboots.

A common Unix-world trick to ensure that temporary files are missing is the following:

  • The process creates and opens a temporary file.

  • When you save an open file descriptor, the process shuts down (i.e. deletes) the file

  • A process reads and writes a file, usually with a file descriptor

  • The process closes the file descriptor when it is executed, and the kernel frees up space

  • If the process (or system) terminates unexpectedly, the temporary file has already been deleted and no cleanup is required.

  • As a bonus, deleting a file reduces the likelihood of name collisions when creating temporary files, and also provides an additional level of ambiguity regarding running processes - for any user except the root user.

This behavior ensures that processes should not deal with files that are suddenly pulled out from under their feet, and that processes should not consult with each other to delete a file. This is an unexpected behavior for those coming from Windows systems, though, since you are usually not allowed to delete the file that is being used.

The lsof command lsof when launched as a user, will show all open files and indicate deleted deleted files:

 # lsof 2>/dev/null | grep deleted bootlogd 2024 root 1w REG 9,3 58 917506 /tmp/init.0W2ARi (deleted) bootlogd 2024 root 2w REG 9,3 58 917506 /tmp/init.0W2ARi (deleted) 

Stop and restart the guilty processes or just restart the server to solve this problem.

Deleted files can also be opened by the kernel if, for example, this is an image of a mounted file system. In this case, unmounting the file system or rebooting the server should do the trick.

In your case, judging by the size of the "missing" space, I would look for any links to the file that you used to configure VPS, for example. The Centos disk image that you deleted after installation.

+11
source

Another case that I came across, although it does not seem to be a problem, if you mount the section "on top" of existing files.

If you do this, you actually hide the existing files that exist in the directory on the mounted partition (mount point) from the mounted partition.

Fix: stop any processes with open files on the mounted partition, unmount the partition, find and move / delete any files that are now displayed in the mount points directory.

+3
source

I had the same problem with the FreeBSD server. Reboot helped.

+2
source

All Articles