Disk full / inode issues
## Understanding disk vs. inode usage
A Linux filesystem tracks storage in two dimensions: disk blocks (space) and inodes (entries that record metadata for each file and directory). Even if you have free disk space, you cannot create new files once you exhaust the available inodes. Typical errors like “No space left on device” can mean either the disk or the inode table is full.
## Identify disk space problems
Use `df -h` to check how much space is used on each mounted filesystem. The `% Used` column shows if any partition is near 100%. To see which directories are consuming space, run `du -sh /*` for a summary or `du -ah / | sort -rh | head -20` to list the largest files and directories.
## Identify inode exhaustion
To check available inodes, run `df -i`. The `% Iused` column shows the percentage of inodes used. High inode usage usually comes from having many small files such as cache or email spools. To find the total number of files on a filesystem, you can use:
```
find / -xdev -type f | wc -l
```
## Free up disk space and inodes
- **Remove unnecessary log files** – compress or delete old logs in `/var/log` using `journalctl –vacuum-time=7d` or `rm -rf /var/log/*.gz /var/log/*.1 /var/log/syslog.*`. Force cleanup with `logrotate -f /etc/logrotate.conf`.
- **Clean package caches and old packages** – run `apt autoremove -y`, `dnf autoremove -y` or `pacman -Rns $(pacman -Qdtq)` to remove unused packages, and `apt clean`, `dnf clean all` or `pacman -Sc` to clear cached packages.
- **Purge temporary files** – delete stale files under `/tmp` and `/var/tmp` (`rm -rf /tmp/* /var/tmp/*`). You can mount `/tmp` as a tmpfs to clear it on reboot.
- **Delete cache and mail directories** – remove application caches, old email files and other small files that eat up inodes.
- **Find and remove large files** – locate large files with `find / -type f -size +500M -exec ls -lh {} + | awk '{print $9, $5}'` and remove those you no longer need.
- **Clean container and snap artifacts** – prune unused Docker images and volumes (`docker system prune -a` and `docker volume prune`) and limit retained snap revisions if you use these tools.
## Prevention & best practices
- Regularly monitor disk and inode usage with `df -h` and `df -i`.
- Configure log rotation and automated cleanup tasks via cron or systemd timers to remove old logs and temporary files.
- Avoid creating large numbers of tiny files; use databases or archive data to reduce inode consumption.
- When creating new filesystems, choose appropriate inode ratios to suit your workload or consider file systems that support dynamic inode allocation.
By following these steps, you can identify whether disk or inode exhaustion is causing “No space left on device” errors and safely free up resources without risking data loss.