Skip to content

Linux No Space Left on Device — Inode Exhausted Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Linux No Space Left on Device. We cover key concepts, practical examples, and best practices.

Linux throws "No space left on device" even when df -h shows free space. This happens when the filesystem runs out of inodes — the data structures that store file metadata. Each file consumes one inode, and small files can exhaust them quickly.

The Problem

df -h

Shows available space:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   30G   20G  60% /

But creating a file fails:

touch test.txt
touch: cannot touch 'test.txt': No space left on device

Wrong Approach

# WRONG — looking at space when the problem is inodes
df -h  # Shows free space — confusing
du -sh /  # Also shows free space — misleading

Right Approach

# Check inode usage instead
df -i /

Expected output:

Filesystem     Inodes  IUsed   IFree IUse% Mounted on
/dev/sda1      3.2M    3.2M      0   100% /

Step-by-Step Fix

Step 1: Check inode usage

df -i /

Step 2: Find the directory with the most files

for d in /*; do echo "$(find "$d" -xdev 2>/dev/null | wc -l) $d"; done | sort -rn | head -10

Step 3: Find and remove small unnecessary files

# Find directories with many files
find /var/spool -type f | wc -l

# Remove old log files
find /var/log -name "*.log" -mtime +30 -delete

# Clear package cache
sudo apt-get clean
sudo yum clean all

Step 4: Remove old kernels

# Debian/Ubuntu
sudo apt-get autoremove --purge

# RHEL/CentOS
sudo package-cleanup --oldkernels --count=2

Step 5: Clean up Docker containers and images

docker system prune -af

Step 6: Delete old temporary files

sudo rm -rf /tmp/*
sudo find /var/tmp -type f -atime +7 -delete

Step 7: Verify recovery

df -i /

Expected:

Filesystem     Inodes  IUsed   IFree IUse% Mounted on
/dev/sda1      3.2M    1.5M    1.7M   47% /

Prevention Tips

  • Monitor inode usage with df -i alongside df -h
  • Set up log rotation with logrotate to prevent log file accumulation
  • Store large numbers of small files on filesystems with high inode counts (XFS, ext4 with -i options)
  • Use databases instead of files for high-volume data storage
  • Set up monitoring alerts at 80% inode usage

Common Mistakes with no space left

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between disk space and inodes?

Disk space is the raw storage capacity for file contents. Inodes are metadata structures that store file attributes (permissions, timestamps, pointers to data blocks). A filesystem has a fixed number of inodes created at format time, so you can run out of inodes even with free disk space.

How many inodes does a new filesystem have?

It depends on the filesystem type and size. Ext4 creates one inode per 16KB of space by default. For a 50GB partition, this yields about 3.2 million inodes. You can control inode density with -i bytes-per-inode when creating the filesystem.

Can I add more inodes without reformatting?

Not easily. Inode count is set when the filesystem is created. Online options include: freeing inodes by deleting files, using a loopback file with a new filesystem, or migrating to a larger partition. For future-proofing, use XFS which allocates inodes dynamically.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro