How to Fix "No Space Left on Device" Errors

A full disk can silently break databases, log writing, package installations, and web applications. This guide covers quickly identifying and freeing up space, plus preventing recurrence.

Step 1 — Confirm the Disk Is Actually Full

df -h

Look for any filesystem at or near 100% under the Use% column.

Step 2 — Rule Out an Inode Problem (Different from Disk Space)

df -i

If inodes are exhausted despite free disk space showing available, the cause is usually millions of small files (often cache or session files), not large files.

Step 3 — Find What's Using the Space

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

Then drill into the largest directory to narrow it down further. See How to Check and Manage Disk Usage on a Linux VPS for the full workflow, including the ncdu interactive tool.

Step 4 — Common Quick Wins

Clear the package manager cache:

sudo apt clean
sudo apt autoremove -y

Trim the systemd journal:

sudo journalctl --vacuum-time=7d

Clean up Docker (if installed):

docker system prune -a

Remove old log files:

sudo find /var/log -name "*.gz" -mtime +30 -delete

Step 5 — Check for a Runaway Log File

sudo find /var/log -type f -size +500M -exec ls -lh {} \;

If found, don't delete an actively-written log outright — truncate it instead to avoid breaking the writing process:

sudo truncate -s 0 /var/log/offending-file.log

Step 6 — Check for Deleted Files Still Held Open

Sometimes deleting a large file doesn't actually free space because a running process still has it open:

sudo lsof +L1

Restart the identified process to release the space.

Step 7 — Verify the Fix

df -h

Step 8 — Restart Any Services That Failed Due to the Full Disk

sudo systemctl restart mysql
sudo systemctl restart nginx

Databases in particular often need a restart after a disk-full event, even once space is freed.

Preventing This from Happening Again

  • Set journal size limits — see How to Read and Analyze Linux Logs with journalctl
  • Set Docker log rotation limits — see Managing Docker Logs
  • Monitor disk usage proactively with a scheduled check rather than discovering it during an outage
  • Ensure backup scripts properly clean up old backups (check your retention/cleanup commands are actually working)

Common Errors

"No space left on device" persists after freeing space — check inode usage (df -i) as the real cause, not raw byte usage.

Space wasn't actually freed after deleting files — a process is still holding the file open; find and restart it with lsof +L1.

Related Articles

  • How to Check and Manage Disk Usage on a Linux VPS
  • Managing Docker Logs
  • How to Choose the Right VPS Plan for Your Workload
  • disk full, no space left on device, disk usage, linux troubleshooting
  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

Website Down? A Step-by-Step Troubleshooting Checklist

When a website goes down, working through checks in the right order saves critical time. This...

VPS Unreachable/Can't Connect via SSH: Troubleshooting Guide

Losing SSH access to your VPS is stressful, but most causes are fixable without needing to...

How to Diagnose and Fix High CPU Usage on a VPS

Sustained high CPU usage can slow down your entire server and every application running on it....

How to Diagnose and Fix Out of Memory (OOM) Errors

When a Linux server runs out of available RAM, the kernel's OOM (Out of Memory) killer forcibly...

How to Troubleshoot DNS Propagation Issues

DNS changes don't take effect everywhere instantly — caching at multiple levels means...