Exclusive Metin2 game shield on FreeBSD: Automatic siege mode, VIP list, and whitelist from your dashboard. See how it works
Create a server

Guide

How to Fix the "No Space Left on Device" Error in Linux

The message No space left on device appears when MySQL stops writing, Nginx cannot save its logs, or apt fails in the middle of an installation. It does not always mean that the disk is full of data: there are three different causes, and each is resolved differently.

First, figure out which of the three causes applies to you

Compare the use of blocks (space) with that of inodes (number of files):

df -hTdf -i
  • 100% utilization in df -hT: no free blocks remain. Continue in Section A.
  • There is free space, but IUse% is 100% full in df -i: the inodes have been exhausted. Go to section B.
  • df says the disk is full, but du doesn't find that much data: there are deleted files that some process is keeping open. Section C.

A. The disk is full of data

Find the largest folders without leaving the root partition (-x excludes other mounted file systems):

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

On a VPS, these are the usual suspects—and here's the safe way to eliminate them.

systemd log entries

journalctl --disk-usagesudo journalctl --vacuum-size=200M

To prevent it from growing indefinitely again, add the line SystemMaxUse=200M to the file /etc/systemd/journald.conf and restart the service using sudo systemctl restart systemd-journald.

Cache of apt and kernels you no longer use

sudo apt cleansudo apt autoremove --purge

Docker Images and Layers

docker system dfdocker image prune -adocker builder prune

docker image prune -a Deletes all images that are not used by any container, including those from stopped containers that you plan to restart. Check docker ps -a first.

Application logs

If an active log file is several GB in size, flush it instead of deleting it; that way, the process continues to write to the same file:

sudo truncate -s 0 /var/log/nginx/access.log

B. We've run out of inodes

Every file uses up one inode, no matter how small it is. Millions of tiny files (PHP sessions, an application's cache, a backed-up mail queue) can use them all up even when the disk is half empty. Look for the folders with the most files:

sudo du --inodes -x -d 3 / 2>/dev/null | sort -n | tail -n 15

When you find the folder, delete files by age using find; a rm * on hundreds of thousands of files results in an "Argument list too long" error:

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

Then fix the source: a session collector that isn't running or a cache with no expiration time will fill it up again.

C. Deleted files that are still taking up space

If you deleted a huge log file using rm while the service had it open, the space isn't freed up until the process closes the file. List them:

sudo lsof -nP +L1

Column COMMAND indicates which service is holding the space. When you restart it (for example, sudo systemctl restart nginx), the space is immediately released.

What You Should Never Delete Manually

  • MySQL or MariaDB binlogs: Delete them from the database server itself using PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY; to ensure that the index remains consistent.
  • The contents of /var/lib/docker: Always use the prune commands; deleting folders in overlay2 corrupts the images.
  • /boot Files: Remove old kernels using apt autoremove, never rm.

ext step

If, after cleaning it up, the disk fills up again within a few weeks, the problem is one of capacity, not maintenance: choose a Cloud VPS with more storage.

Related guides