How to Fix “No Space Left on Device” on Linux
Your server suddenly can't save files, install updates or keep its database running. Here's how to find what filled the disk, free space safely in a few minutes, and stop it from happening again.

One day everything on your server starts failing at once. apt upgrade stops halfway, the database goes down, your app can't write its log, and even saving a file in nano fails. Somewhere in the output you find the same line:
No space left on device
The disk is full. It happens a lot on VPS plans with small disks, and the cause is usually something boring: logs that were never rotated, an old package cache, Docker images nobody uses any more. This guide shows you how to find what filled the disk, free space safely, and make sure it doesn't happen again.
One tip before you start: when the disk is full, commands that install things will fail too. Free some space first, then install any tools you want.
Step 1: Check Which Disk Is Full
df -h
You'll see one line per filesystem. Look at the Use% column and the Mounted on column:
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 25G 25G 0 100% /
tmpfs 987M 0 987M 0% /dev/shm
Here the main disk, mounted on /, is at 100%. That's the one to clean. Lines like tmpfs live in memory and don't matter here.
If no disk is close to 100% but you still get the error, skip to the section about inodes further down.
Step 2: Find What Is Using the Space
This lists the biggest folders at the top level of the disk, largest last:
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -n 15
The -x keeps du on this one disk, so it doesn't count other mounts. Take the biggest folder and look inside it the same way, for example:
sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -n 15
Keep going one level deeper until you find the real culprit. If you've already freed a little space, ncdu makes this much faster: install it with sudo apt install ncdu and run sudo ncdu -x / to browse folders by size with the arrow keys.
These are the places that fill up most often:
| Folder | What is usually there | Safe fix |
|---|---|---|
/var/log/journal | The systemd journal | journalctl --vacuum-size (Step 3) |
/var/log | Old and oversized log files | Delete rotated logs, empty large ones (Step 3) |
/var/cache/apt | Downloaded package files | apt clean |
/var/lib/docker | Unused images, stopped containers, build cache | docker system prune |
/var/lib/mysql | MySQL or MariaDB binary logs | PURGE BINARY LOGS (never delete them by hand) |
/var/lib/snapd | Old snap versions | Keep fewer versions (below) |
/home, /root | Backups, database dumps, downloads | Move them off the server or delete them |
Step 3: Free Space Safely
Work through these in order. Check df -h after each one; you may not need them all.
Clean the package cache
On Ubuntu and Debian:
sudo apt clean
sudo apt autoremove --purge
The first command deletes downloaded package files. The second removes packages nothing needs any more, including old kernels. On AlmaLinux and Rocky Linux, use sudo dnf clean all and sudo dnf autoremove.
Shrink the systemd journal
See how much space the journal takes, then cut it down to 200 MB:
journalctl --disk-usage
sudo journalctl --vacuum-size=200M
Remove old logs, and empty big ones instead of deleting them
Rotated logs end in .gz or a number. They're old copies and safe to delete:
sudo find /var/log -type f \( -name "*.gz" -o -name "*.[0-9]" \) -delete
If one log that's still in use has grown huge, empty it rather than deleting it:
sudo truncate -s 0 /var/log/nginx/access.log
This matters. If you delete a file that a program still has open, the program keeps writing to it and the space is not freed until that program restarts. Emptying it frees the space immediately.
Clean up Docker
Docker is one of the most common reasons a disk fills up. See what it's using first:
docker system df
docker system prune
docker system prune removes stopped containers, unused networks, dangling images and build cache, and asks before it does anything. Add -a to also remove every image no running container uses. Be careful with --volumes: volumes often hold real data, such as databases.
MySQL or MariaDB binary logs
If /var/lib/mysql is full of files named binlog.000123 or mysql-bin.000123, remove old ones from inside the database, never with rm:
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;
To stop them piling up, set binlog_expire_logs_seconds (MySQL 8) or expire_logs_days (MariaDB) in the server's configuration. If you use replication, make sure every replica has read the logs before you purge them.
Old snap versions
Snap keeps up to three versions of each app by default. Two is enough:
sudo snap set system refresh.retain=2
You Deleted Files but the Space Didn't Come Back
This is the classic case of a deleted file that is still open. The name is gone, but a running program still holds the file, so the disk space stays in use. Find those files with:
sudo lsof +L1
The COMMAND column tells you which program holds each one. Restart that service and the space comes back:
sudo systemctl restart nginx
If you can't restart it right now, you can empty the file through the process instead. Take the PID and the number in the FD column (without the letter after it) and run:
sudo truncate -s 0 /proc/PID/fd/FD
Disk Not Full? Check the Inodes
Every file uses one inode, and a filesystem only has a fixed number of them. Millions of tiny files can use them all up while df -h still shows free space. Check with:
df -i
If IUse% is at or near 100%, find the folder with the most files:
sudo du --inodes -x --max-depth=1 / 2>/dev/null | sort -n | tail -n 10
The usual suspects are PHP session folders, application cache folders and a stuck mail queue. For example, to delete PHP sessions older than two days:
sudo find /var/lib/php/sessions -type f -mtime +2 -delete
Things You Should Never Delete by Hand
- Database files in
/var/lib/mysqlor/var/lib/postgresql. Use the database's own tools. - Files in
/boot. Remove old kernels withapt autoremoveso the boot menu stays correct. - Anything inside
/var/lib/docker. Usedocker system pruneinstead. /procand/sys. They aren't real files on the disk and take up no space.
Stop It From Happening Again
Limit the journal for good
Open /etc/systemd/journald.conf, set this line under [Journal], then restart the journal:
SystemMaxUse=200M
sudo systemctl restart systemd-journald
Rotate your own app's logs
Most packages rotate their logs already. Your own app may not. Create /etc/logrotate.d/myapp:
/var/log/myapp/*.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
}
This keeps seven days of compressed logs. copytruncate empties the live log instead of moving it, so the app keeps writing without a restart.
Limit Docker container logs
By default a container's log grows without limit. Add this to /etc/docker/daemon.json and restart Docker with sudo systemctl restart docker:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}
It applies to containers created after the change, so recreate your existing ones when you next update them.
Get warned before it's full
Run df -h now and then, or better, set an alert at 80 to 85% in your monitoring tool. A warning a week early is much better than a database that stops at 3 a.m.
And if your server simply needs more room, a bigger disk is the real fix. On NodexVPS you can upgrade to a larger plan in place and keep all your data.
Quick Checklist
df -hto find the full disk,df -iif it isn't full.du -xh --max-depth=1orncdu -x /to find the folder.apt clean,journalctl --vacuum-size=200M, old.gzlogs.docker system pruneif you use Docker.lsof +L1if deleted files still take space.- Limit the journal, rotate logs and set a disk alert so it doesn't come back.
A full disk feels like an emergency, but it's almost always fixable in a few minutes. Find the folder, clean it the safe way, and put limits in place so you only have to do this once.