Skip to content

Linux Inode Exhaustion: Fix “No Space Left on Device”

Have you ever tried to create a file on a Linux VPS and received a No space left on device error, even though your disk still has several gigabytes of free space? The problem may not be your disk capacity. It could be Linux inode exhaustion.

In Linux, a filesystem needs both available storage blocks and available inodes to create files. If the filesystem runs out of inodes, applications may fail to upload files, create sessions, write cache data, or generate logs—even when df -h reports plenty of free space.

In this guide, you will learn how to diagnose Linux inode exhaustion, identify directories containing excessive numbers of files, clean up unnecessary data safely, and prevent the problem from recurring on your VPS.

What Is an Inode in Linux?

An inode is a filesystem data structure that stores metadata about a file or directory. This includes information such as ownership, permissions, file type, timestamps, and references to the file’s data blocks.

The filename itself is stored in a directory entry rather than directly in the inode.

Every regular file, directory, and symbolic link generally consumes an inode. Even an empty file needs one.

For example, a directory containing 500,000 small cache files can consume a substantial number of inodes even if those files occupy relatively little disk space.

This is why monitoring disk capacity alone is not always enough to understand filesystem problems.

Why Does Linux Report “No Space Left on Device”?

Linux filesystems manage storage capacity and inode availability separately.

  • Disk space exhaustion: The filesystem has insufficient free data blocks to store more content.
  • Inode exhaustion: The filesystem cannot allocate the required inode for a new filesystem object.

Consider a VPS with a 100 GB filesystem. The filesystem might use only 25 GB of storage while nearly all available inodes are consumed by millions of small files.

In that situation, the server may be unable to create new files despite having approximately 75 GB of free disk capacity.

Common causes include:

  • Application cache directories containing excessive files.
  • PHP session files that are never removed.
  • Temporary files generated by scripts or scheduled tasks.
  • Website upload directories containing thousands of small files.
  • Mail queues and mail-storage directories.
  • Application logs split into many individual files.
  • Failed deployment jobs leaving behind temporary files.
  • Applications repeatedly generating files without proper cleanup.

The exact inode behavior also depends on the filesystem. For example, ext4 generally establishes its inode count when the filesystem is created, while XFS uses dynamic inode allocation subject to filesystem constraints.

Step 1: Check Disk Space and Inode Usage

Before deleting anything, determine whether the filesystem has actually exhausted its inodes.

Check disk space

Run:

df -h

This command displays filesystem capacity, used space, available space, and utilization percentages.

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       100G   25G   75G  25% /

In this example, the filesystem still has plenty of free storage.

Check inode usage

Next, run:

df -i

Example output:

Filesystem      Inodes   IUsed   IFree IUse% Mounted on
/dev/vda1      1000000  999500     500  100% /

The important column is IUse%. If it shows 100% and IFree is zero, inode exhaustion is a likely explanation for file-creation failures.

To check the filesystem containing a specific path, run:

df -i /var
df -i /home

Replace these paths with the directory where the application is failing.

Important: Check the filesystem that contains the affected directory. Your root filesystem, home directory, and application storage may reside on different filesystems.

Step 2: Identify Directories Containing Too Many Files

Once you confirm inode exhaustion, locate the directories responsible for the high file count.

Method 1: Use du --inodes

On systems with GNU du supporting the --inodes option, run:

sudo du --inodes -x -d 2 /var 2>/dev/null | sort -n | tail -20

This command:

  • Counts inodes used by files and directories.
  • Stays on the same filesystem with -x.
  • Checks up to two directory levels with -d 2.
  • Sorts the results numerically.
  • Displays the 20 largest inode counts.

If /var is not the source of the problem, investigate other relevant paths, such as /home or your application’s storage directory.

For a website hosted in a user’s home directory, you might run:

sudo du --inodes -x -d 2 /home/USERNAME 2>/dev/null | sort -n | tail -20

Replace USERNAME with the actual system username.

A directory with a high inode count is a useful lead, but it does not automatically mean its contents are safe to delete.

Method 2: Count files in a specific directory

If you suspect a particular application directory, use find:

find /var/tmp -xdev -type f -printf '.' 2>/dev/null | wc -c

This counts regular files beneath /var/tmp without traversing into other filesystems.

Replace /var/tmp with the directory you want to investigate.

For a more detailed breakdown by parent directory, run:

sudo find /var -xdev -type f -printf '%h\n' 2>/dev/null |
sort |
uniq -c |
sort -nr |
head -20

This can help identify directories containing large numbers of regular files.

Keep in mind that these searches can consume CPU and disk I/O on servers with millions of filesystem entries. Run them against targeted directories first and avoid repeating broad scans unnecessarily during peak traffic.

Step 3: Inspect the Files Before Cleaning Up

After identifying a suspicious directory, inspect its contents and determine which application owns the files.

For example:

sudo ls -lah /var/tmp

To inspect file ownership and timestamps:

sudo find /var/tmp -xdev -maxdepth 2 -type f \
-printf '%u %TY-%Tm-%Td %p\n' 2>/dev/null | head -100

This displays a sample of regular files, including their owners and modification dates.

For application-specific directories, also inspect the application configuration, scheduled tasks, and cleanup policies.

Do not assume that old files are unnecessary. Sessions, mail queues, uploads, and application state files may still be important even when they have not changed recently.

Step 4: Safely Free Inodes

The correct cleanup method depends on the source of the problem.

Option A: Remove confirmed temporary files

If you have identified temporary files that are no longer needed, first list the candidates.

For example, to review regular files older than 30 days in a dedicated temporary directory:

sudo find /var/tmp/myapp -xdev -type f -mtime +30 -print

Review the output carefully. Confirm that the directory contains disposable temporary data and that the application does not require those files.

Only after verification, delete the confirmed files:

sudo find /var/tmp/myapp -xdev -type f -mtime +30 -delete

Do not run this example against an arbitrary application directory. Replace the path with the verified temporary directory and confirm the retention policy first.

The -mtime +30 condition is based on modification time; it does not establish whether a file is safe to remove.

Option B: Clean application caches

Some applications generate thousands of cache files. If a cache directory is responsible, use the application’s supported cache-clearing command or maintenance procedure whenever possible.

Before cleanup:

  1. Identify which application owns the cache.
  2. Confirm that the files can be regenerated.
  3. Check whether the application requires a maintenance window.
  4. Follow its documented cleanup process.
  5. Monitor the inode count after cleanup.

Avoid blindly deleting everything under /var/cache, a website’s storage directory, or a hosting account’s home directory. Some of these locations contain data that should be preserved.

Option C: Fix temporary and session-file accumulation

If PHP sessions or application-generated temporary files are responsible, investigate why old files are accumulating.

Check the relevant session directory, application settings, and scheduled cleanup jobs. Verify the configured session lifetime and cleanup mechanism rather than assuming the system removes every expired file immediately.

For custom applications, implement a retention policy that removes only expired, unreferenced data.

Option D: Address mail and log directories

Mail queues and log directories can contain many files, but those files may be needed for delivery, troubleshooting, or auditing.

Use the mail server’s queue-management tools and the application’s log-rotation configuration. Do not delete mail queue files or active logs indiscriminately.

If a log file is growing excessively, fix the logging or rotation policy as well as addressing the immediate storage issue.

Step 5: Verify That Inode Usage Has Improved

After cleanup, check the filesystem again:

df -i

You should see more available inodes if the cleanup removed enough filesystem objects.

Next, check ordinary disk capacity:

df -h

These commands measure different resources, so both are useful when diagnosing filesystem failures.

You can also test file creation in a directory where you have permission:

touch /path/to/test-directory/inode-test.tmp

Replace the path with an appropriate directory. If the test succeeds, remove only the test file you created:

rm -- /path/to/test-directory/inode-test.tmp

Do not test by creating files in system directories unnecessarily.

If the inode count remains at 100%, investigate whether the cleanup affected the correct filesystem, whether files are still being generated, and whether the application is writing to another mount.

Step 6: Prevent Linux Inode Exhaustion From Returning

Resolving the immediate error is only part of the job. If an application continues generating excessive files, the filesystem may reach the same limit again.

Monitor inode usage

Include inode utilization in your regular server monitoring alongside disk capacity, memory, and CPU usage.

For a quick check:

df -i

For a specific filesystem:

df -i /

Configure monitoring alerts before inode utilization reaches 100%. The appropriate warning threshold depends on how quickly the application generates new files and how much time is needed to respond.

Set retention policies

Temporary files, cache entries, expired sessions, and application-generated artifacts should have a defined lifecycle.

Use application-supported cleanup tools or carefully scoped scheduled jobs. Always test automated deletion rules before enabling them in production.

Review application behavior

An unexpected increase in inode consumption may indicate a software bug, a failed scheduled task, or an application that creates a new file for every request or operation.

Track the directory where the growth occurs and investigate the process responsible instead of repeatedly deleting its output.

Plan filesystem capacity appropriately

Filesystem design matters when a workload generates very large numbers of small files.

On ext4, inode availability is generally determined when the filesystem is created. Increasing its inode count is not the same as simply deleting files; changing the filesystem design may require a planned migration or recreation.

XFS allocates inodes dynamically, but it still has filesystem allocation limits and operational constraints.

Do not recreate a production filesystem merely to change inode capacity without a tested migration plan and verified backups.

Common Troubleshooting Scenarios

df -h shows free space, but file creation fails

Run df -i against the affected path. If inode utilization is 100%, investigate directories containing excessive numbers of files.

df -i shows available inodes, but the error continues

Inode exhaustion may not be the cause. Check ordinary disk space, user or project quotas, filesystem health, read-only mounts, and application-specific limits.

Inodes become exhausted again after cleanup

Identify the process or application generating new files. Review cache policies, temporary-file handling, session cleanup, mail queues, and scheduled jobs.

Deleting files does not appear to resolve the problem

Confirm that the deleted files were on the affected filesystem. Also check whether the application immediately recreates them and whether you have permission to access the relevant directories.

If ordinary disk space remains exhausted despite removing files, deleted-but-open files may be relevant to that separate problem. Investigate process-held file descriptors rather than assuming inode exhaustion explains every No space left on device error.

Run Your Applications on a VPS You Can Manage

Reliable server operation requires more than sufficient disk capacity. Monitoring, predictable storage usage, and access to the right troubleshooting tools are essential for keeping applications available.

If you need a server environment for websites, development projects, or production workloads, explore ServerNext and its BDIX VPS hosting plans.

Choose a VPS configuration that fits your storage requirements and expected file workload. If you use a promotional code, check the current offer terms and eligibility at checkout before relying on any discount.

Linux inode exhaustion is a common explanation for No space left on device errors when a filesystem still has free disk space. The most important first step is to compare df -h with df -i.

Once inode exhaustion is confirmed, identify the directories responsible, inspect their contents, and remove only files that are safe to delete. Finally, address the underlying application behavior and monitor inode utilization to prevent the same issue from returning.

For production servers, a careful diagnosis and controlled cleanup are much safer than deleting files indiscriminately.

References: