Fix: disk full, find what is eating the space
A Linux filesystem reports 100 percent used or No space left on device. Find the culprit with df and du, check journals, package caches, Docker and deleted-but-open files, free space safely and add an alert.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
A service stops writing, a database refuses connections, apt fails, or a log fills with:
write error: No space left on device
FATAL: could not write to file "pg_wal/xlogtemp.1234": No space left on device
The fix has two halves: free enough space to get the system breathing again, then find out what grew and make sure you hear about it next time before it reaches 100 percent.
Step 1: which filesystem, and is it space or inodes?
df -h
df -i
Look at the Use% column in both. A filesystem can be out of inodes (the second command) while df -h shows space free; that happens when millions of tiny files pile up, typically in a mail queue, a session directory or a PHP cache. The rest of this article uses / as the example mount point; substitute yours.
Step 2: find the big directories
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -n 15
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -n 15
sudo find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null | sort -k5 -h | tail -n 20
-x (and -xdev for find) stay on one filesystem, so a mounted NAS or /proc does not pollute the numbers. Walk down one level at a time into the biggest entry until you reach the files. If ncdu is installed, sudo ncdu -x / does the same interactively and lets you delete from inside it. Careful: deleting from ncdu is immediate and permanent.
Step 3: the usual suspects
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
journalctl --disk-usage
sudo journalctl --vacuum-size=500M
sudo du -sh /var/cache/apt /var/lib/apt/lists
sudo apt clean
sudo du -sh /var/log
sudo ls -lhS /var/log | head
docker system df
docker system prune --volumes
sudo du -sh /var/lib/snapd /var/tmp /tmp ~/.cache
- Journal:
--vacuum-sizeremoves the oldest archived journal files until the total is under the limit. Careful: those logs are gone. SetSystemMaxUse=in/etc/systemd/journald.confso it does not grow back. - Package caches:
apt clean(ordnf clean all) deletes downloaded package files; they are re-downloaded when needed, so this is safe. - Logs that rotate by size but never got rotated: a single multi-gigabyte
error.logusually means a program logging the same error thousands of times a second. Fix the error, then truncate (see Step 4). - Docker: stopped containers, dangling images, build cache and unused volumes. Careful:
docker system prune --volumesdeletes every volume not attached to a running container, including databases of stopped stacks. Rundocker system prunewithout--volumesfirst and look atdocker volume lsbefore going further. - Old kernels on
/boot:sudo apt autoremoveon Debian and Ubuntu removes kernels that are no longer needed.
Step 4: the space that du cannot see
If df says the disk is full but du adds up to far less, something holds a deleted file open. The space is only returned when the last process closes it. Find the process:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo lsof -nP +L1 | sort -k7 -n | tail -n 10
+L1 lists files with fewer than one link, that is, deleted ones. Restart the process named in the first column (systemctl restart nginx, for example) and the space is freed. If you cannot restart it, truncate the file through the process’s file descriptor: with PID 1234 and FD 7 from the lsof output, run sudo truncate -s 0 /proc/1234/fd/7.
The second invisible case is data hidden under a mount point: files were written to /mnt/data while the disk was not mounted, then the mount covered them. Check with a bind mount of the root filesystem: sudo mkdir /mnt/rootfs && sudo mount --bind / /mnt/rootfs && sudo du -sh /mnt/rootfs/mnt/data, and unmount with sudo umount /mnt/rootfs afterwards.
For live log files, never rm them while the writer is running; that creates exactly the deleted-but-open problem above. Empty them in place instead:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo truncate -s 0 /var/log/nginx/error.log
Step 5: alert before it happens again
A disk that hit 100 percent will do it again. Add a Prometheus rule that fires on the trend, not only on the threshold, so there is time to act:
- alert: DiskFillingUp
expr: |
predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"}[6h], 24 * 3600) < 0
and node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes < 0.2
for: 30m
labels:
severity: ticket
annotations:
summary: "{{ $labels.instance }} {{ $labels.mountpoint }} will be full within 24h"
Without Prometheus, the Server health check script in the Linux admin section reports filesystems above a threshold, and a systemd timer can run it hourly. Either way, the goal is to hear about 85 percent on a Tuesday afternoon instead of 100 percent on a Sunday night.
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0102 Proxmox VE storage types: local, LVM-thin, ZFS, NFS and Ceph Proxmox VE stores disks, ISOs, templates and backups in storage pools defined in /etc/pve/storage.cfg. Learn the main storage types, what local and… Intermediate · Explains an idea · Linux Article Disks, LVM & filesystems · Storage 15 Oct 2026
- 0168 Server health check script: disk, memory and failed units A dependency-free bash script that checks disk and inode usage, available memory, load, failed systemd units and pending reboots, and exits non-zero… Intermediate · Cheat sheet · Linux Script Disks, LVM & filesystems · Services & systemd 15 Oct 2026
- 0169 Add a new disk: partition, format and mount it by UUID Find a new disk with lsblk, partition it with parted, create an ext4 or XFS filesystem and mount it permanently through /etc/fstab… Intermediate · Step by step · Linux Article Disks, LVM & filesystems 15 Oct 2026
- 0170 LVM explained: physical volumes, volume groups and logical volumes LVM puts a flexible layer between disks and filesystems, so you can grow volumes, add disks and take snapshots without repartitioning. Intermediate · Explains an idea · Linux Article Disks, LVM & filesystems 15 Oct 2026
- 0171 Extend an LVM logical volume and filesystem online (safe script) A bash script that grows the LVM volume behind a mount point, checks the filesystem type and free space first, and runs… Advanced · Step by step · Linux Script Disks, LVM & filesystems 15 Oct 2026
- 0172 Fix: No space left on device Writes fail because a filesystem is full, out of inodes, or holding space for deleted files that are still open. Find which… Beginner · Fixes an error · Linux Article Disks, LVM & filesystems 15 Oct 2026
Repos in the wild
- Uptime Kuma: self-hosted uptime monitoring louislam/uptime-kuma Uptime Kuma is a self-hosted monitoring tool with a web UI that checks websites, TCP ports, DNS, Docker containers and more, draws uptime history and sends alerts. One container is all it needs. GitHub
- Netdata: real-time, per-second monitoring with zero configuration netdata/netdata The Netdata repository: an agent that auto-discovers hundreds of metrics on Linux hosts, containers and common services, shows them per second in a built-in dashboard and ships with preconfigured alerts. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +4,829 chars