How to Fix Linux Error ENOSPC: No Space Left on Device
Quick Fix Summary
TL;DRRun `df -h` to check disk space and `df -i` to check inodes, then delete files or increase storage.
ENOSPC indicates the filesystem has no space for new data or metadata. This can be due to exhausted disk blocks or inodes, halting writes and potentially crashing applications.
Diagnosis & Causes
Recovery Steps
Step 1: Diagnose the Root Cause
First, identify if the issue is block space or inode exhaustion. Use `df` with different flags.
df -h
df -i Step 2: Free Up Block Space (If Disk is Full)
If `df -h` shows 100% use, find and remove large, unnecessary files. Start with common culprits like logs, caches, and temporary directories.
du -sh /* 2>/dev/null | sort -rh | head -10
sudo find /var/log -type f -name "*.log" -size +100M
sudo journalctl --vacuum-size=200M Step 3: Free Up Inodes (If Inodes are Exhausted)
If `df -i` shows 100% IUse, you have too many small files. Find directories with high inode counts and clean them.
sudo find / -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -rn
sudo find /path/to/suspect/dir -type f -delete Step 4: Prevent Recurrence & Proactive Monitoring
Implement log rotation, set up monitoring alerts for disk and inode usage, and schedule cleanup tasks.
sudo logrotate -f /etc/logrotate.conf
echo "*/30 * * * * root /usr/bin/find /tmp -type f -mtime +7 -delete" | sudo tee -a /etc/crontab Architect's Pro Tip
"For Docker hosts, `docker system prune -a -f` and setting log driver with `--log-opt max-size` in `/etc/docker/daemon.json` prevents ENOSPC from runaway container logs."
Frequently Asked Questions
My `df -h` shows free space, but I still get ENOSPC. Why?
This is classic inode exhaustion. Run `df -i`. You have free blocks but no free inodes (metadata entries) to create new files, directories, or symlinks.
What's the fastest way to clear space in a production emergency?
Target `/var/log`, `/tmp`, and container log directories (`/var/lib/docker/containers/*/*-json.log`). Use `truncate -s 0 <logfile>` to zero out large logs without deleting them, preserving file handles.
Can I increase inodes on a live filesystem?
No. Inode count is set at filesystem creation (`mkfs` with `-N`). You must back up data, recreate the filesystem with more inodes, and restore.