Solving the "No Space Left on Device" Issue in Ubuntu
The "No Space Left on Device" error in Ubuntu can be a common issue, but it doesn't always mean that your disk is full. This error can also be caused by inode exhaustion – running out of available inodes, which track files. Here's a step-by-step guide on how to diagnose and fix this issue.
How to Diagnose
- Check disk space usage: Run This shows human-readable disk usage per mounted filesystem. If the Use% in the output is 100%, you have run out of disk space.
- Check inode usage: Run This shows inode usage. If the IUse% is 100%, your disk has available storage but no free inodes left. This is common when very many small files exist.
- Find directories with many files: For inode exhaustion, identify directories with huge numbers of files (each consuming an inode) with commands like: or to count files, as in the mail server example.
How to Fix
If disk space is exhausted:
- Clear system logs: This reduces system logs to manageable sizes and removes archived logs.
- Clear APT cache and unused packages: These commands remove cached package files and dependencies no longer needed.
- Remove temporary files: Remove files no longer accessed (safer): Or remove all (use with caution): This clears out temporary storage that might be filling the disk.
- Identify and remove large files or directories manually: Use disk usage tools such as: to find large files/directories to clean.
If inode exhaustion is the cause:
- Delete many small unnecessary files: Common areas to check:
- Mail queues, e.g.,
- Cache or temporary application data directories
- Large numbers of small logs or temporary files
- Avoid creating too many tiny files in application logic if possible.
- In extreme cases, reformatting the partition with a larger inode count can help, though this is disruptive and usually a last resort.
Verify Fix
After cleanup, re-check with: If free space or free inodes have increased and error no longer occurs, the issue is resolved.
Summary table:
| Step | Command(s) | Purpose | |---------------------|-----------------------------------------------|--------------------------------| | Check disk space | | See actual disk space usage | | Check inode usage | | See inode (file count) usage | | Clear logs | | Reduce log file sizes | | Clean APT cache | | Remove cached packages, deps | | Remove temp files | | Clear unused temp files safely | | Find large files | | Identify largest files | | Delete many small files | Use and remove unnecessary files | Free up inodes |
This method systematically diagnoses and fixes "No space left on device" errors due to both disk space and inode exhaustion on Ubuntu systems. Linux manages storage through both disk space (bytes) and inodes (metadata structures). The error can occur if either disk space is exhausted or the system has run out of inodes, even if there's still free space available. Selectively clearing small files in directories like home, usr, and var can free up inodes. Setting up log rotation (logrotate) and scheduling regular cleanups with cron can help prevent future occurrences of the "No Space Left on Device" error. Deleting temporary files with the command "sudo find /tmp -name '*' -mtime +7 -exec rm -rf {} \;" can help free up inodes. The command "find / -type f -exec du -sh {} +" scans the filesystem and counts files per directory. Checking inode usage again after cleaning unnecessary files can verify if the error has been resolved. Running the command "df -i" shows inode usage across all mounted filesystems. This guide provides steps to diagnose and fix the issue, whether it's due to large files filling up storage or too many small files consuming inodes. Each inode in Linux represents a file and contains information about the file's size, permissions, owner, and location. Removing old emails, cached files, and temporary data can consume thousands of inodes.
- Maintaining a lifestyle that involves home-and-garden activities may lead to the accumulation of numerous small files such as images, documents, and maintenance logs, thus causing inode exhaustion on a Ubuntu system.
- Incorporating technology solutions, like automating log rotation and cron jobs, can help prevent inode exhaustion by regularly cleaning up logs, cache files, and temporary data, ensuring a seamless lifestyle experience while managing the storage efficiently.