Management Guides Troubleshooting

"No Space Left on Device" on Linux: Find the Cause and Fix It

The three causes of "No space left on device" on a Linux VPS (full disk, no inodes, deleted files still open) and how to fix each, including Docker logs and database binary logs.

"No space left on device" means a write failed because a filesystem is full. On a VPS it usually arrives as a side effect: the database will not start, uploads fail, logins stop working, or updates abort halfway. The error has three possible causes, and the fix depends on which one you have: the disk is out of space, it is out of inodes, or space is held by files that were deleted but are still open.

Commands are given for Ubuntu 26.04/24.04 and Debian 13 (apt) and for AlmaLinux and Rocky Linux 9 and 10 (dnf). They are standard tools from each distribution; this guide is a reference and was not run on a test server for this article.

Step 1: which of the three is it?

df -h      # space
df -i      # inodes
What you seeCauseGo to
df -h shows a filesystem at 100%Out of spaceStep 2
df -h has room, df -i shows IUse% at 100%Out of inodes: too many small filesStep 5
df -h says full, but the files you can find add up to much lessDeleted files still held openStep 4

Note which mount point is full. A full /boot or /tmp needs different files removed than a full /.

If the disk is so full that commands fail, free a little space first with something safe: sudo journalctl --vacuum-size=100M, or sudo apt clean / sudo dnf clean all.

Step 2: find what is using the space

sudo du -xh / --max-depth=1 2>/dev/null | sort -h | tail -15

-x stays on one filesystem. Repeat the command on the largest folder (for example /var, then /var/lib) until you reach the culprit. To list single large files:

sudo find / -xdev -type f -size +200M -exec ls -lh {} + 2>/dev/null

If it is installed, ncdu does the same interactively: sudo ncdu -x /.

Step 3: the usual culprits and how to clear them

Logs. Do not delete a log that a running program is writing to; empty it instead, so the program keeps a valid file.

sudo journalctl --disk-usage
sudo journalctl --vacuum-time=14d
sudo truncate -s 0 /var/log/some-huge.log

To stop the journal growing back, set SystemMaxUse=500M in /etc/systemd/journald.conf and restart systemd-journald. For application logs, check that a logrotate rule exists in /etc/logrotate.d/.

Package caches and old kernels.

# Ubuntu, Debian
sudo apt clean
sudo apt autoremove --purge

# AlmaLinux, Rocky Linux
sudo dnf clean all
sudo dnf autoremove

Docker. Images, stopped containers, build cache and container logs are the most common cause on servers that run Docker.

docker system df
docker system prune           # stopped containers, unused networks, dangling images
docker image prune -a         # also images not used by any container
docker builder prune

Read each prompt before confirming. docker system prune --volumes also deletes unused volumes, which is where databases keep their data; do not add that flag unless you are sure.

Container logs have no size limit by default. Set one in /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}

Restart Docker afterwards. The limit applies to containers created from then on, so recreate existing ones.

Database files. MySQL and MariaDB binary logs can grow to many gigabytes. Never delete them by hand; ask the server to do it:

mysql -e "SHOW BINARY LOGS;"
mysql -e "PURGE BINARY LOGS BEFORE NOW() - INTERVAL 7 DAY;"

Set an expiry (binlog_expire_logs_seconds on MySQL 8, expire_logs_days on MariaDB) so that it does not recur. If nothing replicates from this server and you do not use point-in-time recovery, binary logging may not be needed at all.

Backups stored on the server itself. Old dump files and archive copies in /root, /home or /var/backups. Move them off the server; they should not be there in the first place.

Application caches and temporary files: page caches, image thumbnails, /tmp, failed uploads, core dumps in /var/lib/systemd/coredump.

Step 4: space held by deleted files

When a file is deleted while a program still has it open, the name disappears but the space is not released until the program closes it. This is what happens when someone removes a large log with rm while the service is running.

sudo lsof +L1

The output lists open files with no remaining name, with their size and the process holding them. Restart or reload that service (for example sudo systemctl restart nginx) and the space returns.

Step 5: out of inodes

Each file uses one inode, whatever its size. A filesystem with millions of tiny files can run out of inodes with gigabytes free. Find the folder with the most files:

sudo find / -xdev -type f 2>/dev/null | cut -d/ -f2-4 | sort | uniq -c | sort -n | tail -15

Typical sources are PHP session files, cache folders, mail queues and spool folders. Delete old files by age, not all at once by wildcard, which can fail with "argument list too long":

sudo find /var/lib/php/sessions -type f -mtime +7 -delete

Check the path first by running the same command without -delete. Then fix the cause: a missing cleanup job, or a cache with no limit.

Step 6: when the disk is simply too small

If everything on the disk is needed, upgrade the plan or attach a volume. After a plan upgrade the disk is bigger but the partition and filesystem often are not. Check with lsblk; if the partition is smaller than the disk:

sudo growpart /dev/vda 1          # grow partition 1 (cloud-guest-utils / cloud-utils-growpart)
sudo resize2fs /dev/vda1          # ext4
sudo xfs_growfs /                 # XFS (default on AlmaLinux, Rocky Linux)

Device names differ between providers (/dev/sda, /dev/vda, /dev/nvme0n1); use what lsblk shows. Take a snapshot before resizing.

Keep it from happening again

  • Alert at 80% disk and inode usage. The maintenance checklist has a script that reports both.
  • Limit the journal, Docker logs and database binary logs as shown above.
  • Send backups off the server and keep only a few days locally. See VPS backup strategy.
  • Look at df -h once a week. Disks fill gradually, and the trend is visible long before the outage.

Frequently asked questions

Why does df show the disk full when du shows less?

Usually deleted files that are still open (step 4). Less often, files hidden underneath a mount point, or the 5% of space ext4 reserves for root.

Is it safe to delete everything in /var/log?

No. Services expect their log files and folders to exist. Truncate large files and let logrotate and the journal limits manage the rest.

Why will MySQL not start after the disk filled up?

It needs free space to write its logs and temporary files. Free space first, then start it and check its error log; a table may need repair if a write was interrupted.

Can a full disk slow the server down before it stops?

Yes. See Why Is My VPS Slow? for how disk problems show up in performance.

Share story:

Continue reading other guides on How VPS.