Home Issue How to Fix the “No space left on device” Error on Ubuntu

How to Fix the “No space left on device” Error on Ubuntu

Last updated on Aug 06, 2026

The No space left on device error means that a filesystem has no usable space left. It can prevent SSH jobs, deployments, package updates, database writes, log files, and uploads from completing. The message may also appear when the disk still has free space but all filesystem inodes are exhausted.

1. Check disk space and inodes

Start by checking all mounted filesystems:

df -h

Check inode usage as well:

df -i

If Use% is close to 100% in df -h, the filesystem is full. If IUse% is 100% in df -i, too many small files have consumed the available inodes.

2. Find what is using the space

To inspect the largest top-level directories without crossing into other mounted filesystems, run:

sudo du -xhd1 / 2>/dev/null | sort -h

Then inspect the directory that is consuming the most space. Common locations include /var, /home, /tmp, application upload directories, backups, Docker data, and log directories. For example:

sudo du -xhd1 /var 2>/dev/null | sort -h

Do not delete files only because they are large. Confirm that they are old logs, caches, temporary files, or obsolete backups before removing them.

3. Use ncdu to analyze disk usage

ncdu (NCurses Disk Usage) provides an interactive way to browse directories, identify large files, and remove unnecessary data.

Install it on Ubuntu if it is not already available:

sudo apt update
sudo apt install -y ncdu

Run it in the current directory:

ncdu

Or scan a specific directory:

ncdu /path/to/directory

For a full server scan, use:

sudo ncdu /

You can also inspect /var directly:

ncdu /var

Use the arrow keys to navigate, press Enter to open a directory, and press the left arrow to go back. Select a file or directory and press d to delete it, then confirm the action. Deletion cannot be undone, so double-check the path before confirming. Press q to exit.

4. Clean up safe, known data

After identifying the cause, remove only data that is no longer needed. Examples include package-manager caches and old systemd journal entries:

sudo apt clean
sudo journalctl --vacuum-time=7d

For application logs, use the application or service's own log rotation and cleanup mechanism where possible. Avoid deleting active log files or database files manually.

If the server uses Docker, first review its usage:

docker system df

Only after confirming that unused images, containers, or volumes are safe to remove, use the relevant Docker prune command. Volumes may contain persistent application data, so do not remove them blindly.

5. Check for deleted files still held open

A process can keep a deleted file open, so df -h may remain full even after the file is removed. Find such files with:

sudo lsof +L1

Restart the service that still holds the deleted file open, or restart the server during an approved maintenance window. Verify the result afterwards with df -h.

6. Verify the filesystem

Run these commands again after cleanup:

df -h
df -i

Then retry the failed deployment, SSH job, package update, or application operation. Keep some free space available for logs, temporary files, package updates, and database operations. If the filesystem fills repeatedly, configure log rotation, review backup retention, increase the disk size, or move large data to a dedicated volume.

Warning: Never remove system directories, database files, active application data, or server configuration files unless you have confirmed their purpose and have a recoverable backup.