Disk Full but du Disagrees? Troubleshooting Linux Disk Space
When df says a filesystem is full but du cannot find the files, the cause is usually deleted-but-open files, inode exhaustion, reserved blocks or data hidden under a mount point. Here is how to find each one and free space safely.
Disk Full but du Disagrees? Troubleshooting Linux Disk Space
A disk space alert fires. You log in, run df -h and see a filesystem at 100%. You run du to find the culprit, and the numbers do not add up: du reports far less used space than df. Or df shows plenty of free space, yet applications fail with No space left on device.
These situations are confusing because df and du measure different things. df asks the filesystem how many blocks and inodes are in use. du walks the directory tree and adds up the files it can see. Anything the filesystem counts but du cannot reach creates a gap.
This guide walks through a structured way to find where space has gone on a Linux server, explains the common causes of a df and du mismatch, and shows how to free space without making things worse. The investigation commands are read-only. Commands that delete or truncate data are clearly marked.
Step 1: Get the Full Picture with df
Start by checking both block usage and inode usage:
# Space usage per filesystem, with filesystem type
df -hT
# Inode usage per filesystem
df -i
Both commands are read-only. Note three things:
- Which filesystem is full.
/varand/are common, but the problem may be on a separate data volume. - The filesystem type. ext4, XFS and Btrfs behave differently in some of the cases below.
- Inode usage. If
IUse%is at 100%, you have run out of inodes, not space. New files cannot be created even if gigabytes are free.
Step 2: Find Large Directories with du
Next, see where visible data lives. Stay on the affected filesystem so mounted volumes do not distort the results:
# Top-level directory sizes on the root filesystem only
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -n 15
The -x option keeps du on one filesystem. Drill down into the largest directory and repeat. On a busy server this can take a while and causes disk I/O, so avoid running it repeatedly against very large filesystems during peak load.
To find individual large files directly:
sudo find / -xdev -type f -size +1G -exec ls -lh {} + 2>/dev/null
If du explains most of the usage reported by df, you have a normal cleanup task. If there is a large gap, continue with the next steps.
Step 3: Check for Deleted Files Still Held Open
This is the most common cause of a df and du mismatch. On Linux, deleting a file removes its directory entry, but the data stays on disk until every process that has the file open closes it. du cannot see the file anymore, while df still counts its blocks.
The classic example is a log file deleted by hand while the application is still writing to it. The space is not freed, and the file may keep growing.
List open files that have been deleted:
sudo lsof -nP +L1
The +L1 option shows open files with a link count below one, which means they no longer have a name on disk. The output includes the process name, PID, file descriptor number, size and original path. This command is read-only.
Freeing the Space
The cleanest fix is to restart or reload the process holding the file. For a service managed by systemd:
sudo systemctl restart myapp.service
Warning: restarting a service interrupts it. Many daemons support a reload or log reopen signal that closes and reopens log files without a full restart; check the service's documentation first.
If a restart is not possible right now, you can truncate the deleted file through the process's file descriptor:
# Replace PID and FD with values from the lsof output
sudo truncate -s 0 /proc/PID/fd/FD
Warning: this permanently discards the file's contents. Only do this when you are sure the data is not needed, for example for a deleted log that has already been shipped elsewhere. Never truncate files belonging to databases or other stateful services, as that can corrupt data.
To prevent this in the future, configure log rotation correctly. With logrotate, either have it signal the application to reopen its logs after rotation, or use copytruncate for applications that cannot reopen files, accepting that a few lines may be lost during rotation.
Step 4: Check for Data Hidden Under Mount Points
If files are written to a directory and a filesystem is later mounted on top of it, the original files become hidden. du walks the mounted filesystem instead, but the hidden files still use space on the underlying filesystem.
This often happens when a data volume fails to mount at boot, an application writes to the empty mount point directory, and the volume is mounted later.
To look underneath mount points, bind-mount the root filesystem to a temporary location. A bind mount shows the filesystem without the other mounts stacked on top of it:
sudo mkdir -p /mnt/rootview
sudo mount --bind / /mnt/rootview
sudo du -xh --max-depth=1 /mnt/rootview/var /mnt/rootview/data 2>/dev/null
If a directory such as /mnt/rootview/data contains files, that data is hidden under the real /data mount. When you are done, remove the bind mount:
sudo umount /mnt/rootview
Warning: files under /mnt/rootview are the real files on your root filesystem, not copies. Be careful not to modify or delete anything there by mistake. If you find hidden data, decide whether it needs to be moved to the mounted volume before you remove it.
Step 5: Check Inode Exhaustion
If df -i shows 100% inode usage, the filesystem has run out of entries for new files. This is usually caused by huge numbers of tiny files: session files, cache entries, mail queues or unbounded temporary files.
Find which directories hold the most inodes. Recent GNU coreutils versions support inode counting in du:
sudo du --inodes -x --max-depth=2 / 2>/dev/null | sort -n | tail -n 15
If your du does not support --inodes, count files per directory with find:
sudo find / -xdev -type f 2>/dev/null | cut -d/ -f2-3 | sort | uniq -c | sort -n | tail -n 15
Once you know the directory, find out which application creates the files and fix its cleanup behavior. Deleting the files frees inodes, but they will return if the cause stays in place.
On ext4, the number of inodes is fixed when the filesystem is created. XFS allocates inodes dynamically, so true inode exhaustion is less common there, though not impossible.
Step 6: Understand Reserved Blocks
On ext4, a percentage of blocks is reserved for the root user by default. This lets system services and administrators keep working when regular users fill the disk. As a result, df may show a filesystem as full to normal users while some space remains available to root.
Check the reserved block count:
sudo tune2fs -l /dev/sdXN | grep -Ei 'reserved block count|block size'
Replace /dev/sdXN with the device shown by df. This command only reads filesystem metadata.
You can lower the reservation with tune2fs -m, and on large data-only volumes that is sometimes reasonable. Do not reduce it on the root filesystem as a quick fix. The reserve exists so a full disk does not prevent logging, logins and recovery work.
Step 7: Check Common Space Consumers
Some locations fill up on almost every Linux server. Check their usage with these read-only commands:
# systemd journal size
journalctl --disk-usage
# Stored core dumps, if systemd-coredump is used
coredumpctl list 2>/dev/null | tail -n 5
# Docker images, containers, volumes and build cache
docker system df 2>/dev/null
# Package manager caches
sudo du -sh /var/cache/apt /var/cache/dnf 2>/dev/null
Cleanup options, each of which permanently deletes data:
sudo journalctl --vacuum-size=500Mremoves archived journal files until the journal is under the given size. Make a permanent limit withSystemMaxUse=injournald.conf.docker image pruneremoves dangling images. Broader prune commands can remove stopped containers, unused volumes and images you may still need, so read the confirmation prompt carefully and avoid pruning volumes unless you are sure.sudo apt cleanorsudo dnf clean packagesremoves cached package files, which can be downloaded again.
A Note on Btrfs
On Btrfs, df can be misleading because of snapshots, compression and how data and metadata space are allocated. Use sudo btrfs filesystem usage / for an accurate view, and check whether old snapshots are holding on to deleted data.
Security Considerations
Disk space problems have security implications:
- Deleting logs destroys evidence. Before clearing logs to free space, make sure they are forwarded to central storage, especially authentication and audit logs.
- A full disk can stop security logging. When
/var/logfills up, audit and authentication events may be lost. Consider placing/var/logon its own filesystem so a runaway log does not affect the rest of the system. - Unbounded writes are a denial-of-service risk. Upload directories, temporary paths and log endpoints that accept user input should have size limits or quotas.
- Be careful with cleanup scripts. Automated deletion with
find ... -deleteshould always target specific paths and patterns, and should be tested with-printfirst.
Preventing the Next Incident
Most disk space incidents are predictable. A few habits make them rare:
- Alert on trends, not only thresholds. A volume at 80% that grows a few percent a day needs attention long before it reaches 95%.
- Monitor inodes as well as blocks. Many monitoring setups only watch space.
- Set retention limits for the journal, application logs and container images.
- Verify mounts at boot, and consider systemd options that prevent services from starting when their data volume is not mounted.
Keeping filesystem usage, mounts and retention settings visible across all of your hosts makes these problems easier to spot early. That kind of infrastructure visibility is the area AtGlance focuses on, but the habits above work with any monitoring stack.
Conclusion
When df and du disagree, the filesystem is not lying; something is using space that a directory walk cannot see. Check for deleted files still held open, data hidden under mount points, inode exhaustion and reserved blocks, in that order. Free space with the least destructive option available, usually a service restart or a proper log rotation fix, and treat every deletion as permanent. Then add inode monitoring, retention limits and trend-based alerts so the next full disk is caught well before it causes an outage.