Causes of the No space left on device Error in Linux
04 Oct 2026, 14:43:39
The No space left on device error is usually perceived as an indication that the disk is completely full. However, on Linux, this error can occur even when df -h shows enough free space. Possible causes include exhausted inodes, deleted files that are still open, a full separate filesystem, reserved blocks, or filesystem problems.Let's look at the main causes of this error and a step-by-step troubleshooting procedure.
1. Check Free Space on the Filesystem
First, run:df -hFor example:Filesystem Size Used Avail Use% Mounted on
/dev/sda1 80G 65G 11G 86% /
In this case, there are still 11 GB available on the / filesystem.
If free space is available but the application continues to receive No space left on device, do not immediately start deleting files. Other possible causes should be checked first.
For more detailed information, use:
df -hTThe -T option additionally shows the filesystem type:Filesystem Type Size Used Avail Use% Mounted onThe filesystem type is important because it determines which further checks are relevant (ext4, XFS, Btrfs, tmpfs).
/dev/sda1 ext4 80G 65G 11G 86% /
2. Check Inodes
One of the most common causes is exhausted inodes.An inode is a filesystem structure that contains metadata about files and directories. Each file and directory uses at least one inode.
Therefore, you can have plenty of free disk space but still be unable to create a new file.
Check inode usage:
df -iFor example:Filesystem Inodes IUsed IFree IUse% Mounted onHere, disk space may still be available, but IFree is 0.
/dev/sda1 5242880 5242880 0 100% /
As a result, creating a new file may fail with No space left on device.
Important: on ext4, the number of inodes is fixed when the filesystem is created. On XFS, inodes are allocated dynamically (the limit is controlled by the maxpct parameter), while Btrfs does not have a fixed inode count, so df -i is not very informative on Btrfs.
How to Find the Cause
Inodes usually run out because of a huge number of small files.Common sources include:
- /tmp;
- application caches;
- PHP sessions;
- mail queues;
- log directories;
- temporary files;
- Docker containers;
- website directories.
find /var -xdev -type f | cut -d/ -f1-4 | sort | uniq -c | sort -nFor a specific directory:find /var/www -xdev -type f | wc -lNote: these commands count file names, not inodes. Hard links can have multiple names referring to the same inode, so the result may differ slightly from the actual inode usage.If you find a directory containing a large number of unnecessary files, determine which application is creating them before deleting anything.
3. Check for Deleted Files That Are Still Open
Another common situation is:- A large file was deleted.
- rm completed successfully.
- df -h barely changed.
- The space is still occupied.
Check for such files:
lsof +L1Example:COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NAMEIn this case, the file has already been deleted, but the php-fpm process is still keeping it open. Until the process closes the file descriptor, the occupied space may remain unavailable.
php-fpm 1234 root 10w REG 8,1 10G 0 /var/log/php.log (deleted)
First, identify the process:
lsof +L1Then determine which service started it:systemctl status After that, the corresponding service can be restarted properly.For example:
systemctl restart php-fpmThe service name depends on the specific operating system and installed software.If restarting the service is not currently possible, as a temporary measure you can truncate the deleted file through the process descriptor. The PID and FD values are taken from the lsof output. In the example above, they are 1234 and 10:
truncate -s 0 /proc/1234/fd/10The space will be released immediately, while the process can continue writing to the file.Use this method only if you are certain that the contents of the file are no longer needed.
Do not terminate random processes just to free disk space. First make sure that the process is actually holding an unnecessary deleted file open.
How to Avoid Log File Problems
If a log file has not been deleted and you need to clear it, do not remove it with rm while the application is writing to it.Instead, truncate the file:
truncate -s 0 /var/log/app.logThe file will remain in place, while its contents and occupied space will be released immediately.4. Check Each Filesystem Separately
df -h displays information for each mounted filesystem.For example:
Filesystem Size Used Avail Use% Mounted onIn this case, the root filesystem / has free space, but /var is completely full.
/dev/sda1 80G 50G 26G 66% /
/dev/sda2 10G 10G 0 100% /var
An application trying to write data to /var will receive: No space left on device.
Therefore, it is important to use:
df -hTrather than looking only at the available space on /.You can also check a specific directory:
df -h /varor:df -h /tmp5. Find Directories That Are Using Disk Space
If a filesystem is actually full, determine what is consuming the space.For example:
du -xh --max-depth=1 /var | sort -hThe output may look like:500M /var/cacheYou can then go deeper:
1.2G /var/log
8.5G /var/lib
12G /var
du -xh --max-depth=1 /var/lib | sort -hFor the root filesystem:du -xh --max-depth=1 / | sort -hTo find large files:find /var -xdev -type f -size +1G -exec ls -lh {} \;This can help identify:- old backup files;
- large log files;
- database dumps;
- ISO images;
- temporary files;
- archives.
6. Check /tmp
The /tmp directory is actively used by various applications.Check:
df -h /tmpand:df -i /tmpIf /tmp is a separate filesystem, it can become full independently of the free space available on /.For example:
Filesystem Size Used Avail Use% Mounted onIn this case, an application attempting to create a temporary file in /tmp will receive: No space left on device
tmpfs 512M 512M 0 100% /tmp
Other tmpfs filesystems can become full as well, such as /dev/shm and /run.
7. Check Reserved Blocks on ext4
On ext4, 5% of blocks are reserved for root by default. Therefore, a regular user or an application running as a non-root user may receive No space left on device before Use% reaches 100%, while root can continue writing data without problems.Check the reserved blocks:
tune2fs -l /dev/sda1 | grep -iE "block count|reserved block"If the reserved space is excessive, for example on a large data partition rather than a system partition, it can be reduced:tune2fs -m 1 /dev/sda1Change this setting carefully. On system partitions, reserved blocks help protect the system from completely running out of disk space.8. Check Quotas
The server may use disk space limits for individual users.Check the quota:
quota -sDepending on the system configuration, you can also use:repquota -aThis is especially important if:- the filesystem has free space;
- the error occurs only for one user;
- other users can create files without problems.
Note that when a quota is exceeded, the application will usually receive Disk quota exceeded (EDQUOT) rather than No space left on device.
Exceptions are possible, for example with XFS project quotas. If you see Disk quota exceeded, this is where you should look for the cause.
9. Check Docker
On servers running Docker, a significant amount of space can be consumed by: /var/lib/docker.Check Docker disk usage:
docker system dfThe command shows how much space is used by:- images;
- containers;
- local volumes;
- build cache.
du -sh /var/lib/dockerFor cleanup, use Docker's built-in commands.For example:
docker system pruneThis command removes stopped containers, unused networks, dangling images, and build cache. Volumes are not removed by default. They are removed only with the --volumes option, which should be used with extreme caution on production servers. Before running the command, make sure you understand which objects will be deleted.
It is not recommended to manually delete files from /var/lib/docker, as this can corrupt Docker's internal state.
10. Check the Filesystem State
If free disk space and inodes are available, but write operations still fail, check system messages.For the kernel:
dmesg -T | grep -iE "error|fail|ext4|xfs|I/O"Also:journalctl -k -p errPay attention to messages such as:- I/O error
- EXT4-fs error
- XFS
- Remounting filesystem read-only
This is a related problem, but it is worth checking because the symptoms — write operations failing — can look similar.
The problem is no longer related to a lack of free disk space.
Possible causes include:
- filesystem errors;
- disk problems;
- RAID problems;
- controller errors;
- hardware failures.
Rare Cases of ENOSPC
For completeness, the error can also occur when a directory becomes full. On ext4, dmesg may contain a Directory index full message. ENOSPC can also occur when certain IPC resources are exhausted, such as semaphores or shared memory.These are rare situations, but they are worth keeping in mind when the standard checks do not reveal the cause.
11. Check the Disk and SMART
If the system logs contain I/O errors, check the disk health.For a SATA/SAS drive:
smartctl -a /dev/sdaFor NVMe:smartctl -a /dev/nvme0Here, /dev/nvme0 is the controller, while /dev/nvme0n1 is the namespace. Both variants can be used with smartctl.For NVMe, you can also use:
nvme smart-log /dev/nvme0Pay particular attention to signs of:- reallocated sectors;
- pending sectors;
- uncorrectable errors;
- media errors;
- read/write errors.
Depending on the RAID controller, you may need storcli, perccli, or other specialized tools.
For MegaRAID controllers, smartctl can also be used by specifying the physical drive number N:
smartctl -a -d megaraid,N /dev/sda12. When df and du Show Different Values
Sometimes you may encounter a situation where:df -hshows, for example:/dev/sda1 100G 95G 5G 95% /while du shows significantly less usage.
For a correct comparison, use the -x option so that du does not enter other filesystems:
du -xsh /Without -x, the command can traverse /proc, /sys, and filesystems mounted inside /.The resulting value cannot be directly compared with df.
One possible reason for the difference is deleted files that are still open by processes.
Check them with:
lsof +L1You should also take into account:- other filesystems mounted inside /;
- special filesystems;
- bind mounts;
- Docker storage;
- hidden mount points — data stored in a directory that was later covered by another mounted filesystem. To see such data, mount the root filesystem again through a bind mount: mount --bind / /mnt/root
13. Quick Troubleshooting Algorithm
When No space left on device appears, it is recommended to proceed in the following order.Step 1. Check disk space
df -hStep 2. Check inodesdf -iStep 3. Check filesystems and mount pointsdf -hTStep 4. Find deleted but open fileslsof +L1Step 5. If a filesystem is full, find large directoriesdu -xh --max-depth=1 / | sort -hFor /var:du -xh --max-depth=1 /var | sort -hStep 6. If there is free space but the error occurs only for regular users on ext4tune2fs -l /dev/sda1 | grep -i "reserved block"Step 7. Check quotas, especially when Disk quota exceeded is reportedquota -sStep 8. If Docker is useddocker system dfStep 9. Check filesystem errorsdmesg -T | grep -iE "error|fail|ext4|xfs|I/O"and:journalctl -k -p errStep 10. If I/O errors are present, check the disksmartctl -a /dev/sdaTypical Situations
| Situation | What to check |
|---|---|
| df -h shows free space | df -i |
| df -i shows 100% | Number of files/inodes |
| A large file was deleted but the space was not released | lsof +L1 |
| / has free space but writing fails | df -hT |
| The error occurs only for one user | Quota, reserved blocks (tune2fs) |
| Disk quota exceeded | quota -s, repquota -a |
| /tmp is full | df -h /tmp, df -i /tmp |
| Docker uses a lot of space | docker system df |
| There is an I/O error | dmesg, journalctl, SMART |
| Read-only file system | Filesystem and disk status |
| df shows more used space than du | du -xsh /, open deleted files, mount points |
Important Points
The No space left on device error does not automatically mean that you need to delete files.Before cleaning the server, determine which resource has actually been exhausted:
- disk space;
- inodes;
- reserved blocks;
- space on a specific filesystem;
- Docker storage;
- or filesystem availability due to disk errors.
rm -rf /var/log/*or:rm -rf /tmp/*on a production server. This can delete required data or cause problems for running applications. In addition, deleting logs that are still held open by an application will not necessarily free the space.Use truncate -s 0 when you need to clear a file while keeping it in place.
Conclusion
If Linux reports No space left on device even though free space is available, start by checking:df -h
df -i
df -hT
lsof +L1In most cases, these commands help determine whether the disk is actually full, inodes have been exhausted, space is being held by a deleted file, or the problem is related to a specific filesystem.If free space and inodes are normal, proceed to checking quotas, Docker, system errors, and disk health.
This systematic approach helps identify the cause of the error without unnecessarily deleting files or risking disruption to a production server.