No space left on device stops MySQL, breaks uploads, prevents logins and can corrupt files being written. The fix is to free space quickly and then find what filled the disk. This guide covers the usual suspects, plus two cases where df looks fine but the error persists.
Before you start
- Root access. If you cannot log in over SSH because the disk is full, use your provider's console.
- Do not delete files you do not recognise in system folders; follow the steps below.
Confirm which filesystem is full
df -hLook for Use% at 100% and note the mount point (/, /var, /home...). Then check inodes, which can run out even with free space:
df -iFind what uses the space
du -xh / --max-depth=1 2>/dev/null | sort -h | tail -15Drill into the largest folder by repeating with its path. ncdu -x / (install it with apt/dnf) gives an interactive view that is much faster to navigate. List single large files:
find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/nullQuick, safe clean-ups
| What | Command |
|---|---|
| Systemd journal | journalctl --vacuum-size=200M |
| APT package cache | apt clean && apt autoremove --purge |
| DNF cache | dnf clean all |
| Old rotated logs | find /var/log -name '*.gz' -mtime +14 -delete |
| Docker (unused images, stopped containers, build cache) | docker system prune |
| Old kernels (Ubuntu) | apt autoremove --purge |
Other common space hogs: forgotten backups in /root or /home, database dumps, MySQL binary logs (/var/lib/mysql/binlog.*; purge with PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY; rather than deleting files), application logs and cache folders, and mail queues.
Empty a huge log file safely
If one active log is enormous, truncate it instead of deleting it:
truncate -s 0 /var/log/myapp/huge.logThen add a logrotate rule so it does not happen again.
Space not freed after deleting files
A process still holding a deleted file keeps the space allocated. Find such files:
lsof +L1Restart the process listed (for example systemctl restart nginx) to release the space.
Inodes exhausted
If df -i shows 100% IUse, the disk has run out of file entries, usually from millions of tiny files (session files, cache, mail queue). Find directories with the most files:
for d in /*; do echo "$(find "$d" -xdev 2>/dev/null | wc -l) $d"; done | sort -n | tailTypical fixes: clear old PHP sessions (/var/lib/php/sessions), application cache folders, or a stuck mail queue.
Prevent it from happening again
- Set log rotation and a journal size limit.
- Keep backups off the server or rotate them.
- Limit Docker container logs in
daemon.json. - Add disk usage alerts (Netdata, a monitoring service or a cron script that emails above 85%).
- If the data genuinely grew, add storage or upgrade the plan, then extend the filesystem.
Troubleshooting
- MySQL will not start after the disk filled: free space first, then start it and check tables with
mysqlcheck --all-databases. - du totals are much smaller than df: deleted-but-open files (see above), or files hidden under a mount point.
- Disk fills again within hours: something writes continuously. Watch with
iotop -oaor compareduresults over time.
Disk space FAQ
How much free space should a server keep?
At least 10–20%. Databases and updates need room for temporary files.
Is it safe to delete files in /tmp?
Old files there are usually safe, but files in use by running programs should be left; deleting files older than a day is a reasonable rule.
Does this happen on cPanel hosting?
On shared hosting you hit your account's disk quota instead; check cPanel → Files → Disk Usage.
