How to Fix No Space Left on Device Errors in Linux
Understanding No Space Left Errors
The "No space left on device" error occurs when your filesystem runs out of available disk space or inodes. This guide will help you diagnose and fix the issue quickly.
Quick Diagnosis
df -h # Check disk space
df -i # Check inode usage
du -h --max-depth=1 / 2>/dev/null | sort -hr | head -20Common Solutions
Clean Package Cache
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremoveClear Log Files
sudo journalctl --vacuum-time=3d
sudo find /var/log -name "*.gz" -mtime +30 -deleteRemove Old Kernels
sudo apt-get autoremove --purgeClean Docker
docker system prune -a --volumesFind Large Files
sudo find / -type f -size +100M 2>/dev/null | xargs ls -lhPrevention
- Set up log rotation in /etc/logrotate.conf
- Configure journal size limits
- Monitor disk usage with alerts
- Schedule cleanup scripts