This topic describes the cause of and solutions to the issue that the "No space left on device" error message appears when the disk usage of Ext4 file systems is low.
Problem description
When you create a file in an Ext4 file system, the No space left on device error message appears despite low disk usage or available disk space.
Mount the
/dev/vdbdisk whose usage is 1% to the/mntmount point.Filesystem Type Size Used Avail Use% Mounted on ... /dev/vdb ext4 100G 308K 95G 1% /mntGo to the
/mntdirectory and run the following command to create a file:sudo touch testfile.txtThe following error message appears:
touch: cannot touch 'testfile.txt': No space left on device
Cause
When you create an Ext4 file system, the system internally maintains an inode table. Each time a file or directory is created, an inode is used. Even if the files are small and do not take up much storage space, you may receive the following error message when inodes in the inode table are used up: No space left on device. As a result, you can no longer create files or directories in the Ext4 file system. This issue often occurs in scenarios in which a large number of small files exist in an Ext4 file system.
Solutions
Use one of the following solutions to resolve the issue.
Delete unnecessary data
Delete unused small files to free up inodes and allow files or directories to be created.
Advantages: This solution is simple.
Disadvantages: This solution is a workaround that temporarily resolves the issue and is associated with risks.
Optimize the file storage method
For specific applications, we recommend that you combine multiple small files into a large file to decrease the inode usage, or compress multiple small files into a compressed package to save disk space and inodes.
Advantages: This solution can significantly reduce the
inodesusage and simplify file management.Disadvantages: This solution may increase the complexity of accessing individual files.
Increase the number of inodes in the file system
This solution involves re-creating the file system, which erases existing data on the disk. To prevent data loss, back up your disk data before you use this solution. For information about how to back up disk data, see Create a snapshot.
Increase the inode density to increase the number of inodes.
Advantages: This solution provides flexibility in configuring the
inodedensity.Disadvantages: Improper operations may result in data loss and pose high operational risks.
If inodes are frequently used up, consider reformatting the file system and adjusting the inode density during the reformatting process. In the following example, the /dev/vdb disk, which is mounted at the /mnt mount point, is used.
Back up disk data. For more information, see Create a snapshot.
Run the following command to unmount the file system that is mounted at
/mnt:sudo umount /mntRun the following command to create an Ext4 file system on the
/dev/vdbdisk:<bytes-per-inode>specifies the inode density. A smaller value indicates a higherinodedensity.sudo mkfs.ext4 -i <bytes-per-inode> /dev/vdbThe default value of
<bytes-per-inode>is 16 KB. If a large number of small files exist in a file system, you can decrease the value of<bytes-per-inode>to increase theinodedensity and the number of inodes. For example, set<bytes-per-inode>to 4 KB.sudo mkfs.ext4 -i 4k /dev/vdb