• Moges
  • 2026-10-29

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

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</mnt/b/big.bin; sleep 30' &
sleep 1 ; rm -f /mnt/b/big.bin
df -h /mnt/b ; ls -l /proc/$!/fd | grep big
--- after rm (space did not come back) ---
tmpfs    10.0M  5.0M  5.0M  50% /mnt/b
--- who still holds the deleted file ---
lr-x------ 1 root root 64 Oct 29 00:55 3 -> /mnt/b/big.bin (deleted)

The file is held open by a process; rm removes it from the directory but the space is not released until the process exits or closes the handle. This is the most common reason df says full while du finds no large file (lsof +L1 or /proc/<pid>/fd shows (deleted)). With inode exhaustion, by contrast, deleting a file takes effect at once, one out for one back, so the remedies differ completely: the first needs the process restarted, the second only allows deletion.

Experiment three: batch deletion restores writes immediately. After deleting half, usage fell from 100 percent to 50 percent and the exit code of touch turned 0 at once.

--- before cleanup ---
tmpfs   800  800    0  100% /mnt/a
deleted 400 files this round
--- after cleanup ---
tmpfs   800  400  400   50% /mnt/a
--- write one more file ---
touch exit code: 0

In production the effect is the same: not wait for it to fix itself, but delete and it takes effect.

7. How to Find It Early Instead of Waiting for a Call

The reason this fault dragged on until the user called was that monitoring covered CPU, memory and disk space, but not inodes. Three additions:

One, put df -i into monitoring, alongside df -h, with an alert at 80 percent. Inode exhaustion usually climbs slowly and then hits bottom suddenly, and 80 percent is the window to act.

Two, put queue length into monitoring. On machines with a mail service, watch the count from mailq | tail -1, or count the files under deferred directly. A steadily rising number is the signal of still sending what cannot be sent, and it surfaces the problem earlier than inodes.

Three, build per-directory inode baselines. Record once how many files each major directory holds in normal times, and compare directly when something goes wrong. /var/spool, /tmp, session directories, cache directories and upload temporary directories are the usual suspects.

One more easily overlooked point: an inode alert cannot be replaced by whether space is sufficient. One disk may be 90 percent used with few files and only 5 percent of its inodes gone; another may be 30 percent used with 95 percent of its inodes gone. In df -h one looks more dangerous and the other safer, when the truth is the opposite.

8. Several Wrong Moves, and Why Not to Make Them

rm -rf /var/spool/postfix. The queue directory structure, ownership and permissions are maintained by postfix itself. Delete the whole tree and the service will most likely fail to start after a restart, or start with a corrupted queue state. Clear the files inside and keep the tree.

Deleting active and incoming directly. These are the queues being delivered and just received; deleting here throws away mail that could have been delivered. Delete deferred and corrupt first.

One rm for six hundred thousand files. The argument list is too long and it reports Argument list too long; even with find -delete, the deletion itself updates directories and journals, IO saturates, and a machine already fragile from inode exhaustion easily stalls.

Only scaling up. Adding disks and extending partitions solves space, not inodes. ext4 adds inodes at a fixed ratio on resize, millions are missing, doubling the space only doubles them and is usually not enough; meanwhile the business keeps producing garbage during the resize, like adding water to a leaking bucket.

Tuning inode parameters with tune2fs. ext4's inode total is fixed at format time and cannot be increased online; what tune2fs can adjust does not solve a shortage of numbers. A large increase means rebuilding the file system, which is a migration with downtime, not an emergency measure.

Leaving the service running and only adding a scheduled cleanup script. This was the choice we nearly made at first: since one cleanup fixes it, clean once a day. That amounts to admitting a line nobody uses keeps producing garbage and dealing with it by robot vacuum. A cleanup script should exist as a fallback, but the cure is stopping the service.

9. This and Minimal Installation Are the Same Thing

In the article on application environment setup we wrote the principle for installing a system: minimal installation, do not install services you do not need; after installation go back and subtract, turning off what came by default and is not used. This fault is a counterexample to that principle, and it exposed a cost that is usually invisible: the cost of one extra service is not only memory and CPU but how it behaves when nobody is watching.

The mail service is entirely invisible in df -h and barely visible in top, yet it writes files into a queue every day. By the time it exhausts the inodes, the symptom is that the business system cannot be logged into, a symptom with no relation to mail at all.

The same logic applies to security: one more listening port, one more service that can send mail, is one more entry that can be exploited. The article on security hardening talks about closing unneeded services and narrowing the attack surface, which is the same action seen from the other side: turning off unneeded services solves both resources being quietly consumed and an oversized attack surface.

The test is one sentence: if this service died today, would the business be affected? If not, consider stopping it; if unsure, check whether it has done any real work lately (for mail, the queue and logs; for others, connection counts and logs), and stop it once confirmed idle.

10. Next Time Something Cannot Be Written, Follow This Order

Compress this path into a decision table. Order matters, because the first two steps lead people astray and the third is the real culprit this time:

OrderWhat to checkCommandWhat the result means
1Spacedf -hFull, so hunt large files level by level
2Who holds deleted fileslsof +L1(deleted) present, restart that process to release
3inodesdf -i100%, the case in this article, delete only
4Who is creating filesdu --inodes -d1 /varLocate the directory, then drill down
5Do writes work nowtouch /tmp/xCreates, so the path is open, then check the app
6Will it recurdf -i again after 10 minutesStill rising, the source is not stopped, back to step 4

Two reminders: steps 1 and 3 must be done together, and do not skip df -i because df -h looks good; treat no errors in the application log as a clue, not a conclusion.

No single link in this kind of fault is complicated; what is hard is that it appears in the wrong place, with every surface symptom pointing at the application while the culprit sits in the system layer, in a service nobody remembers installing. When Moges handles this kind of emergency, the first step is always to confirm clearly whether a write can succeed before looking upward, because a system that cannot even write its log is not to be trusted about anything it says. Such problems are usually cured by one on-site response plus a round of service consolidation, with the remaining effort in monitoring: with inodes, queue length and per-directory file counts visible, the next incident will not wait for a user to call.

Professional mold, automation parts manufacturing industry management software
Small and Medium-sized Enterprise ERP, MES, and MRP Solutions
Trade Inventory SaaS Management System, Linux Email Server Solution

Tel: 18625220688

Solutions

Mold Manufacturing Digitalization
Focused on mold shop production management, significantly shortening delivery cycles
ERP Systems for the Sheet Metal Industry
End-to-end management of laser cutting, bending, and welding
Custom Automation Equipment Management
Integrated quotes, production progress, and cost accounting
Tooling & Fixture Management Systems
Fully digital control of the inspection fixture production process

Resource Downloads

MES Whitepaper

In-depth Guide to Mold Manufacturing Execution Systems

Product Documentation

Moges PMS System Feature Guide

FAQ

Answers to all your questions

Contact Us

Now
Talk to Us

14 years of industry experience, focused on the digital transformation of mold, sheet metal, and custom automation equipment manufacturing

186 2522 0688

Headquartered in Kunshan, with on-site service within a 2-hour radius

Contact
Product & Service Inquiry

Free Online Consultation on Products & Solutions

Get a Quote

FAQ

Q: There's clearly still space on the disk, so why can't it be written to?
A: Because in addition to "space," the file system has another resource called inodes—each file occupies one record, and once the records run out, no new files can be created, and the error still reads No space left on device. In this case, df -h shows nothing unusual; you have to use df -i to see it.

Q: df -h shows tens of GB left, but df -i is at 100%—what does that mean?
A: It means the number of files has exhausted the inodes, not that space is full. Existing files can still be read as usual, but any operation that creates a new file will fail: writing sessions, writing logs, generating verification codes, uploading attachments, exporting reports—all come to a halt.

Q: How do I quickly find which directory is consuming the inodes?
A: Use du --inodes -d1 /var | sort -rn to look at the first-level directories first, then drill down two or three levels and you can basically pinpoint it. Older versions of coreutils don't have --inodes, so as a fallback use find -xdev -type f -printf '%h\n' | sort | uniq -c | sort -rn | head. Both commands are read-only and will still run even when inodes are full.

Q: Why is "can't log in" the first symptom?
A: Because login depends on session files. The password check passes, but the session file can't be written, so the login logically can't complete, and the next request still thinks you're not logged in, so it sends you back to the login page. Likewise, logs can't be written either—so what you see during troubleshooting is "no errors," when in fact the errors simply can't be recorded.

Q: df says it's full, but du can't find any large files—is that the same thing?
A: No. That's another situation: the file has already been rm'd, but a process still has it open, and the space is released only when the process exits. Use lsof +L1 or look for (deleted) in /proc//fd to confirm. The difference lies in how you handle it—a handle issue is solved by restarting the process, while an inode issue can only be solved by deleting files.

Q: Once the inodes are used up, can expanding capacity solve it?
A: It can only alleviate it proportionally. When ext4 is expanded, the new space adds inodes according to the ratio at format time; the shortfall is on the order of millions, which expansion usually can't make up; and during expansion the business keeps generating garbage, which is like adding water while leaking. To really raise inode density substantially, you can only rebuild the file system, and that's a migration with downtime.

Q: Will xfs run into the same problem?
A: Generally not; xfs allocates inodes dynamically. But it has other behaviors to watch: after deleting files, the available space shown by df may not change immediately (delayed allocation and preallocation), which easily creates the illusion of "deleted but not released."

Q: Can I just delete the mail queue directory?
A: Don't. The queue directory structure, ownership, and permissions are maintained by postfix itself; deleting the whole tree will cause the service to behave abnormally after a restart or the queue state to become corrupted. The correct approach is to first delete the oldest files in deferred and the files in the corrupt directory, keeping the directory structure; active and incoming hold messages that are being delivered, so don't touch them.

Q: Will stopping the mail service affect the business?
A: It depends on whether this machine is actually sending mail. The way to judge is to see whether the queue has a long-term backlog and whether the logs are all retries and bounces—if not a single message has ever been delivered successfully, it has no reason to exist. Conversely, if the business depends on sending mail (password recovery, alert notifications), you can't just stop it; you need to configure a usable relay, set an upper limit on the queue, and bring queue length into monitoring.

Q: How do I detect inodes about to fill up in advance?
A: Three things: put df -i and df -h side by side in monitoring, with an alert at 80% usage; for machines running the mail service, bring queue length (mailq | tail -1) into monitoring; establish an inode baseline for the main directories so you can compare directly when problems occur. /var/spool, /tmp, session directories, cache directories, and upload temp directories are high-incidence areas.

Q: What does this have to do with "minimal installation"?
A: A direct relationship—the mail service on that machine was left over from a default full install when the system was installed, and nobody has ever used it. The cost of installing an extra service isn't just memory and CPU, but also its behavior when left unattended. After installation, do subtraction: turn off the unneeded services, which solves both the problem of resources being silently consumed and the problem of an oversized attack surface.

Q: Can this kind of fault be handled all at once?
A: Usually yes. Clear the queue to restore writes, then stop the unneeded service to fix the root cause—one on-site handling plus one round of service consolidation is enough. The remaining effort goes into monitoring: make inode, queue length, and directory file count visible, and similar incidents won't wait until users call. Our Moges emergency handling also follows the order of "restore the business first, then locate the source, and finally add monitoring."

Latest News

Online Subscription