Sometimes, when we try to access our website or our panel, certain errors may appear because there is no free space left on the disk. To check this, you can read this other article where we explain how to perform this check: See used space on disk on my Linux server.
If you have confirmed that the disk is at 100%, here are some options you can use to free up some space and get your services running again.
Important
Keep in mind that if the disk is at 100%, some commands may not be executable, because if a file needs to be created it will not be possible, and you will need to resize the disk first: How to resize your cloud server
Things to keep in mind
A disk can become full for several reasons, but keep in mind that if your disk is very small, it is normal for it to fill up easily. There may be several reasons why it has become full.
Some options to free up disk space
Below are some options that may help free up space. In many cases, some of them may not have any effect on your server. It will depend on how you use the server and what you have installed.
Clean the package manager cache
One option is to clean your server's package manager cache. Sometimes many downloaded packages can accumulate. This is normal, because once downloaded they are kept on the server in case they are needed later.
APT
To free up APT space, use this command:
apt cleanYUM / DNF
To clean the YUM / DNF cache, use this command:
yum clean all
dnf clean allDelete system logs
Another option is to delete log records. For this procedure, it is important to delete only the logs that are compressed in .gz format. If you delete another log file, some service may stop working.
System logs are located in /var/log. You can check the size of this directory with:
du -sh /var/log/If the size is excessively large, you can check inside to see which directory is taking up the most space:
du -sh /var/log/*If you have any log file ending in .log that takes up a lot of space, it is probably because log rotation is not configured for it, so we recommend configuring this rotation first: How to configure a rotation with logrotate.
Create a Snapshot
Before running this command, keep in mind that it is a good idea to have a server snapshot so that if something does not work correctly, you can return to a previous state. So try to create a snapshot first.
If you have many records in .gz format, you can safely delete these files:
less /var/log/dpkg.log
dpkg.log dpkg.log.1 dpkg.log.2.gz dpkg.log.3.gz dpkg.log.4.gz dpkg.log.5.gz dpkg.log.6.gz dpkg.log.7.gz dpkg.log.8.gz dpkg.log.9.gz
To delete them, for example with the alternatives.log log:
alternatives.log.*.gzYou can repeat this last step with other log records you have.
Find which files or directories are the largest in the system
Another option is to check which directories or files take up the most space in your entire system. This way, you can tackle the problem directly.
du -a / | sort -n -r | head -n 10This command will show the largest files and directories in the system.
For example, for this tutorial we created several large files and directories to show you a possible output of the command:
7812752 /
5441392 /var
3145732 /var/www
2107820 /var/log
2097156 /var/log/registros
1135660 /usr
1048608 /home
1048604 /home/debian
1048580 /home/debian/fotos
772668 /usr/lib
As you can see, there are two directories taking up quite a lot of space: /var/log/registros and /home/debian/fotos. Now we know that those directories take up a lot of space, and we can check again with du -sh inside those directories to find out which subdirectory or file takes up the most.
Free up JournalD space
You can also try deleting the system journal logs. Sometimes they can take up a lot of space, and it is possible to safely free between 2GB and 5GB depending on what you have installed.
You can delete records older than 10 days:
journalctl --vacuum-time=10dOr those exceeding 2GB:
journalctl --vacuum-size=2GFree up space from internal backups (Panels only)
If you are using a server with HestiaCP, Plesk, cPanel or another panel available in our images, you can check whether you have internal backups taking up too much space. In general, they can be deleted from each panel's web interface. This allows you to free up space quickly.
Prevent the disk from filling up
To prevent the disk from filling up, what you can do is configure some monitoring system that periodically checks the disk status. This way, if the disk exceeds the threshold you have configured, you will receive an e-mail warning that the disk is about to become full.
To do this you can use different software:
Monit must be installed on the same server and you configure an SMTP server for alerts: Monitor my Ubuntu server with Monit or Monitor my CentOS server with Monit.
Zabbix, for us the best option, since it allows monitoring many servers at the same time and managing all kinds of notifications and monitoring many different services: How to install and configure Zabbix.
If you have any questions that are not fully answered in this article, remember that you can always contact support.