How to Fix the ‘No Space Left on Device’ Error on Linux

No Space on Device Linux

So your Linux system is telling you that you have no space left on your hard drive, but you know there is actually a lot of free space left. Why? This is one of those few frustratingly vague errors on Linux systems, but there are a few usual culprits.

Before you go any further, it’s a good idea to check that there really is space left on the disk. While the tools in your desktop environment are good, it’s much better to use the direct ones from the command line.

Linux Filesystem du

Begin with du. Point it to the base directory on the drive that’s having the problem. This guide is assuming it’s the partition with root.

Linux Filesystem df

It’ll take some time to go through everything. Now, try with df.

Add root and the filesystems mounted under it. For example, if you have “/home” on a separate drive, add that in with the reading for root. The total should come out close to what you had with du. If not, that might point toward a deleted file being used by a process.

Of course, the main concern here is whether or not the results of these commands come in under the size of the drive. If it did, there’s obviously something wrong.

There are a couple of main causes here. If you saw a discrepancy between du and df you can jump down to the first option here. Otherwise, start at the second one.

Deleted File Reserved by Process

Occasionally, a file will be deleted, but a process is still using it. Linux won’t release the storage associated with the file while the process is still running. You just need to find the process and restart it.

Check processes for deleted files

Try to locate the process.

The problematic process should be listed, then just restart it.

Not Enough Inodes

Linux check filesystem inodes

There is a set of metadata on filesystems called “inodes.” Inodes track information about files. A lot of filesystems have a fixed amount of inodes, so it’s very possible to fill the max allocation of inodes without filling the filesystem itself. You can use df to check.

Compare the inodes used with the total inodes. If there’s no more available, unfortunately, you can’t get more. Delete some useless or out-of-date files to clear up inodes.

Bad Blocks

The last common problem is bad filesystem blocks. Filesystems get corrupt and hard drives die. Your operating system will most likely see those blocks as usable unless they’re otherwise marked. The best way to find and mark those blocks is by using fsck with the -cc flag. Remember that you can’t use fsck from the same filesystem that you’re testing. You’ll probably need to use a live CD.

Obviously, replace the drive location with the drive that you want to check. Also, keep in mind that this will probably take a long time.

Hopefully, one of these solutions solved your problem. This issue isn’t exactly easy to diagnose in every instance. With any luck, though, you can get it cleared up and have your hard drive working again as normal.

6 comments

  1. I’ve never had any of those things above affect my system but I have had, on several occasions, my root drive filled up due to a mounting error. Sometimes my NFS share from my server would be mounted onto root and take up the whole space. I have it exclusively setup in /etc/fstab to mount to /srv/ but randomly this still happens today. Usually I can unmount the NFS share and delete the files that wrote to the /srv and remounted it as a Share but it has been severe enough where I had to restart and boot to single user mode to fix what is going on. What do you think could help fix this problem u have been having? By the way keep up the good work.

  2. Some quite useful tips here, but in all cases, you do not need to use ‘ sudo ‘ with ‘ df ‘.

    On ext4 / ext3 filesystems, you might as a last resort do ‘ tune2fs -m1 /dev/sdXX ‘ to decrease the reserved space.

  3. Trying to put a >4GB file on a FAT partition will also give “No space left on device”

  4. I wanted to add what worked for me.

    The issue on my case was on a ZFS partition. And it’s apparently a know issue on ZFS that you need empty space to delete a file. After looking around, I found a solution that worked for me. In my case, I couldn’t empty my trash (too full).

    find /data/.Trash-1000/ -type f -exec truncate -s 0 {} +

  5. Thanks for this ran all the checks. Cause was a performance hit due to thousands of files and directories on the the cheap low power NAS on an SMB mount. Moved the offending files to another directory problems solved!

Comments are closed.

Sponsored Stories