I have file servers which are used to store files. Files might reside there for a week, or for a year. Unfortunately, when I remove files from the server, df
command doesn't reflect the freed up space. So eventually, the server gets filled up (df
shows 99%), and my script doesn't send any more files there, except there might be a few dozen GB of free space on there.
I got noatime
flag on the mounted partitions if that makes any difference.
Deleting the filename doesn't actually delete the file. Some other process is holding the file open, causing it to not be deleted; restart or kill that process to release the file.
Use
to find out which process is using a deleted (unlinked) file.
as Ignacio mentions, deleting the file won't free the space until you delete the processes that have open handles against that file.
Nevertheless, you can reclaim the space without killing the processes. All you need to do is to remove the file descriptors.
First execute lsof | grep deleted to identify the process holding the file
Then execute:
then
The "1" will be the file descriptor. Now type "> FD" to reclaim that space
You might need to repeat the operation if there are other processes holding the file.
If partition has been configured to reserve certain portion of disk space only for root usage,
df
will not include this space as available.Even after space will be reclaimed by deleting files/directories, non-root user won't be able to write to particular partition.
You can easily check if that's your case by trying to create a file on a device as root and non-root user.
Additionally you can check filesystem configuration by running
and calculating actual % on your own.
To change disk % reserved for root-only usage, execute
One possibility is that the file(s) you deleted have more references in the filesystem. If you've created hardlinks, several filenames will point to the same data, and the data (the actual contents) won't be marked as free/usable until all references to it has been removed. Before you delete files, either stat them (Entry named Links) or do ls -l on them (should be the second column).
If it does turn out that the files are referenced elsewhere, I guess you'll have to ls -i the file(s) to find the inode-number, and then do a find with -inum <inode-number> to find the other references to that file (you probably also want to use -mount to stay within the same filesystem as well).
The file is still locked by the process opening it. To free up space, do these steps:
Run
sudo lsof | grep deleted
and see which process is holding the file. Example result:Kill the process using
sudo kill -9 {PID}
. In above sample, the PID is 1623.Run
df
to check if space is already freed up. If it's still full, maybe you need to wait a few seconds and check again.Since I know a ton of you are doing this for redhat in
/var
and gzipping files expecting the FS to shrink, but instead it grows, just make sure you service syslog restart. andwould show you this anyhow.
One reason for missing disk space (a scenario I just encountered myself because I obviously didn't do as I normally do when creating a new array), is this...
Usually I free all available disk space, also the 5% reserved for root (tune2fs -m0), since it's a single user file server system. However, I was suddenly stuck with 0 bytes free according to df, but the difference between total and used space said something else.
Since I was certain I had freed those 5% reserved as a default in at least Fedora (and having some empty folders instead of having the files I had just copied... or thought I had), I started to sweat and search desperately for a way to fix this issue, rebooting, trying "lsof" and that kind of stuff.
Then finally I decided to run tune2fs -m0 on the file system even though I was certain that was not the cause - but it was! A little over 400G became available as it should be. Yeah, I know... my mistake, but nonetheless my comment might be useful to others who forget about this reserved space or strongly believe they've freed it. c",)
The other answers are correct: If you delete a file, and space does not get freed, it's usually either because the file is still kept open, or there are other hardlinks to it.
To help in troubleshooting, use a tool that tells you where the drive space is being spent: You can use
du
to get an overview of where space is going. Even better, use a graphical tool like xdiskusage (there are many like this) to hunt down the culprit. xdiskusage and friends let you drill down into the biggest space hogs to find where space is going.That way, you'll quickly find files that still occupy space because of a second hardlink. It will also show space occupied by deleted, but open files (as (permission denied), I believe, since it cannot read the file name).
One more option: The disk might be full due to a process that is continuously creating data: logs, cores and the like. It is possible that space is actually being freed but is immediately filled up. I have actually seen such a case.
df
in this case simply doesn't give the hole picture. Usedu
to learn more.I`m using EXT2, FSCK helped me in this situation. Try shudown -F now , after some restarts and fscks, I see half used space.