Start with read-only checks. Run df -hT and df -i to confirm which filesystem is full and whether it has run out of space or of inodes. Then compare df's Used figure with du -x on that filesystem. If du finds far less, look first for deleted files that a running service still holds open (lsof +L1), then for files hidden underneath a mount point. Neither check changes anything. Restart services or remove files only once you know what you are dealing with.
Work out which filesystem is full, and of what
A server can report "no space left on device" while the visible files add up to almost nothing. That usually means the thing reporting the problem and the thing counting files are looking at different things. df asks the filesystem itself how many blocks are used. du walks the directories it can see and adds up what it finds. When the two disagree, the gap is the clue.
First pin down which filesystem is affected, because a server normally has several (root, /var, /home, data volumes) and the full one is not always the one you were logged in to. Also check inodes. Every file consumes an inode, and a filesystem can run out of those while plenty of space remains, which gives the same error message for a completely different reason.
These three commands only read information and are safe to run on a busy production server.
- Run df with the type option to list every mounted filesystem, its size, how much is used and its mount point. Look for the one at or near 100%.
df -hT - Run df with the inode option on the same system. If IUse% is near 100% on the full filesystem while space is not, skip ahead to the inode notes in the section on unexplained gaps.
df -i - If you know a path that is failing (for example an application log directory), ask findmnt which filesystem actually holds it. The result shows the mount point and device that the path really lives on.
findmnt --target YOUR_PATH
Compare what df says with what du can find
Run du as root, because as an ordinary user it skips directories it cannot read and quietly understates the total. The -x option keeps du on one filesystem, so it does not wander into other mounts and muddy the comparison. On a large tree this reads a lot of directory entries, so on a busy server run it outside peak hours.
Do not expect the two numbers to match exactly. Filesystem metadata and journals take space that du never lists. A gap of a few hundred megabytes is unremarkable. A gap of many gigabytes, or one that is a large fraction of the filesystem, means something is consuming space that normal directory listings cannot show.
- Replace YOUR_MOUNT_POINT with the mount point of the full filesystem from the previous step (for example /var). The output lists each top-level directory with its size, largest last.
sudo du -xh --max-depth=1 YOUR_MOUNT_POINT | sort -h - Add up the du total and compare it with the Used column from df for the same filesystem. If du accounts for most of it, the space is simply held by files you can see, and the largest directories in this list are where to look. If du is far lower, carry on with the next two sections.
Deleted files that a running service still holds open
This is the most common reason for a gap. Deleting a file removes its name from the directory, but if a running process still has it open, the data stays on disk and keeps using space until the process closes it or exits. du cannot count a file that no longer has a name, so the space vanishes from du while staying in df. Someone removing a huge log file by hand while the application is still writing to it is the classic cause: the file leaves the guest list but remains in the building.
lsof can list open files whose link count is zero, which is exactly this situation. Run it as root, otherwise it only shows your own processes.
- List unlinked open files on the full filesystem. Replace YOUR_MOUNT_POINT as before. Each line gives the process name, its PID, the file descriptor and the size; the name column typically ends with (deleted). Large entries are your suspects.
sudo lsof -nP +aL1 YOUR_MOUNT_POINT - Identify which service owns the biggest offender. If the PID belongs to a systemd service, this shows the unit name and its state.
systemctl status YOUR_PID - If anyone might need the contents of a deleted file, copy it out before releasing it. Open files can be read through the process's /proc entry, where YOUR_PID is the process ID and YOUR_FD is the file descriptor number from the lsof output. The destination must be on a different filesystem with enough free space, or you will make the shortage worse.
sudo cp /proc/YOUR_PID/fd/YOUR_FD YOUR_SAFE_DESTINATION - Restart the owning service during an agreed window, using the unit name from the previous step. This briefly interrupts that service, so check with whoever depends on it first. When the process lets go of the file, the space returns immediately; run df -h on the filesystem and the Used figure should drop by roughly the size lsof reported. The deleted data itself cannot be recovered afterwards, which is why the copy step comes first.
sudo systemctl restart YOUR_SERVICE
Hiding the evidence: truncating through /proc
You will find advice online to empty the open file directly through its /proc entry so no restart is needed. Red Hat's own guidance describes this as an advanced option and warns that applications can behave unpredictably or end up inconsistent when a file they have open is emptied underneath them. It is only reasonable for a plain append-only text log whose owner confirms the application never reads it back, and even then lines can be lost. For databases, queues and anything holding state, use a proper restart instead, or hand the decision to the application's owner.
Files hiding underneath a mount point
If lsof lists nothing useful, the next suspect is data buried under a mount point. When a filesystem is mounted on a directory, whatever was in that directory beforehand becomes invisible but keeps using space on the parent filesystem. This happens when a directory such as /home or /data is moved onto its own volume and old files are left behind, or when an application writes into the empty directory while the volume was not mounted and the mount then returns. df counts those blocks; du, which sees only the mounted contents, does not.
A bind mount lets you look at the parent filesystem without the other mounts on top of it. A bind mount attaches just that one filesystem, not the mounts beneath it, so the hidden files appear. It reads nothing destructive and does not stop services, but it does create a second view of live data, so avoid writing through it by accident and unmount it when you are finished.
- List current mounts with their devices, and note any directory that is a mount point for another filesystem and sits inside the full one. Those directories are where hidden data can sit.
findmnt -o TARGET,SOURCE,FSTYPE - Create an empty directory and bind-mount the full filesystem onto it. Replace YOUR_MOUNT_POINT with the mount point of the full filesystem; use / if it is the root filesystem.
sudo mkdir /mnt/fsview sudo mount --bind YOUR_MOUNT_POINT /mnt/fsview - Run du against the bind-mounted view. Directories that look empty or tiny in normal use but are large here are your hidden data.
sudo du -xh --max-depth=2 /mnt/fsview | sort -h | tail -n 20 - Decide what to do with what you find. Move it onto the correct filesystem rather than deleting it, unless its owner confirms it is disposable. Moving is reversible, and deleting is not.
- Unmount and remove the temporary directory.
sudo umount /mnt/fsview sudo rmdir /mnt/fsview - Run df -h on the filesystem again. The Used figure should have dropped by roughly the size of what you moved or removed.
df -h YOUR_MOUNT_POINT
If the gap is still unexplained
Work through these in rough order of likelihood. Each is a read-only check. Which apply depends on your filesystem and what the server runs.
- Inodes. If df -i shows the filesystem nearly out of inodes, the cause is millions of tiny files (session stores, mail queues, caches) rather than big ones, and du by size will never reveal it. This count of files per top-level directory is heavy on large filesystems, so run it off-peak. Delete only with the data owner's agreement.
sudo find YOUR_MOUNT_POINT -xdev -type f | cut -d/ -f1-3 | sort | uniq -c | sort -n | tail -n 10 - Reserved blocks on ext2/3/4. These filesystems set aside a percentage for privileged processes, normally 5% by default according to the tune2fs manual, so ordinary users can see Avail hit zero while Used is below 100%. This lists the block counts, including the reserved figure. Changing the percentage is possible but is a trade-off against fragmentation and the ability of system daemons to keep working, so treat it as a considered change rather than a quick fix.
sudo tune2fs -l YOUR_DEVICE - Btrfs. df on Btrfs shows only a summary of allocations, and the Btrfs documentation points to btrfs filesystem usage for the real picture. Snapshots share blocks with the live data, so deleting a file from the live subvolume does not free blocks a snapshot still references. Look at the snapshot list with whoever manages them before removing anything.
sudo btrfs filesystem usage YOUR_MOUNT_POINT - LVM thin provisioning. If the volume sits on a thin pool, the pool can fill even though the filesystem inside looks fine. In lvs output, Data% or Meta% at or near 100 is serious: the lvmthin manual warns that a full pool leads to write errors, possible filesystem damage and lost unsynced data, and that the pool should be extended before either value reaches 100%. Escalate immediately rather than experimenting.
sudo lvs - Containers. Docker stores images, container writable layers and volumes under /var/lib/docker, and its documentation specifically warns against manipulating files there directly. docker system df gives a summary by images, containers and local volumes, and the verbose form breaks it down. Use Docker's own commands to clean up, not rm.
sudo docker system df - systemd journals. Journals can grow large under /var/log/journal. journalctl --disk-usage reports the total for archived and active journal files. Vacuuming (--vacuum-size, --vacuum-time) deletes archived journal files permanently, so confirm your log retention needs first.
journalctl --disk-usage
Checking it worked, and when to hand over
You are done when df -h for the affected filesystem shows a Used figure that has fallen by roughly the amount you found, df -i is healthy, and the application that was failing writes normally again. If the service still reports errors after space has returned, restart it and check its own logs, because some applications do not recover on their own after a disk-full event.
If you have checked open deleted files, mounts, inodes and the filesystem-specific causes above and df still disagrees with du by a large margin, stop there. Filesystem repair tools need the filesystem unmounted, which means planned downtime, and running them on a live volume is not safe. That, and anything involving a thin pool near 100%, is the point to hand over to a storage or systems specialist with your df, du and lsof output in hand.
Technical terms explained
- bind mount
- A way to make an existing directory or filesystem visible at a second path. It lets you view a parent filesystem without the mounts layered on top of it.
- inode
- A record the filesystem keeps for each file or directory, holding details such as ownership and where the data lives. A filesystem has a fixed number of them and can run out even when space remains.
- link count
- The number of directory names pointing at a file. When it reaches zero the file has no name, but its data stays on disk while a process still has it open.
- mount point
- A directory where a separate filesystem or disk volume is attached. Whatever the directory held before the mount is hidden while the mount is active.
- reserved blocks
- Space that ext2, ext3 and ext4 filesystems set aside for privileged processes, 5% by default. Ordinary users cannot use it, so they can run out of space before df shows 100% used.
- snapshot
- A point-in-time view of a filesystem or volume that shares data blocks with the original. Blocks a snapshot still references are not freed when the live copy is deleted.
- thin pool
- An LVM storage pool whose volumes are allocated on demand rather than up front. The pool can fill up while the filesystems inside it still report free space.
Sources and further reading
- df(1) - Linux manual page
- du(1) - Linux manual page
- lsof(8) - Linux manual page
- Red Hat: Why is space not being freed from disk after deleting a file in Red Hat Enterprise Linux?
- Red Hat: Linux disk usage diagnostics
- mount(8) - Linux manual page
- findmnt(8) - Linux manual page
- tune2fs(8) - Linux manual page
- Btrfs documentation: Filesystem commands (btrfs filesystem usage)
- Btrfs documentation: Subvolumes and snapshots
- lvmthin(7) - Linux manual page
- Docker docs: OverlayFS storage driver
- Docker docs: docker system df
- journalctl(1) - Linux manual page