The df -h command shows that the disk is 100% full, while the du -sh command shows that the space used is only 20%. What is the root cause and how do you solve it without restarting the server?
The reason is that there are files that were deleted with the rm command, but they are still open and being held by running processes (such as an application server writing to a deleted log file). The file system unlinks only the name of the file, but does not free the blocks on disk as long as the File Descriptor is open. The problem is solved by using lsof +L1 to find the retained PIDs, then dumping the file by typing > /proc/<PID>/fd/<FD> or restart the responsible service.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Diagnostic and resolution steps in production environments:
-
Detect processes that are holding deleted files:
lsof +L1 # Or scan processes that hold deleted files lsof | grep '(deleted)'You will be shown the process (eg
nginxorjava) with thePID, file size, andFDfile descriptor. -
Instantly free up space without stopping the service: You can dump the content of the retained file directly through the virtual link in
/proc:> /proc/<PID>/fd/<FD_NUMBER>This immediately dumps data blocks into disk and makes space free in
df -hwithout having to restart or disconnect from the service. -
Restart or cleanly reload the service:
systemctl reload <service-name>
- Rerunning the rm command over and over in hopes of freeing up space; the file isn't even visible in the folder tree because its named entry was removed.
- Reboot the entire server as a quick solution rather than diagnosing and resolving file descriptor leaks in the process in question.
- How do you read the contents of a deleted file that is still opened by a process via the /proc path?
- How do you dump a huge log file in production without breaking it via truncate or > access.log command?
Compare hard links and soft/symbolic links in Linux in terms of inodes and operational limits.
A hard link is an additional name for the same inode and disk blocks. Deleting the original name does not affect the hard link, but hard links cannot target directories or cross file systems. A symbolic link is a separate file containing the target path. It can target directories and cross file systems, but it becomes broken when its target is deleted.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Basic comparison table:
| Comparison Hard Link | Soft / Symbolic Link |
|—|—|—|
| Inode number | Same Inode number as the original file | It has a new, independent inode number |
| Crossing file systems | It is not possible (exclusively the same Filesystem) | Yes (can be linked via any path and section) |
| Linking to folders | Not allowed (to prevent infinite loops) | Fully allowed |
| Effect of deleting the original file | The file remains available via the link without any data loss The link is broken and becomes a pointer to a lost path (Dangling Link).
| Create command | ln file link | ln -s file link |
- Trying to create a Hard Link between two different partitions (such as between / and /var on a separate disk), which is impossible because the inode numbers are unique and independent for each file system.
- The belief that modifying the content of a Soft Link does not change the original file; modifying any link changes the content of the actual file, but deleting the Soft Link only deletes the link.
- What does the second column represent in the output of the ls -l command?
- When does the kernel permanently delete physical file data blocks from disk?