Error No space left on device (ENOSPC) in Linux
What does the ENOSPC error mean
The No space left on device error (error code ENOSPC) is a standard error in Linux systems that occurs when attempting to write data to a disk that has run out of free space. The abbreviation ENOSPC stands for Error NO Space PaCe — "no space on device."
This error can occur in any situation related to disk writing: when installing programs, creating files, updating the system, or working with databases.
Causes of the error
There are several main reasons for the ENOSPC error:
- Physical disk filling — there is truly no free space left on the partition.
- Exhaustion of inodes — the disk has run out of file descriptors (inodes), even if there is free space available.
- User quotas — a disk space quota has been set for a user account or group.
- Overflow of temporary directories — the directories
/tmpor/var/tmpare filled with temporary files.
Diagnosing the problem
Checking disk space usage
First, check how much space is available on the disks:
df -h
The result will show the usage of all mounted partitions:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 95G 5G 95% /
/dev/sdb1 500G 500G 0 100% /mnt/data
If the value in the Use% column is close to 100%, this confirms the lack of space.
Checking the number of inodes
Sometimes space runs out due to a large number of small files:
df -i
Example output:
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 655360 655360 0 100% /
If IUse% is 100%, it means that inodes have been exhausted, not the actual disk space.
Finding large directories
Find directories that take up the most space:
du -sh /* 2>/dev/null | sort -rh | head -10
For a more detailed analysis of a specific directory:
du -sh /var/*
Ways to solve the problem
Clearing system logs
System logs can take up a lot of space. Clear old logs:
# Clear journald (last 7 days)
sudo journalctl --vacuum-time=7d
# Clear old logs
sudo rm -rf /var/log/*.gz
sudo rm -rf /var/log/syslog.*
sudo truncate -s 0 /var/log/syslog
Clearing the package manager cache
Remove the cache of installed packages:
For Debian/Ubuntu:
sudo apt clean
sudo apt autoremove
sudo apt-get clean
For CentOS/RHEL:
sudo yum clean all
sudo dnf clean all
For Arch Linux:
sudo pacman -Scc
Removing old system kernels
If the system has not been updated for a long time, old kernels may take up a lot of space:
# For Ubuntu/Debian
sudo apt autoremove --purge
# For CentOS/RHEL
sudo package-cleanup --oldkernels --count=2
Clearing temporary files
Remove the contents of temporary directories:
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
Deleting large files
Find and delete large files manually:
# Find files larger than 100 MB
sudo find / -type f -size +100M -exec ls -lh {} \;
Warning: Before deleting any files, ensure that they are not system files or important for the operation of applications.
Expanding disk space
If cleaning up did not help, consider:
- Adding a new disk and mounting it to the system
- Expanding the existing partition (using
gpartedorresize2fs) - Creating symbolic links to a new partition
Preventing recurrence
To avoid the ENOSPC error in the future:
- Regularly clean the system — set up automatic cleaning of logs and caches.
- Set up log rotation — edit
/etc/logrotate.conf. - Monitoring — use monitoring systems (Prometheus, Zabbix) to track disk usage.
- Directory separation — place
/tmp,/var/log, and/homeon separate partitions.
Conclusion
The No space left on device (ENOSPC) error in Linux is a common problem faced by system administrators and users. In most cases, it can be resolved by cleaning the disk of unnecessary files: logs, caches, and temporary data. If regular preventive maintenance is performed on the system, the risk of this error occurring is minimized.
In cases of serious disk space issues, it is advisable to reconsider the data storage architecture and, if necessary, expand the disk subsystem.