Resolving Disk Space issues on a VPS/Dedicated server

If your server is running out of disk space, you may experience downtime, slow website loading, or emails that get sent but don’t arrive in your mailbox.

When accessing your cPanel/WHM accounts, this message may pop up:

Sorry for the inconvenience!
The filesystem mounted at / on this server is running out of disk space.
cPanel operations have been temporarily suspended to prevent something bad from happening.
Please ask your system admin to remove any files not in use on that partition.


To fix this issue, then, it is required to check your disk space usage on the server and remove unnecessary files.




Checking disk usage


Please follow these steps to check your disk usage:

1. Connect to your server as the root user using SSH.

2. To check the overall disk usage, run:

df -h



This command shows the total size of disk space, used disk space, available disk space and mount points on a file system.

3. To list the top 5 largest folders on the server, run:

du -a / | sort -n -r | head -n 5



  • -a shows all items
  • / tells what directory to scan
  • -nr displays the largest directories at the top
  • head -n 5 specifies the number of results to show

4. To find the largest files, use:

find / -type f -exec du -Sh {} + | sort -rh | head -n 5



5. To list the largest files in a specific folder, include the path to the folder after find, e.g.,

find /backup -type f -exec du -Sh {} + | sort -rh | head -n 5



6. Now that you have located the folders and files that can be removed, use the following commands to delete them:

  • To remove a directory with all its content: rm -rf /path/to/directory
  • To remove all files and folders inside a directory: rm -rf /path/to/directory/*
  • To remove a file: rm -f /path/to/filename.ext
  • To remove all files but not folders from a directory: rm -f /path/to/directory/*



Checking inode usage


If you receive the No space left on device error message, but there is plenty of free disk space left, it’s possible that your system is running out of available inodes.

An inode is a data structure that stores information about every file and directory on the file system. The number of inodes is set when the filesystem is first created.

To check your inode usage:

1. Connect to your server as the root user using SSH.

2. Run the following command to check overall usage:

df -i



For more detailed information run:

tune2fs -l /drive/location | grep -i inode


If you see that your system is out of free inodes, use the following command to locate the directories that contain the number with the most inodes:

find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n



This command may take some time to run. It lists and sorts every directory on the filesystem prefixed with the number of files (and subdirectories) in that directory. The directory with the largest number of files will be located at the bottom.

Make sure to delete unnecessary files and folders:

  • To remove a directory with all its content: rm -rf /path/to/directory
  • To remove all files and folders inside a directory: rm -rf /path/to/directory/*
  • To remove a file: rm -f /path/to/filename.ext
  • To remove all files but not folders from a directory: rm -f /path/to/directory/*


Updated
Viewed
38267 times

Need help? We're always here for you.

notmyip