Diagnose inode exhaustion and verify safe file reclamation
When multiple sites continually generate session files, thumbnails, and temporary task files, uploads and cache writes can start failing even though the disk still has plenty of free space. Looking only at df -h can lead to the wrong diagnosis: data blocks may still be available while the inodes that track file objects have run out. The goal is not to delete the most bytes immediately, but to identify what is driving file counts up and prove that cleanup has restored the ability to create files.
1. Identify the filesystem behind the failing path
The examples below use Debian 12 with GNU coreutils, findutils, Python 3, and lsof. Install any missing tools through the system package manager first. The commands require sufficient permissions to read directories, and the write experiment requires write permission on the target directory. After payment for an AmdCli dedicated server, connection credentials are available in the control panel. If multiple addresses are listed, use the first address to connect over SSH.
Start by finding the actual write path in the application's error messages, then inspect that path rather than checking only the root directory:
findmnt -T /srv
df -hT /srv
df -i /srv
These examples consistently use /srv; replace it with the directory where the error occurs. If the application runs in a container, also verify the path mapping in the application's mount namespace. Do not mistake free space on the host for space available inside the container.
Record the filesystem type, mount point, available data blocks, and free inodes. On ext4, the inode count is usually set when the filesystem is created. XFS allocates inodes dynamically, so the same capacity assumptions cannot be applied to both. If plenty of inodes remain, investigate quotas, read-only mounts, and application-specific limits instead. A “no space” error is not, by itself, a reason to start deleting files.
A filename is a directory entry; an inode represents a file object. Multiple hard links can point to the same inode, so removing one name does not necessarily free the underlying object.
2. Narrow the search by directory instead of deleting straight from scan results
Work down through the confirmed mount point one level at a time. Start with the application's data area rather than recursively scanning the entire system without discrimination:
du --inodes -x --max-depth=2 /srv | sort -n | tail -n 20
--inodes counts objects rather than bytes, while -x prevents crossing into other filesystems. The command still reads a large amount of directory metadata, so narrow the scope progressively. Stop the scan if it causes noticeable I/O pressure on the production system. Do not simply ignore permission errors: incomplete results may hide the actual source of growth.
Document the file lifecycle
For directories with unusually high file counts, identify the service writing the files, what triggers their creation, the application's retention requirements, and the supported deletion mechanism. You can use the following command to inspect candidate files, but it only lists them; it does not delete anything:
find /srv -xdev -type f -mtime +7 -printf '%TY-%Tm-%Td %s %p\n'
Seven days is only a selection criterion here, not a retention policy. Session files, attachments, or indexes with older modification times may still be referenced by the application. Filenames can also contain newlines, so this output is suitable only for manual inspection and must not be piped directly into a deletion command. For automation, use application interfaces or NUL-delimited file lists.
For caches, prefer the application's own invalidation and cleanup procedures. Check task status before removing temporary task files. Never recursively delete database directories, mail queues, or hidden files whose purpose is unknown. Also distinguish regular files, directories, and hard links in the scan results: the total number of directory entries is not the number of inodes you can reclaim.
3. Verify file creation and reclamation in an isolated directory
Run the following experiment only after the incident has been mitigated, with more than 10,000 free inodes and sufficient data capacity remaining on the target filesystem. It creates 2,000 empty files to verify counter changes; it is not a stress test. Do not run it while inodes are already exhausted.
export LAB="$(mktemp -d /srv/inode-lab.XXXXXX)"
test -n "$LAB" && test -d "$LAB" || exit 1
df -i "$LAB"
python3 - <<'PY'
import os
from pathlib import Path
root = Path(os.environ["LAB"])
for number in range(2000):
with (root / f"sample-{number:04d}").open("xb"):
pass
PY
df -i "$LAB"
find "$LAB" -mindepth 1 -maxdepth 1 -type f -name 'sample-*' | wc -l
The expected file count is 2,000. Data usage should change very little, while inode usage increases. If other services are still writing, the filesystem-wide difference reported by df -i may not be exactly 2,000; the count inside the experiment directory is the direct evidence. If the script fails partway through, record the error and the actual file count first. Do not rerun it and obscure the original state.
Limit cleanup to the experiment directory saved in the current shell:
case "$LAB" in
/srv/inode-lab.*)
test -d "$LAB" && test ! -L "$LAB" || exit 1
find "$LAB" -mindepth 1 -maxdepth 1 -type f -name 'sample-*' -delete
rmdir -- "$LAB"
;;
*)
exit 1
;;
esac
df -i /srv
rmdir fails when the directory is not empty. That failure is a safety checkpoint that prevents cleanup from expanding beyond its intended scope. Inspect anything left behind instead of switching to forced recursive deletion. This script is suitable only for a newly created experiment directory controlled by the administrator and not used for writes by other processes.
4. If deletion does not restore free inodes, check for remaining references
If free inodes do not increase noticeably after cleaning up application directories, first confirm that you cleaned the correct mount point. Then check for deleted files that are still open:
sudo lsof +L1
Look at the process, file descriptor, device, and filename, and match them to the target filesystem. A file object may remain in existence while a process still has it open, even after its last directory entry has been removed. Prefer having the application close the file normally, or perform a controlled restart of the relevant service according to operational procedures. Do not simply terminate every matching process.
A reboot is no substitute for diagnosis
Hard links are another common cause: after one path is deleted, other names may still reference the same object. Use stat on a remaining file to inspect its link count. Processes inside containers may also hold files open; verify process ownership from the host. Save the diagnostic evidence before closing files or stopping processes so you can determine which type of reference prevented reclamation.
5. Validate recovery beyond a single free-inode reading
Recovery requires more than a better counter: free inodes on the target mount point must increase, the application must be able to create and delete files normally, the originally failing operation must succeed, and background cleanup jobs must not continue failing. Write probes must use a test location approved for the application. Do not place test files inside production data structures.
Afterward, monitor both the remaining inode count and its rate of consumption. Estimating time to exhaustion from recent net growth is more useful than watching a fixed percentage alone. Set alert thresholds according to the growth rate and the time needed to respond, rather than copying a universal number.
Finally, make the file lifecycle part of operational policy: the producer records ownership, the cleanup process limits the amount handled in each run, and failures leave a list for follow-up. Splitting files across subdirectories can improve management and traversal, but it does not reduce inode consumption. Before consolidating large numbers of small objects into combined storage, validate concurrency, recovery, and backup procedures. Troubleshooting is complete when the cause of growth is under control—not merely when the free-inode count temporarily rises.
Frequently asked questions
Why does file creation fail when the disk still has free space?
Free data blocks do not guarantee free inodes. Run df -hT and df -i against the failing path, then check quotas, read-only mounts, and the exact error. Investigate file counts once inode pressure on that filesystem is confirmed.
Should the server be rebooted if deleting files does not reclaim inodes?
Not as the first step. Check for remaining hard links and open deleted files with lsof +L1. Have the application close the file or perform a controlled restart of the relevant service, then check df -i again.
AMD EPYC 7543P Dedicated Server
From $463.8/month, with no setup fee or contract.