Your site suddenly returns error 500, MySQL refuses to start,
apt stops halfway, and the logs keep repeating the same line: No space left on device. The VPS disk is full. It sounds scary, but the culprit is almost always one of a few well-known ones, and it takes about 10 minutes to fix.1. Check how much space is left
Code: Select all
df -h/ (the main disk). If Use% is at or near 100%, you are out of space.Then check the inodes too. That is the number of files the disk can hold, and sometimes they run out before the space does:
Code: Select all
df -iIUse% is 100%, the problem is not big files but millions of small ones: usually the cache, sessions or temporary files of some application.2. Find what takes the space
This command shows the size of every folder in the root, with the largest at the bottom:Code: Select all
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h/var:Code: Select all
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -hncdu is more convenient: it gives you a menu you move through with the arrow keys:Code: Select all
sudo apt install ncdu # Ubuntu / Debian
sudo dnf install ncdu # Rocky / AlmaLinux
sudo ncdu -x /3. The five most common culprits
System logs (journald)
See how much space they take:Code: Select all
journalctl --disk-usageCode: Select all
sudo journalctl --vacuum-size=200M
Package cache and old kernels
Code: Select all
sudo apt clean && sudo apt autoremove --purge # Ubuntu / Debian
sudo dnf clean all # Rocky / AlmaLinux
Docker
Docker quietly piles up old images, stopped containers and build cache. First see how much:Code: Select all
docker system dfCode: Select all
docker system prunedocker system prune -a --volumes also deletes every image without a running container and every volume without a container, and volumes often hold the database. Do not run it unless you are sure what is in them.Separately, container logs grow without limit. See which ones are large:
Code: Select all
sudo du -sh /var/lib/docker/containers/*/*-json.log | sort -h | tail
WordPress
The most common places in wp-content:wp-content/cache: the cache of a caching plugin, which you can clear from the plugin itselfwp-content/updraft,ai1wm-backupsand similar: plugin backups that sit on the same disk and grow every monthwp-content/uploads: images, often uploaded at full size
Code: Select all
sudo du -sh /var/www/*/wp-content/* 2>/dev/null | sort -h | tail
A deleted file that still takes space
You deleted a big log, but df still shows a full disk? Some process still holds the file open, and the space is not freed until the process lets go of it:Code: Select all
sudo lsof +L1COMMAND column (for example sudo systemctl restart nginx) and the space comes back.Next time, do not delete a big log that is being written; empty it instead:
Code: Select all
sudo truncate -s 0 /path/to/file.log4. How to keep it from happening again
A limit for journald. In/etc/systemd/journald.conf set:Code: Select all
SystemMaxUse=200Msudo systemctl restart systemd-journaldA limit for Docker logs. In
/etc/docker/daemon.json:Code: Select all
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}sudo systemctl restart docker. It applies to new containers; existing ones need to be recreated.An alert before it is too late. If you are a VPSStorages customer, the free Monitoring add-on checks every 5 minutes whether the disk is over 90% and sends you an email. That way you find out in time, not from your clients. More: simple monitoring in 15 minutes.
5. If you simply need more space
Sometimes nothing is unnecessary; the project has simply grown. At VPSStorages you can request a plan change from the portal: Start → Plus → Power, and each next plan has a bigger disk. Your data, IP address and SSH port stay the same, and the main partition grows by itself on the next start.
In short
df -handdf -i: space or inodes?duorncdu: which folder?- Logs, package cache, Docker, WordPress backups, deleted but open files
- Limits for the logs and an alert at 90%