No space left on CentOS/RHEL Server

Share It!

Sometime you Can’t write to the hard disk on a Linux or Unix-like systems? or in other words we can say that we face issue “No space left on device”, although partition was not nearly full. So Need to analyze corrupt disk issues on a server? Need to figure out why you are getting “disk full” messages?

Centos-Logo

Want to solve full/corrupt and failed disk issues. Below is the solution for this problem.

1. Check available disk space

First need to check the available disk space on server.

# df -h

Output:

Filesystem            Size  Used Avail Use% Mounted on
/dev/md2              909G  648G  216G  76% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/md1              283M   47M  222M  18% /boot

Note: -h: print sizes in human readable format

2. Check available Inodes

After checking disk we need to check the available Inodes on server. Use following command to check Inodes:

# df -ih

Output:

Filesystem           Inodes IUsed IFree IUse% Mounted on
/dev/md2                58M   58M   0   100% /
tmpfs                  977K     1  977K    1% /dev/shm
/dev/md1                76K    44   76K    1% /boot

Note: -i: list Inode information instead of block usage

If IUse% is 100%, then huge number of small files is the reason for “No space left on device” errors.

3. Find Files or Directory

Below command will list directories with unusually high number of files.

# for i in /*; do echo $i; find $i |wc -l; done

This command will list directories and number of files in them. Once you see a directory with unusually high number of files (or command just hangs over calculation for a long time), repeat the command for that directory to see where exactly the small files are.

# for i in /opt/*; do echo $i; find $i |wc -l; done

4. Delete the files

Once you found the files which are consuming highest no. of Inodes. Just delete that files

# sudo rm -rf /home/bad_user/directory_with_lots_of_empty_files

4. Check the Inodes again

You need to check Inodes again using df command:

# df -ih

Output:

Filesystem           Inodes IUsed IFree IUse% Mounted on
/dev/md2                58M   13M   45M   23% /
tmpfs                  977K     1  977K    1% /dev/shm
/dev/md1                76K    44   76K    1% /boot

Leave a Reply

Your email address will not be published.