The Linux Disk Is Not Full, Why Can't a Single Byte Be Written (Troubleshooting inode Exhaustion)

2026-10-29 09:03:30

The call that day was typical: the internal management system would not let anyone log in. The page loaded, the login box appeared normally, you typed the account and password, it spun for a moment and returned to the login page. Different browsers, cleared cache, different accounts, all tried; the user's description was precise: it never logs in.

The cause turned out to have nothing to do with logging in, with the system or with the database: a mail service nobody was minding on this Linux server had used up the file system's inodes. At the time df -h showed more than half the disk free.

That is what makes this class of fault so deceptive on Linux. The error says No space left on device, you look at disk space and there is plenty; you look for large files and find none; so you start suspecting the application, the database, the password. The command you should have run first is often remembered only after a long detour.

This article takes the process and the mechanism apart, including three experiments you can reproduce yourself, and a decision sequence to follow the next time something cannot be written.

The Linux Disk Is Not Full, Why Can't a Single Byte Be Written (Troubleshooting inode Exhaustion)

1. The Fault Started with Cannot Log In

The page loads, so the web service is alive; the login box displays, so the application still responds. Those two facts rule out the service being down. Then you type the account and password, click login, it spins and returns to the login page. That symptom points to the session: after a successful login a session file must be written, and every later request uses it to identify the user. If the session cannot be written, login cannot complete logically: the password check passes, the session is never created, the next request still considers you logged out, and back you go to the login page.

Following that thread: restart the application service, no use; look at the application log, no errors in it; check the database connection, normal; run the login-related queries directly, they return results; the account status and password are both fine.

In hindsight one detail was overlooked: the log had no errors because the errors could not be written. A system that cannot write its log looks remarkably healthy.

2. The First Misjudgment: Assuming the Disk Was Full

The most common reason for cannot write is a full disk, so check space first:

df -h

The result was unexpected: the root partition still had tens of gigabytes free and was under sixty percent used. Since there was space, the disk was not the problem, or so we judged at the time, and that judgment cost nearly an extra hour.

Next came finding who had eaten the space: large files, log directories, upload directories, database files. du scanned down level by level, the largest directory was only a few gigabytes, and the total did not add up to anything abnormal. Meanwhile the system kept reporting that it could not write.

What brought us back was a very plain question: if there really is space, why can a new file not be created?

Following that question we tried another command:

df -i
Filesystem      Inodes   IUsed    IFree IUse% Mounted on
/dev/vda1      6553600 6553600        0  100% /

The inodes were used up, 100 percent. At the same moment df -h still showed plenty of space. Two commands, two worlds.

3. What an inode Is and Why It Can Run Out

In the ext4 file system on Linux, one region of the disk records the file list, each file taking one entry, and the number of that entry is the inode (index node). A file actually occupies two things:

Data blocks: where the content itself lives, which is what df -h counts; the inode: the file name, permissions, owner, size, times and the location of its data blocks, which is what df -i counts.

So whether there is enough space and whether a new file can still be created are two independent questions. Enough space with inodes exhausted means existing files can still be read, not one new byte can be written, and the error is still the most misleading sentence of all: No space left on device. That sentence contains neither disk nor inode; it only says the device has no space.

The difference between the two file systems is worth remembering too: ext4 fixes the total number of inodes at format time, roughly one per 16KB of space by default, about six million on a 100G disk, and that number cannot be increased online; xfs allocates inodes dynamically and generally does not run out because of file count, though its space reclamation after deletion behaves differently from ext4 (delayed allocation and preallocation).

The key conclusion: inode consumption depends only on the number of files, not their size. A zero-byte empty file and a 4G video take exactly the same inode. That explains why du found nothing abnormal: the files eating the inodes may add up to a few hundred megabytes, trivial against tens of gigabytes free.

4. Where Six Hundred Thousand Small Files Came From

Count files per directory (a read-only operation, which still runs when inodes are full):

du --inodes -d 1 /var | sort -rn | head

The result was blunt: /var/spool/postfix alone held over six hundred thousand inodes, and every other directory combined was a fraction of it.

postfix is a mail service. The machine ran an internal management system, and the mail service had been left over from the default full installation when the system was set up: the panel brought it, the OS brought it, nobody turned it off. It was quiet in normal times, using no CPU and no memory, invisible in df -h, so nobody had ever noticed it.

How it ate the inodes takes three points:

First, a mail queue is a place with one file per message. If delivery fails the message stays in deferred waiting for a retry. postfix hashes it into several levels of subdirectories, precisely so that no single directory holds hundreds of thousands of files; the design itself shows that queue buildup was anticipated and needs guarding against.

Second, undeliverable mail keeps retrying. The default policy retries after an interval, with longer intervals later, so a message can sit in the queue for days.

Third, and the most lethal: bounces generate bounces. The system has scheduled jobs, and the output of some jobs is mailed to local accounts; if the account does not exist or local delivery fails, the mail system generates a bounce notifying the original sender; if that bounce also cannot be delivered, for example because the recipient is root@hostname and the hostname does not resolve, or outbound mail is blocked by network policy, it enters the queue, retries, and generates new bounces. One becomes two, two become four.

This is a classic avalanche, and a silent one: no alert, no log anomaly, CPU and memory normal, only the inodes falling steadily. When they reach zero, every operation that needs to create a file stops at once: no session file, so login never completes; no log, so even the reason cannot be recorded; no captcha image; uploads, exports and temporary files all fail.

What the user sees is still only cannot log in. The first thing to break in a system is often the least conspicuous write.

Knowing the queue directories makes the next diagnosis immediate:

DirectoryMeaningSafe to delete
maildrop / incomingJust received, not yet writtenDo not delete
activeBeing deliveredDo not delete
deferredDelivery failed, awaiting retryYes (oldest first)
bounceBounce being processedCareful; leave ones in progress
corrupt / holdCorrupt or manually heldYes after confirmation

For day-to-day queue checks, three commands are enough:

mailq                       # list the queue
postqueue -p | tail -1      # summary only: -- 632847 Kbytes in 612304 Requests
postsuper -d ALL deferred   # empty the deferred queue (careful, check the count first)

The summary line that day showed over six hundred thousand messages. That number did not grow in a day: a few dozen a day at first, undeliverable ones accumulating, bounces generating new bounces, until thousands were added daily. It had been growing for months, and in all that time no monitoring item could see it.

5. Restore Writes First, Then Talk About the Root Cause

Inode exhaustion has only one cure: delete. But deleting in a queue directory carries risk: a direct rm -rf takes away the directory structure, ownership and permissions postfix maintains itself, and the service will probably not come up cleanly; deleting files being delivered corrupts the queue state. The order we followed was this:

Step one, preserve evidence. Save df -i, the queue size and the directory listing before touching anything. Delete first and there is no data left for a review.

df -i > /root/inode-before.txt
mailq | tail -3 > /root/mailq-before.txt
du --inodes -d 1 /var/spool/postfix | sort -rn > /root/postfix-inodes.txt

Step two, clean in scripted batches, not all at once. Not postsuper -d ALL, because that would also delete the mail in active and incoming that could still be delivered normally, and deleting hundreds of thousands of files in one go would drive the already unhealthy machine to a standstill on IO. The approach was to delete the least valuable first: the oldest in deferred (bounces that had sat for days and long since lost meaning) and corrupt.

#!/bin/bash
Q=/var/spool/postfix/deferred
BATCH=2000
DRY=1          # 1 = count only, do not delete; set to 0 once confirmed

echo "before:" && df -i / | tail -1

for d in "$Q"/*/; do
  cnt=$(find "$d" -type f -mtime +2 | wc -l)
  [ "$cnt" -eq 0 ] && continue
  echo "$d has $cnt to clean"
  [ "$DRY" -eq 1 ] && continue
  find "$d" -type f -mtime +2 -print0 | xargs -0 -n "$BATCH" rm -f
done

echo "after:" && df -i / | tail -1

A few details: -mtime +2 deletes only files older than two days and leaves newly arrived ones still retrying; -print0 with xargs -0 handles special characters in file names; -n 2000 works in batches so a single delete does not saturate IO; DRY=1 runs through the list first, and only after the directories and counts look right is it set to 0 to actually delete. Watch df -i during the run: if the usage rate starts falling, it is working.

Step three, verify writes immediately. No need to wait for user feedback; create a file yourself: touch /tmp/inode-check. If it can be created, the write path is open, and only then look at login.

Step four, stop the mail service; that is the real cure. Clearing the queue only lowers the water level while the service keeps running and bounces keep breeding. On a new system use systemctl disable --now postfix; on an older system without systemd use chkconfig postfix off plus service postfix stop. Ten or so minutes later check df -i again; there should be no further change in magnitude.

Why this counts as the cure: the source of the problem was not a full queue but that the machine never needed a mail service at all. It carries no business function, is only a default product of installation, and its sole purpose is to send scheduled jobs' mail that nobody reads, which piles up when it cannot go out. Stopping it shuts down a line nobody uses that keeps producing garbage.

The reverse case needs stating too: if the business really does need to send mail, such as alert notifications or password recovery, it cannot simply be stopped; three things are needed instead, a relay that can actually deliver, a queue cap and cleanup policy, and queue length in monitoring. Mail that can go out does not pile up, and every queue buildup is essentially still sending what cannot be sent.

6. Three Experiments That Reproduce It

Reproduce the key mechanism on its own; all three were done in a container without touching production.

Experiment one: half the space left, inodes exhausted, writes fail. Using a 50M temporary file system with only 800 inodes (tmpfs nr_inodes caps the inode count exactly):

mkdir -p /mnt/a
mount -t tmpfs -o size=50m,nr_inodes=800 tmpfs /mnt/a
for i in $(seq 1 900); do touch /mnt/a/f_$i 2>/dev/null || break; done
df -h /mnt/a ; df -i /mnt/a ; touch /mnt/a/zzz
files created: 799
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           50.0M    0  50.0M   0% /mnt/a
Filesystem    Inodes  Used  Avail Use% Mounted on
tmpfs            800   800      0 100% /mnt/a
touch: /mnt/a/zzz: No space left on device

Space usage 0 percent, inode usage 100 percent, error No space left on device. Three lines together are the whole point of this article. All 799 files are zero bytes, yet they used 799 of the 800 inodes.

Experiment two: the file is deleted but the space does not come back. This and inodes are two different kinds of deleted but no use, easily confused in troubleshooting:

mkdir -p /mnt/b
mount -t tmpfs -o size=10m tmpfs /mnt/b
dd if=/dev/zero of=/mnt/b/big.bin bs=1M count=5 2>/dev/null
sh -c 'exec 3
« Back to News list