If you are dealing with too many files and directories or if you have many important files that cannot be deleted, you will see the error message “no space left on device” often. This error can be very dangerous for daily operations if you are an individual user. In enterprise applications, if this error pops up, it means that either the disk management is not proper or in most cases, there is an unexpected surge in space utilization. Either way, it is important to understand what this error message means and how to resolve it. In this article, we are going to learn exactly that.
What Does the Error Message “No Space Left on Device” Mean?
Linux devices throw up this error not only when they run out of space. When this error shows up, the primary reason can be that the hard disk is full. There are two reasons and they are:
- Unavailable or low disk space: When the physical disk space on the storage device has been completely used, this error message can pop up.
- Unavailable inodes: Inodes are the data structures that are used to store the information about files and directories. You can have plenty of disk space available but if your system has run out of inodes, new files cannot be created.
Understanding these two causes will help the diagnosis part easier and eventually the troubleshooting part gets much easier.
How to Diagnose the Issue?
Before we see the ways to fix the “no space left on device” error message, let us see how we can diagnose where the error lies. It is important to know if this is a disk space issue or an inode issue.
How to Check the Disk Space
You can use the “df” command to see the available disk space in your Linux system. Here is the basic command for that:
The flag “-h” makes sure that the output you see is human readable. The output shows the available and the used space in either GB or MB. The command shows how much storage is used on each mounted filesystem.
How to Check Inodes
If the earlier command shows that the disk space is fine and the issue still occurs, check for available inodes by executing the command:
This command will show the inode usage on each filesystem. If the inode usage of a filesystem reaches 100%, the system cannot create any new files even if there is enough space left on the disk.
Why does the Error Message No Space Left on Device Show Up
- Huge log files: Some log files keep growing without bounds and can take up a considerable portion of disk space.
- Temporary files accumulation: Too many temporary files like cache can accumulate and take up valuable disk space.
- Backups: Though backups and dump files are important, it is essential to keep an eye on them. You can employ practices like incremental backups to keep the size of these files in check.
- Unwanted files: These files are also called orphaned files which are files that were not properly deleted. When you use containerized environments like Kubernetes, this error is more common.
- Too many small files: When there are too many small files, the inodes are easily exhausted.
How to Fix this Error
Here are some easy ways to fix the no space left on device error.
Clear up Disk Space
First solution is to clean up the disk and remove any unwanted files. This helps to reclaim disk space. To do this, you can start by deleting unnecessary files. Identify large files and directories by executing the “du” command:
This command locates large files and directories. You can start by deleting obsolete backups, logs, and any temporary files.
Review Log Files
Log files, which are usually stored in the var-log directory, can grow to unexpected sizes if they are left unchecked. Use the sudo truncate command to clear logs.
This command sets the file size to 0 but does not delete the file. This is useful if an application requires the file to exist but does not care about its contents.
Remove Unwanted Packages
Old Kernels and unused packages can lead to bloating of your disk space. Execute this command to free up some space:
How to Free Up Inodes
If the problem is not with disk space and it is about unavailable inodes, let us see how to fix that as well.
How to Identify Directories with Too Many Small Files
Execute the “find” command to locate the directories with a large number of small files. The find command will show the directories with the highest number of files. Once the directories are identified, review the unwanted files and remove them.
Remove Temporary and Cache Files
In some cases, temporary files including the cache files can accumulate too much space and take up both disk space and inodes. Remove them by executing sudo rm commands on the tmp and var/cache directories
Wrapping Up
The no space left on device is a fairly easy to fix error message once you know the reason for it. With the solutions given in this article, that error message will not bother you anymore.
Some More Articles That Would Be of Interest to You
- Best practices for securing Office365 on Linux
- Distrobox: Manage your Linux Distros like a pro
- RHEV: Unleashing the Power of Enterprise Virtualization
Related Link
Chapter 12. Managing Disk Storage | Red Hat Product Documentation