All Products
Search
Document Center

Alibaba Cloud Linux:What do I do if the "No space left on device" error message appears when the disk usage of Ext4 file systems is low?

Last Updated:Apr 10, 2025

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.

  1. Mount the /dev/vdb disk whose usage is 1% to the /mnt mount point.

    Filesystem     Type      Size  Used Avail Use% Mounted on
    ...
    /dev/vdb       ext4      100G  308K   95G   1% /mnt
  2. Go to the /mnt directory and run the following command to create a file:

    sudo touch testfile.txt

    The 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 inodes usage and simplify file management.

  • Disadvantages: This solution may increase the complexity of accessing individual files.

Increase the number of inodes in the file system

Warning

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 inode density.

  • 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.

  1. Back up disk data. For more information, see Create a snapshot.

  2. Run the following command to unmount the file system that is mounted at /mnt:

    sudo umount /mnt
  3. Run the following command to create an Ext4 file system on the /dev/vdb disk:

    <bytes-per-inode> specifies the inode density. A smaller value indicates a higher inode density.

    sudo mkfs.ext4 -i <bytes-per-inode> /dev/vdb

    The 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 the inode density and the number of inodes. For example, set <bytes-per-inode> to 4 KB.

    sudo mkfs.ext4 -i 4k /dev/vdb