How to Manage Disk Space on a VPS
Find what’s eating your disk, clean up safely, set up log rotation, and expand storage on your GoZen VPS.
A full disk is one of the most common causes of server outages. When disk space hits 100%, databases crash, websites return 500 errors, logs stop writing, and you can’t even SSH in to fix it (if the shell needs to write temp files). This guide helps you diagnose, clean up, and prevent disk space problems.
Check Current Disk Usage
Overall Disk Space
# Human-readable overview of all mounted filesystems
df -h
Key columns to watch:
| Column | Meaning |
|---|---|
Size | Total size of the partition |
Used | Space currently used |
Avail | Space remaining |
Use% | Percentage used - act when this exceeds 85% |
Mounted on | Where it’s mounted (/ is your main disk) |
Find What’s Using Space
# Size of each top-level directory
sudo du -sh /* 2>/dev/null | sort -rh | head -20
# Drill into a specific directory
sudo du -sh /var/* 2>/dev/null | sort -rh | head -20
sudo du -sh /var/log/* 2>/dev/null | sort -rh | head -20
# Interactive disk usage analyzer (if available)
sudo apt install ncdu -y # Ubuntu/Debian
sudo dnf install ncdu -y # Rocky/AlmaLinux
sudo ncdu /
ncdu is highly recommended - it gives you an interactive, navigable view of disk usage with the ability to delete files directly.
Find Large Files
# Top 20 largest files on the entire server
sudo find / -type f -exec du -h {} + 2>/dev/null | sort -rh | head -20
# Large files in a specific directory (over 100 MB)
sudo find /var -type f -size +100M -exec ls -lh {} \; 2>/dev/null
# Large files modified in the last 7 days
sudo find / -type f -size +50M -mtime -7 -exec ls -lh {} \; 2>/dev/null
Common Disk Space Culprits
On a typical web hosting VPS, these are the usual suspects:
| Location | What’s There | Typical Size |
|---|---|---|
/var/log/ | System and service logs | 500 MB – 10+ GB |
/var/lib/mysql/ | MySQL/MariaDB databases | 1 – 50+ GB |
/tmp/ | Temporary files | 100 MB – 5 GB |
/var/cache/ | Package manager cache | 500 MB – 3 GB |
/home/ or /var/www/ | Website files, uploads, backups | Varies wildly |
/var/lib/docker/ | Docker images, containers, volumes | 2 – 50+ GB |
/var/mail/ | Unread mail notifications | 100 MB – 5 GB |
/snap/ | Snap packages (Ubuntu) | 500 MB – 5 GB |
Clean Up Safely
1. Clean Package Manager Cache
2. Clean Old Logs
# Check total log size
sudo du -sh /var/log
# Truncate a large log file (keeps the file, empties contents)
sudo truncate -s 0 /var/log/syslog
sudo truncate -s 0 /var/log/mail.log
# Remove old rotated logs
sudo rm -f /var/log/*.gz
sudo rm -f /var/log/*.1
sudo rm -f /var/log/*.old
Don’t delete active log files with rm. Services keep a file handle open, so deleting the file won’t free space until the service is restarted. Use truncate to safely empty a file while it’s in use.
3. Clean Journal Logs (systemd)
Systemd’s journal can grow very large:
# Check journal size
journalctl --disk-usage
# Keep only the last 7 days
sudo journalctl --vacuum-time=7d
# Or limit to 200 MB
sudo journalctl --vacuum-size=200M
Make the size limit permanent:
sudo nano /etc/systemd/journald.conf
Add or change:
SystemMaxUse=200M
Restart the journal:
sudo systemctl restart systemd-journald
4. Clean Old Kernels (Ubuntu)
Ubuntu keeps old kernel versions. After confirming your current kernel boots fine:
# List installed kernels
dpkg --list | grep linux-image
# Remove old kernels (keep current and one previous)
sudo apt autoremove --purge -y
5. Clean WordPress and Website Backups
Old backups are often the #1 disk hog on web servers:
# Find backup files
sudo find /var/www -name "*.zip" -o -name "*.tar.gz" -o -name "*.sql" -o -name "*.bak" | head -20
# Check their sizes
sudo find /var/www -name "*.zip" -exec du -sh {} \; | sort -rh
# Find WordPress revision bloat
# (use WP-CLI if installed)
wp post list --post_type=revision --format=count --path=/var/www/yourdomain.com
6. Clean Docker (If Using)
Docker is notorious for consuming disk space:
# Check Docker disk usage
docker system df
# Remove everything unused (stopped containers, dangling images, unused networks)
docker system prune -a
# Also remove unused volumes (careful - this deletes data)
docker volume prune
7. Clean Mail Queue
If you’re getting bounced mail or cron email notifications:
# Check mail queue size
sudo du -sh /var/mail/
sudo du -sh /var/spool/mail/
# Clear mail for a specific user
sudo truncate -s 0 /var/mail/root
# Clear the entire Postfix queue (if using Postfix)
sudo postsuper -d ALL
Set Up Log Rotation
Prevent logs from growing forever by configuring logrotate:
# View existing logrotate config
cat /etc/logrotate.conf
# List application-specific configs
ls /etc/logrotate.d/
Create a Custom Rotation Rule
Example for a custom application log:
sudo nano /etc/logrotate.d/myapp
/var/www/myapp/logs/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
copytruncate
}
| Directive | Meaning |
|---|---|
daily | Rotate every day |
rotate 14 | Keep 14 rotated files (2 weeks) |
compress | Gzip old logs |
delaycompress | Don’t compress the most recent rotated file |
notifempty | Skip rotation if log is empty |
copytruncate | Truncate the original file after copying (safe for apps that don’t handle SIGHUP) |
missingok | Don’t error if the log file is missing |
Set Nginx Log Rotation
Nginx logs (access.log and error.log) can grow very fast on busy sites:
sudo nano /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid)
endscript
}
Test the rotation:
sudo logrotate -d /etc/logrotate.d/nginx # dry run
sudo logrotate -f /etc/logrotate.d/nginx # force run
Set Up Disk Usage Alerts
Get notified before your disk fills up. Create a simple monitoring script:
sudo nano /usr/local/bin/disk-alert.sh
#!/bin/bash
THRESHOLD=85
USAGE=$(df / | awk 'NR==2 {gsub("%",""); print $5}')
if [ "$USAGE" -ge "$THRESHOLD" ]; then
echo "Disk usage on $(hostname) is at ${USAGE}%." | mail -s "Disk Alert: ${USAGE}% Full" admin@yourdomain.com
fi
sudo chmod +x /usr/local/bin/disk-alert.sh
Run it every hour via cron:
crontab -e
0 * * * * /usr/local/bin/disk-alert.sh
Expand Disk Space
If cleanup isn’t enough, you may need more storage.
Option 1: Upgrade Your VPS Plan
The simplest option. Upgrade to a larger plan through the GoZen Host client area and your disk will be resized automatically.
Option 2: Resize a Partition (LVM)
If your VPS uses LVM (Logical Volume Manager), you can expand a partition after adding more disk:
# Check if you're using LVM
lsblk
# If you see entries like /dev/mapper/..., you're on LVM
# Extend the logical volume to use all available space
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
# Resize the filesystem
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv # ext4
sudo xfs_growfs / # XFS (Rocky/Alma)
Option 3: Attach Additional Storage
Some GoZen Host VPS plans support attaching additional block storage. Check the client area for availability.
After attaching:
# Find the new disk
lsblk
# Format it (replace /dev/vdb with your disk)
sudo mkfs.ext4 /dev/vdb
# Create a mount point
sudo mkdir -p /mnt/storage
# Mount it
sudo mount /dev/vdb /mnt/storage
# Make it permanent
echo '/dev/vdb /mnt/storage ext4 defaults 0 2' | sudo tee -a /etc/fstab
Quick Cleanup Commands
Copy-paste this block for a quick cleanup on an Ubuntu/Debian VPS:
# Package cache
sudo apt clean && sudo apt autoremove -y
# Journal logs (keep 7 days)
sudo journalctl --vacuum-time=7d
# Old rotated logs
sudo rm -f /var/log/*.gz /var/log/*.1 /var/log/*.old
# Temp files older than 7 days
sudo find /tmp -type f -mtime +7 -delete
# Check result
df -h /
Troubleshooting
| Problem | Fix |
|---|---|
df shows disk full but du doesn’t add up | A process is holding a deleted file open. Run sudo lsof +L1 to find it, then restart that service. |
| Can’t delete files - “No space left on device” | You may be out of inodes, not disk space. Check with df -i. Old mail directories and session files create millions of tiny files. |
/boot is full | Old kernels. Run sudo apt autoremove --purge (Ubuntu) or sudo dnf remove --oldinstallonly (Rocky/Alma). |
| MySQL won’t start after disk full | MySQL needs space for temp files and binary logs. Free space, then start MySQL: sudo systemctl start mysql. Check binary logs: ls -lh /var/lib/mysql/binlog.* |
| Website uploads filling disk | Move uploads to object storage (S3/B2) or set upload size limits in your application. |
Related Articles
Last updated 21 Apr 2026, 08:08 +0300.