How to Fix a Full VPS Disk Without Disrupting Your Website
How to Fix a Full VPS Disk Without Disrupting Your Website
There is nothing more stressful for a server administrator than logging into a terminal only to find that every command fails because of a linux disk full error. When your Virtual Private Server (VPS) hits 100% disk usage, your website typically goes offline, databases stop writing new entries, and email services freeze. It is a critical situation that requires a calm, methodical approach to avoid deleting the wrong files.
Many people panic and start running “rm -rf” on folders they do not understand. This is a recipe for disaster. The goal here is to reclaim space safely. You want to target disposable data like old logs and temporary caches while keeping your core application files and database records intact. By following a systematic cleanup, you can bring your site back online without the need for a full server restore from backups.
In my experience managing servers for various Malaysian clients, the most common culprits are usually overgrown log files or forgotten backup archives. Once you identify the source of the bloat, removing it is the easy part. This guide will walk you through the process of diagnosing the space leak and clearing it out securely.
Identifying the Source of Your Linux Disk Full Error
Before you start deleting things, you need to know exactly where the space has gone. Running random delete commands is dangerous. The first step is to use the disk free command to see which partition is actually full. Most of the time, it is the root partition (/).
Start by running df -h in your terminal. The “-h” flag makes the output human readable, showing you gigabytes and megabytes instead of raw blocks. If you see 100% usage under the “Use%” column for your main partition, you have confirmed the problem. However, this does not tell you which folder is the problem.
Using the DU Command to Pinpoint Bloat
To find the specific directory eating up your space, the du (disk usage) command is your best friend. I recommend running a summary of the top level directories first. For example, run du -sh /*. This will list every folder in the root directory and show its total size.
If you notice that /var is taking up 20GB while others are only taking 500MB, you know to dive deeper into that specific path. You can repeat this process by navigating into the folder and running the command again. For instance, move into /var/log and run du -sh * to see which specific log file has grown out of control.
The biggest mistake beginners make is deleting files based on “Date Modified” alone. Just because a file is old does not mean it is useless. Always check the file extension and the directory name before hitting delete.
Safe Ways to Clear Space and Fix Linux Disk Full Issues
Now that you have identified the culprits, it is time to clean. The objective is to remove files that the system can recreate or that are simply historical records no longer needed for daily operations.
Cleaning Up System Logs
On most Linux distributions, /var/log is the first place to check. System logs, mail logs, and kernel logs can grow massively if a process is throwing errors repeatedly. If you find a massive syslog or kern.log, do not simply delete the file using “rm”. If a process is still writing to that file, the space will not actually be released until the process is restarted.
Instead, use the truncate command. For example: truncate -s 0 /var/log/syslog. This empties the content of the file without deleting the file itself, meaning the system can keep writing to it without crashing. This is the safest way to handle active log files without disrupting the services that rely on them.
Managing Package Manager Caches
Every time you update your server using apt (on Ubuntu/Debian) or yum (on CentOS), the system keeps a copy of the downloaded package files. Over months of updates, these archives accumulate and take up significant space.
You can clear these safely using the following methods:
- For Ubuntu/Debian: Run
sudo apt-get clean. This removes the cached .deb packages from/var/cache/apt/archives. - For CentOS/RHEL: Run
yum clean all. This clears the temporary cache and metadata.
These commands are completely safe because they do not remove the installed software, only the installation files used to put that software on your system. If you ever need to reinstall a package, the system will simply download it again from the official repository.
Emptying the /tmp Directory
The /tmp directory is designed for temporary files used by running applications. Usually, the system cleans this up automatically, but sometimes a crashed application leaves behind massive temporary files that never get deleted. Check this folder using ls -lh /tmp.
If you see files that are several days old and very large, they are likely safe to remove. However, avoid deleting files that were created in the last few minutes, as they might be actively used by your web server or database. A safe way to clear this is to delete files older than 7 days using a find command, rather than a blanket delete.
Preventing Future Disk Space Crisis
Fixing the problem today is great, but preventing it from happening next month is better. If your server keeps filling up, you are likely dealing with a deeper issue like a misconfigured application or an aggressive logging level.
First, check your backup settings. Many people set up automated backups that store files locally on the server. If you are backing up your 10GB website every day and keeping 30 days of archives on the same disk, you will run out of space very quickly. Always move your backups to an external storage solution or a different server.
Second, consider a professional approach to server management. If you find yourself constantly fighting with disk space, you might need a more robust setup or a managed service. For those who want to focus on their business rather than the command line, looking into website maintenance packages can be a lifesaver. Having an expert monitor your disk health prevents these emergencies from happening in the first place.
Disk Usage Comparison Table
To help you understand what is “normal” and what is “suspicious,” refer to this general guide for a standard small VPS.
| Directory | Normal Size | Warning Sign | Recommended Action |
|---|---|---|---|
| /var/log | 100MB to 2GB | Over 5GB | Truncate logs or check for app errors |
| /var/cache | 500MB to 2GB | Over 4GB | Run apt-get clean or yum clean all |
| /tmp | Under 1GB | Multi-GB files | Delete files older than 7 days |
| /home | Depends on content | Unexpected spikes | Check for old zip/tar backups |
Advanced Cleanup for Database Servers
If you are running a MySQL or MariaDB database, the disk space issue might be coming from the database itself rather than the OS logs. Binary logs (binlogs) are used for replication and recovery, but they can grow to enormous sizes if not rotated properly.
Log into your MySQL console and check for files named mysql-bin.0000X. Instead of deleting them from the terminal, use the SQL command PURGE BINARY LOGS. This tells the database to safely remove old logs while keeping the internal index consistent. Deleting these files via the Linux terminal can corrupt your database’s understanding of its own history.
If your database tables are bloated, you might need to run an OPTIMIZE TABLE command. This reorganizes the physical storage of the table and can reclaim a surprising amount of space, especially if you delete a lot of data frequently.
For those who are not comfortable performing these database operations, it is often better to rely on a specialized provider. Choosing high quality web hosting Malaysia ensures that you have the right infrastructure and support to handle scaling without manual headaches.
Long Term Solutions for Storage Issues
Sometimes, the linux disk full error happens simply because your business has grown. Your images are higher resolution, your database has more customers, and your logs are naturally larger. In this case, cleaning is only a temporary fix.
You have two main options for a permanent fix:
- Resize your Disk: Most VPS providers allow you to increase your disk size through their dashboard. After increasing the quota, you may need to extend the filesystem using
resize2fsorxfs_growfsdepending on your partition type. - Offload Static Content: Move your images, videos, and large PDF files to an Object Storage service like Amazon S3 or DigitalOcean Spaces. This keeps your server lean and fast, as it only has to handle the application logic and database.
If you are unsure which path to take, visiting Ewallz Solutions can provide you with the technical guidance needed to optimize your server environment for long term growth.
Summary
Dealing with a linux disk full situation requires a balance between urgency and caution. Always start by diagnosing the problem with df -h and du -sh. Focus your cleanup efforts on /var/log, package caches, and the /tmp folder. Use the truncate method for active logs to avoid system instability and always use built-in database tools to clear binary logs.
By implementing a regular maintenance schedule and offloading backups and static files to external storage, you can ensure your website remains online. Remember that a full disk is often a symptom of a larger problem, such as a software bug causing excessive logging. Once you clear the space, take a moment to investigate why the disk filled up in the first place to prevent a recurrence.
You Might Be Wondering (FAQ)
Can I just delete everything in /var/log to save space?
No, you should not delete the directory itself or all the files inside. Some applications require specific log files to exist with correct permissions to function. Instead, truncate the files or use the logrotate utility to manage them automatically.
Will clearing the apt cache delete my installed programs?
No. Running apt-get clean only removes the cached installer files (.deb) that were used during the installation process. It does not touch the actual software installed on your system.
Why is my disk still showing 100% full after I deleted large files?
This usually happens because a process still has the deleted file open. In Linux, a file is only truly removed from the disk when no process is using it. You can fix this by restarting the service associated with the file or rebooting the server.
Is it safe to delete files in the /tmp folder?
Generally, yes, but only for files that are old. Avoid deleting files created within the last hour, as your web server or database may be using them for current sessions or temporary calculations.
How do I stop my logs from filling up the disk again?
The best way is to configure logrotate. This is a system utility that automatically compresses old logs and deletes them after a certain number of days, ensuring that your log directory never grows beyond a set limit.
