The Top 3 Methods to Solve the "No Space Left on Device” Error in Linux

The Top 3 Methods to Solve the “No Space Left on Device” Error in Linux

The most frustrating problems are those that don’t have a cause. Linux can be very specific with its error messages but this is one instance when Linux falls short.

A “No place left in device error” message is not very helpful, particularly if you have a large drive. This error message is why? What is the reason you can’t create new files even though there is enough space? What’s the best way to fix this?

Let’s see what happens.

Top 3 ways to fix “no space left on device” error in linux

Do you have enough space on your hard drive?

Be sure to identify the problem before you rush to fix it. There is no reason to panic if your disk space runs out. To free up space, you can simply delete unnecessary data.

Two Linux commands can be used to get information on disk space: du and df. While the du command calculates disk space consumption, the df command analyses the available disk space. These commands can be used in combination with sudo It will give you an accurate estimate of the space available on your disk.

  1. Let’s begin with the du command. The output of the du command can sometimes be quite long and difficult to read. We will therefore use the flags -s or -h. The -s flag summarizes the results while the -h flag makes it easily readable. Enter the command sudo du -sh / where / Points to the base directory.
Does your hard drive actually have enough space?
  1. You don’t need to worry about permission denied messages. This is how the system crawls through subdirectories. It may be necessary to keep it running depending on how large your drive is. The drive recursively runs through all the files.
Does your hard drive actually have enough space?
  1. After scanning is complete, du will produce a list of directories along with their sizes. This is an example of what the du command looks like when applied to an ordinarily-sized directory.
Does your hard drive actually have enough space?

To find out how much available space, we’ll use the df command. Because it shows only the filesystems mounted and statistics about their use, the df command makes life easier. We will again use the “-h” flag to render the output human-readable.

sudo df -h

Does your hard drive actually have enough space?

It is important to add up the results from the du and the df commands. Any discrepancy indicates disk space not available for use, despite the fact that it isn’t being used by files or folders.

Linux Displays “No Space Left on Device” Why is this?

It’s possible that your hardware is not to blame if you see the error “No Space Left on Device”, even though there’s plenty of space on your hard drive. It can be difficult to determine the cause of the error.

  • Recently Deleted File: A recently deleted file is the most frequent reason you will see this error. Sometimes a file will be deleted when a process still uses it. The space is retained even though it is gone.
  • Not Enough Inodes: inodes. . Inodes refer to the index pages within a Unix Unix filesystem. They hold metadata about every file in storage. But inodes don’t have an unlimited number. If you run out of inodes, the storage space will be reduced and this can result in the “No space left” error.
  • Failing Hard Drive: There is also the possibility of the hard drive simply failing and a lot of its space being taken up with bad sectors. It throws an exception because the system cannot create files at these addresses.

Repair 1: Start Processes with Deleted Files

A process that is still using deleted files is the most likely cause for “No space left” error. This error can be fixed easily. All you have to do is Start the process again You can free the storage that is reserved.

  1. You can use the lsof or grep command to locate the problem process. The lsof command displays a listing of open files used by running processes. grep allows you to narrow the list down to those that have been deleted. So enter sudo lsof / | grep deleted a pipe for linking lsof’s output to grep.
Fix 1: restart processes using deleted files
  1. You can now restart affected processes with the sudo systemctl restart service_name command. The service name represents the service found in the search.
Fix 1: restart processes using deleted files
  1. You can reset all of these processes with the if you have multiple ones or don’t want any specific services sudo systemctl daemon-reload command. This will restore all dependencies taking into account any modifications to the filesystem.
Fix 1: restart processes using deleted files

Once this is complete, any storage space that was held up during the process will be freed again. This allows you to continue writing files and not run into errors.

Fix 2: Examine Inodes

Although each drive may have a high number of inodes it can only store so much. If your drives are cluttered with a large number of files it’s possible to exhaust the available storage space. The reason why you should have more large files than small ones is because they can be overwhelming.

You can check for the existence of inodes easily by using the command df with the -i flag. This is how it looks:

sudo df -i

Fix 2: check inodes

This number will tell you how many inodes are currently being used and also the total amount of them. The “No space left in device” error is caused by insufficient free disk space.

Inodes can only be created when the drive is formatted. There are no other ways to create more. To free up space for new files, you only need to delete unnecessary files.

Mark Bad Blocks

Any hard drive will eventually succumb to data corruption. This problem will not affect a brand new hard drive, but older drives will eventually become “bad..

This means that a portion of your hard drive is rendered inoperable even though you filesystem considers it functional. This bad block inflates the free space, even though no files are able to be written to it. As the operating system attempts to delete any files stored in these areas, it will result in an “No space left” error.

Bad sectors can’t be repaired as they result from physical wear and tear on the hard drive. Only thing that you can do to fix this issue is to mark those bad sectors and make sure they don’t get referenced by your file system.

To do this, you must be able to access a Live CD, You cannot run a File System Check on a running drive. After you have done that, simply use the following command:

sudo fsck -vcck /dev/sda

Fix 3: mark bad blocks

It replaces the “/dev/sda” with the path to your drive. The program will mark any unusable blocks as invalid and detect them automatically. However, it won’t add any additional storage, so make sure to delete unnecessary files in order to clear up drive space.

Which is the best way to fix “No Space Left on Device” error?

A running process may be using a file that was deleted and is still used to cause a “No room left on device” error in Ubuntu or other Linux distros. This saves the space that was used by the file and prevents other operations from writing to it.

It is easy to fix this issue. All you have to do to solve the problem is restart the process. It is not easy to correct the errors caused by other factors.

No direct solution is available for bad data blocks and inodes on your hard drive. For new data to be created, it is necessary to delete any files that are already in use.

Leave a Reply

Your email address will not be published. Required fields are marked *