Linux Disk Full? Check Space, Inodes, and Open Files
Diagnose Linux No space left on device with df, du, findmnt, and lsof. Distinguish full storage, inode pressure, sparse files, and deleted-open files.
Check the filesystem containing the failed write path with findmnt, then inspect both df -hT and df -i. Use du to locate allocated bytes or inode-heavy directories. If df and visible files disagree, check scope, permissions, and deleted-open files before choosing a recovery action.
Start with the failed path and the exact error
A failed write is evidence about a particular operation, user, and filesystem. Capture the destination path, the application’s error, and whether it was creating a new file or extending an existing one. Checking the free space on your home directory does not explain a failure under a separately mounted /var, a container volume, or a temporary filesystem.
The commands below target Linux with GNU coreutils and util-linux. Replace /var/log with the existing directory involved in your incident. If the failing file does not exist yet, use its existing parent directory. Start with these read-only checks before selecting any cleanup action.
findmnt identifies the mount containing the path. df -hT reports filesystem space and type, while df -i reports inode information. Keep the outputs together with their timestamps. An inode percentage by itself is not a universal capacity model: filesystems differ in how they allocate metadata and report these counters.
target_path=/var/log
findmnt --target "$target_path" --output TARGET,SOURCE,FSTYPE,OPTIONS
df -hT -- "$target_path"
df -i -- "$target_path"Source: GNU df manual page ↗
Choose the branch supported by the counters
File contents need storage blocks; files and directories also need filesystem metadata. On a filesystem with a limited inode pool, many tiny files can exhaust that pool while substantial data space remains. Conversely, a few large files can consume data space without exhausting inode capacity.
Interpret availability for the account doing the write. User, group, or project quotas can constrain it independently of global free space. Reserved capacity and filesystem-specific allocation rules can also matter. If both global counters look healthy, inspect the actual error and relevant quota or filesystem diagnostics rather than assuming df is wrong.
“Read-only file system,” “Permission denied,” and “No space left on device” point to different investigations. An application may wrap these errors, so preserve the underlying errno or log context where available. Avoid converting every failed write into a capacity incident.
| Observation | Next investigation | What it does not prove |
|---|---|---|
| Very little available data space | Locate allocated bytes on this mount | The largest visible filename is safe to delete |
| Little inode availability, bytes available | Locate directories with many filesystem objects | A single large archive will release many inodes |
| df usage exceeds visible du total | Check scope, permissions, deleted-open files and filesystem accounting | The difference is necessarily corruption |
| Both counters have headroom | Check quotas, mount state and exact error | The application has permission and capacity |
| tmpfs destination | Check its own size and inode limits | Host disk space is the relevant limit |
Locate bytes and inode-heavy directories separately
Use du to investigate the directory tree on the affected filesystem. A depth-one summary gives you a starting point; repeat it for the large or inode-heavy child directory. The -x option avoids descending into directories on different filesystems, helping keep the investigation aligned with the mount you measured.
These commands still traverse the selected subtree. A shallow display does not mean a shallow scan. On a large or busy tree, scanning may be expensive, so choose a focused starting directory and account for production load. Read permission errors rather than hiding them: an incomplete scan cannot establish the full total.
du measures reachable objects in its traversal, whereas df describes filesystem-wide accounting. Comparing du for /var/log with df for the entire root filesystem compares different scopes. Bind mounts and namespace visibility can complicate that relationship further. Confirm what is included before interpreting a difference.
# Allocated usage, human-readable, one filesystem:
du -x -h --max-depth=1 -- "$target_path"
# Filesystem object usage rather than allocated bytes:
du -x --inodes --max-depth=1 -- "$target_path"Source: GNU du manual page ↗
Lab: one large-looking file and twenty empty files
This bounded exercise creates a new temporary directory, twenty empty files, and a file with an apparent length of 16 MiB. Run it only where that small learning workload is acceptable. It does not attempt to exhaust free space or inodes. Keep the shell open for the following read-only commands.
On a filesystem supporting sparse allocation, truncate can extend a file’s logical length without allocating every data block. Compare allocated usage with apparent size rather than treating ls-style length as disk consumption. Exact allocation and directory metadata depend on the filesystem, so your byte totals may differ from another machine.
The empty files illustrate why object count and data volume answer different questions. They still need directory entries and metadata even though each has length zero. This small exercise demonstrates the accounting distinction; it is not an experiment that reproduces inode exhaustion.
disk_lab=$(mktemp -d)
python3 - "$disk_lab" <<'PYLAB'
from pathlib import Path
import sys
root = Path(sys.argv[1])
small = root / "small-files"
small.mkdir()
for number in range(20):
(small / f"item-{number:02d}").touch()
with (root / "sparse.bin").open("wb") as handle:
handle.truncate(16 * 1024 * 1024)
print("Created a bounded learning fixture:", root)
PYLAB
du -B1 -- "$disk_lab/sparse.bin"
du -B1 --apparent-size -- "$disk_lab/sparse.bin"
du -x --inodes --max-depth=1 -- "$disk_lab"
df -hT -- "$disk_lab"
df -i -- "$disk_lab"Source: GNU du manual page ↗
Why removing a filename may not reclaim its storage yet
On Linux, removing the final directory link does not immediately dispose of a file while a process still holds it open. The open descriptor continues to refer to the object. This is a common explanation for a deleted log disappearing from a directory listing while filesystem usage remains high.
lsof +L1 selects open files with a link count below one. The -nP options avoid hostname and service-name lookups. Access controls and process namespaces limit visibility, so an empty result from an unprivileged or container-local view is not proof that no deleted-open files exist on the host.
Identify the owning process, file, and operational role before acting. Use the service’s documented log-reopen, rotation, or controlled restart workflow when appropriate. Do not kill an unfamiliar process or truncate its descriptor simply to make a graph drop; that can interrupt work or damage application assumptions.
# Read-only investigation; inspect warnings and permissions.
lsof -nP +L1Lab: observe an unlinked file through its descriptor
This self-contained Python exercise creates a temporary file, writes only 1 MiB, then removes its directory name while keeping the handle open. It prints that the name is absent and that the same open handle can still read data. The context managers close the handle and remove the temporary directory afterward.
We ran both labs on Linux with CPython 3.12.14 and GNU coreutils 9.4. The sparse-file apparent length was 16,777,216 bytes, and the twenty empty files were created as specified. The unlinked-file example retained readable data with a zero link count while open. We did not fill a filesystem or measure a production recovery.
This explains the lifetime rule without depending on a visible change in df. A 1 MiB release may be hidden by rounding or unrelated writes. Use the descriptor observations to understand the example, and use appropriately scoped service evidence for an actual incident.
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory(prefix="pwp-unlink-") as directory:
path = Path(directory) / "held.bin"
with path.open("w+b") as handle:
handle.write(b"x" * (1024 * 1024))
handle.flush()
path.unlink()
info = os.fstat(handle.fileno())
print("Name exists:", path.exists())
print("Link count while open:", info.st_nlink)
print("Length while open:", info.st_size)
handle.seek(0)
print("Readable while open:", handle.read(1) == b"x")
print("Handle closed; temporary directory cleaned up.")Other reasons df and du do not match
A missing total can have several explanations at once. First confirm that du can read the full tree and that you are comparing the same filesystem and namespace. Then investigate deleted-open files. A directory hidden beneath a mounted filesystem is another scope issue: the visible mount can obscure underlying files from an ordinary traversal.
Filesystem metadata, reserved capacity, snapshots, shared extents, and layered storage can affect accounting. These mechanisms are filesystem-specific; do not interpret their counters using one ext4-style rule everywhere. In a container, determine whether the write targets its writable layer, a bind mount, or a managed volume.
Hard links add another distinction: several names can refer to one inode, and GNU du normally avoids counting a hard-linked file’s data repeatedly during a traversal. Counting pathnames is therefore not identical to counting unique objects. Sparse files create the opposite-looking surprise: apparent length may greatly exceed allocated usage.
Source: GNU du manual page ↗
A temporary filesystem can be full while the disk is not
Paths such as /dev/shm may use tmpfs. Its configured capacity is separate from free space on a disk-backed root filesystem. Kernel documentation describes size and inode limits for tmpfs; check the actual mount rather than assuming every temporary directory uses the same backing store.
If the failing workload runs in a container or service with its own mount namespace, collect the evidence in that context. A host-level df command against a similarly named path may describe a different mount. Record the path, mount target, source, and filesystem type with the application identity.
Changing a tmpfs limit can alter memory pressure and service behavior. Establish the workload’s need and the environment’s resource policy before changing it. The immediate diagnostic goal is to identify the limit that was reached, not to expand every limit until the symptom disappears.
Match recovery to the resource that is actually scarce
For data-space pressure, review the owning application’s retention, rotation, cache eviction, or archival process. For inode pressure, focus on the source of excessive object creation and the lifecycle of those objects. Removing one very large file may release substantial bytes but only one inode; cleaning an approved cache of tiny files has a different effect.
Use the database, container runtime, package manager, or logging service’s supported maintenance workflow for its data. Storage paths often contain live state whose importance is not apparent from a filename. Preserve needed evidence and backups, and choose a change with a known owner and recovery path.
If growth outpaces legitimate retention, plan capacity and address the producer. A cleanup that restores headroom for five minutes is an operational clue, not a durable fix. Compare growth rates and available inodes over time, keeping mount changes and deployments in the timeline.
Verify the original operation and record what changed
After the approved recovery action, rerun the same df checks against the original directory. Confirm both byte and inode headroom, then verify the application’s actual write or creation operation. A different shell user succeeding elsewhere on the host is not sufficient evidence that the incident is resolved.
Record the affected mount, limiting resource, responsible workload, recovery action, and subsequent growth. If deleted-open files were involved, confirm the relevant descriptors were released through the supported service workflow. Keep monitoring focused on the resource that failed rather than only a generic disk percentage.
The repeatable sequence is path, mount, capacity dimension, owning workload, controlled recovery, and application verification. That sequence turns “No space left on device” into a specific diagnosis while avoiding cleanup actions that remove data without restoring the resource the application needs.
Source: GNU df manual page ↗
Your next steps
- Measure the original failed path in the same runtime and user context as the application.
- Separate data-space pressure from inode pressure and investigate df/du differences before cleanup.
- Use the owning service’s maintenance workflow, then verify the original application operation and sustained headroom.
Sources & official resources
Linked resources checked on 2026-10-24. Technical behavior and provider guidance can change; check the documentation for the version you use.
About this guide and its recommendations
Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.
Suggest a correction →