ENOSPC (errno 28) has four common causes, and only one of them is “the disk is full”. Triage in this order, always against the path that actually failed rather than / — and do not run fsck until you have read the next section, because on a mounted filesystem sudo fsck -n is the only form that is safe:
df -h /path/that/failed # blocks — note if Used + Avail is less than Size
df -i /path/that/failed # inodes — 100% IUse% with free blocks
lsof +L1 # deleted files still held open (NLINK 0)
quota -s # per-user limits (a different errno: EDQUOT)
The deleted-file case and the errno below were reproduced first-hand on macOS 26.6 against a 100 MiB scratch volume, because that failure mode is identical on any Unix. Everything ext4-specific is cited from its own documentation and marked as such, because none of it was run on Linux. On a Mac, fix-no-space-left-on-device-error.sh repeats the full-volume error and the held-open file on a 100 MiB disk image that it builds with hdiutil and removes when it exits; the ext4, /proc and fsck claims are left as cited, not run.
Table of Contents
Before you run fsck
This comes first because it is the step that can cost you the filesystem. e2fsck(8) is explicit: “Note that in general it is not safe to run e2fsck on mounted file systems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified.” -n means “Open the file system read-only, and assume an answer of ‘no’ to all questions.”
findmnt /dev/sdXN # is it mounted? answer this first
sudo fsck -n /dev/sdXN # read-only inspection, safe on a mounted fs
sudo umount /dev/sdXN # only then, and only if -n found something
sudo fsck /dev/sdXN
A repair pass against a live, mounted, read-write filesystem is how a recoverable problem becomes an unrecoverable one. If the answer to findmnt is that the volume is /, the repair belongs in single-user mode or on rescue media, not in your current shell. Nothing in the triage above requires fsck, and neither does any of the four causes below.
Bad sectors do not cause this error
Bad sectors do not make a drive falsely report available space, and blaming them sends people to badblocks and disk replacement for a problem that is almost always a full /boot or an open file handle. Free-space accounting comes from the filesystem’s block bitmaps, which have no notion of sector health; a drive remaps failing sectors internally and its addressable capacity does not change. A genuinely bad sector produces an I/O error (EIO), not ENOSPC.
The error is errno 28, and you can watch it happen
Filling a 100 MiB volume until the write fails, with the exception printed rather than summarised:
OSError: [Errno 28] No space left on device
errno.ENOSPC == 28
/dev/disk4s1 100Mi 2.3Mi 98Mi 3% /Volumes/HWNOSPACE (before)
/dev/disk4s1 100Mi 99Mi 636Ki 100% /Volumes/HWNOSPACE (after)
If your application logs a different errno, you are not looking at this problem. Quota exhaustion in particular reports EDQUOT, “Disk quota exceeded” — a separate error whose numeric value differs by platform (69 here, measured). A user over quota sees plenty of free space in df.
Deleting the file does not always free the space
This is the cause most often missed, and it is fully reproducible. A process wrote 60 MiB, still holds the descriptor open, and the file is then removed:
=== baseline ===
/dev/disk4s1 100Mi 2.3Mi 98Mi 3%
=== after writing 60 MiB (file still linked, fd open) ===
/dev/disk4s1 100Mi 62Mi 38Mi 63%
=== after rm (fd STILL open) ===
/dev/disk4s1 100Mi 62Mi 38Mi 63%
=== ls says it's gone ===
ls: /Volumes/HWNOSPACE/held.log: No such file or directory
=== after the fd closed ===
/dev/disk4s1 100Mi 2.3Mi 98Mi 3%
rm removed the directory entry; the inode and its blocks survive until the last descriptor closes. du cannot see it, ls cannot see it, and df will not move. lsof +L1 lists exactly the files whose link count has dropped to zero:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
Python 51397 <user> 3w REG 1,21 62914560 0 20 /Volumes/HWNOSPACE/held.log
(The USER column is the only thing edited in any output on this page — an account name replaced with <user>.) Read that line as a recipe: PID 51397 is holding file descriptor 3, the NLINK column is 0, and 62914560 bytes are unreachable. One fix is to restart the service. On Linux you often do not have to: /proc/[pid]/fd/ is documented as “a subdirectory containing one entry for each file which the process has open, named by its file descriptor, and which is a symbolic link to the actual file”, so truncating through that link releases the blocks with the process still running.
truncate -s 0 /proc/51397/fd/3 # Linux only — cited, NOT executed here
There is no /proc on macOS, so that command is unverified. It also destroys the log’s contents, which is the point — use it when a runaway log has filled a production disk and restarting the writer is worse than losing the file.
More causes: reserved blocks, a full /boot, tmpfs and inodes
Reserved blocks. ext4 sets aside a share of every filesystem for root. mke2fs(8) on -m: “Specify the percentage of the file system blocks reserved for the super-user. This avoids fragmentation, and allows root-owned daemons, such as syslogd(8), to continue to function correctly after non-privileged processes are prevented from writing to the file system. The default percentage is 5%.” The signature is a df -h where Used plus Avail falls short of Size, root can still write, and an ordinary user cannot. tune2fs -m 1 /dev/sdXN lowers it on a data volume; leave it alone on /. Cited, not run.
A full /boot. Separate, small, and filled by accumulated kernel packages, so the rest of the system looks fine. df -h /boot is the check.
tmpfs. /tmp, /run and /dev/shm are commonly RAM-backed and sized as a fraction of memory, so filling them costs RAM and never touches the disk. df -h -t tmpfs shows them.
Inode exhaustion is real and is what df -i is for, but it cannot be demonstrated here: the scratch volume above reports 4.3G free inodes because HFS+ and APFS allocate inodes dynamically rather than fixing a count at mkfs time. On ext4 that count is fixed when the filesystem is created and millions of small files will exhaust it while df -h still shows free blocks. Skipped rather than faked.