VPS Disk Space Management: How to Monitor, Clean, and Expand Storage

VPS Disk Space Management: How to Monitor, Clean, and Expand Storage

A full disk is one of the most common and preventable VPS failures. When your disk fills up, databases stop writing, web servers return 500 errors, logs stop rotating, and email bounces. The good news: most disk space issues are caused by a handful of predictable culprits — log files, Docker images, old backups, and package caches — and take minutes to resolve once you know where to look.

This guide covers monitoring disk usage, finding and eliminating space wasters, automating cleanup, and expanding your VPS storage when you genuinely need more.

Step 1: Assess Your Current Disk Usage

Overall disk usage

# Human-readable disk space summary
df -h

# Show all filesystems including tmpfs
df -ah

Find the largest directories

# Top 10 largest directories from root
du -h --max-depth=2 / 2>/dev/null | sort -rh | head -20

# Find largest directories in /var (common space culprit)
du -h --max-depth=3 /var 2>/dev/null | sort -rh | head -20

# Interactive disk usage explorer (install ncdu)
sudo apt install ncdu -y
sudo ncdu /

ncdu is the fastest way to find disk space hogs — navigate directories interactively and see sizes in real time.

Find large files anywhere on the system

# Files larger than 100MB
find / -type f -size +100M 2>/dev/null | xargs ls -lh | sort -k5 -rh | head -20

# Files larger than 1GB
find / -type f -size +1G 2>/dev/null -exec ls -lh {} \;

Step 2: The Common Space Culprits

1. Log files

Nginx, Apache, MySQL, syslog, and application logs accumulate rapidly on busy servers:

# Check log directory sizes
du -sh /var/log/*

# View the largest log files
find /var/log -type f -name "*.log" | xargs ls -lh 2>/dev/null | sort -k5 -rh | head -10
# Safely truncate a log file (don't delete — the service holds the file open)
sudo truncate -s 0 /var/log/nginx/access.log

# Force log rotation now
sudo logrotate -f /etc/logrotate.conf

2. Docker images and containers

# Show Docker disk usage breakdown
docker system df

# Remove stopped containers
docker container prune -f

# Remove unused images
docker image prune -a -f

# Remove unused volumes
docker volume prune -f

# Full cleanup (removes everything unused)
docker system prune -a -f --volumes

Docker images are the biggest disk surprise for developers — a few pulled images and build caches can easily consume 20–50 GB.

3. APT package cache

# See how much space the package cache uses
du -sh /var/cache/apt/archives/

# Clean downloaded packages
sudo apt clean

# Remove packages that are no longer needed
sudo apt autoremove -y

4. Old kernel versions

# See installed kernels
dpkg --list | grep linux-image

# Remove old kernels (keep current + 1 previous)
sudo apt autoremove --purge -y

5. Temporary files

# Check /tmp and /var/tmp
du -sh /tmp /var/tmp

# Clear temp files (safe to delete)
sudo rm -rf /tmp/* /var/tmp/*

6. Mysql/MariaDB binary logs

# Check binary log size
ls -lh /var/lib/mysql/mysql-bin.*

# In MySQL, purge old binary logs
sudo mysql -u root -p -e "PURGE BINARY LOGS BEFORE DATE_SUB(NOW(), INTERVAL 7 DAY);"

# Disable binary logs if you don't need replication
# In /etc/mysql/mariadb.conf.d/50-server.cnf add:
# skip-log-bin

7. Core dump files

find / -name "core" -type f 2>/dev/null
find / -name "core.*" -type f 2>/dev/null | xargs ls -lh
# Delete if found and not needed for debugging
sudo find / -name "core" -type f -delete 2>/dev/null

Step 3: Configure Log Rotation

Prevent logs from ever filling your disk again with proper logrotate configuration:

sudo nano /etc/logrotate.d/nginx
/var/log/nginx/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 0640 www-data adm
    sharedscripts
    postrotate
        nginx -s reopen
    endscript
}
# Apply to all services
sudo nano /etc/logrotate.conf
# Rotate weekly, keep 4 weeks
weekly
rotate 4
compress
create
dateext

Step 4: Automate Disk Cleanup with Cron

nano ~/auto-cleanup.sh
#!/bin/bash
LOG="/var/log/auto-cleanup.log"
echo "=== Cleanup $(date) ===" >> $LOG

# Package cache
apt clean >> $LOG 2>&1
apt autoremove -y >> $LOG 2>&1

# Temp files older than 7 days
find /tmp -type f -atime +7 -delete >> $LOG 2>&1
find /var/tmp -type f -atime +7 -delete >> $LOG 2>&1

# Old log files larger than 100MB (compress them)
find /var/log -type f -name "*.log" -size +100M -exec gzip {} \; >> $LOG 2>&1

# Docker cleanup (if installed)
if command -v docker &> /dev/null; then
    docker system prune -f >> $LOG 2>&1
fi

echo "Disk after cleanup:" >> $LOG
df -h >> $LOG
chmod +x ~/auto-cleanup.sh
crontab -e
# 0 3 * * 0 /bin/bash /root/auto-cleanup.sh  # Weekly Sunday 3 AM

Step 5: Set Up Disk Space Alerts

nano ~/disk-alert.sh
#!/bin/bash
THRESHOLD=80
EMAIL="you@youremail.com"
HOSTNAME=$(hostname)

df -H | grep -vE '^Filesystem|tmpfs|cdrom|udev' | awk '{print $5 " " $1}' | while read OUTPUT; do
    USAGE=$(echo $OUTPUT | awk '{print $1}' | cut -d'%' -f1)
    PARTITION=$(echo $OUTPUT | awk '{print $2}')
    if [ $USAGE -ge $THRESHOLD ]; then
        echo "WARNING: $PARTITION on $HOSTNAME is ${USAGE}% full" | \
            mail -s "⚠️ Disk Alert on $HOSTNAME" $EMAIL
    fi
done
crontab -e
# 0 * * * * /bin/bash /root/disk-alert.sh  # Check hourly

Step 6: Expanding VPS Storage

Option A: Upgrade your VPS plan

The simplest solution. In VPS.DO’s SolusVM control panel, upgrade to a plan with more storage. After upgrading, you may need to resize the partition:

# Check partition layout
lsblk
df -h

# If the disk grew but partition didn't, resize it
sudo growpart /dev/vda 1
sudo resize2fs /dev/vda1  # For ext4
# Or for XFS:
sudo xfs_growfs /

Option B: Add a separate disk for data

Keep your OS on the primary SSD and move large data (databases, user uploads, backups) to a secondary volume:

# After attaching additional storage, find it
lsblk
# Typically shows as /dev/vdb

# Format the new disk
sudo mkfs.ext4 /dev/vdb

# Mount it
sudo mkdir /data
sudo mount /dev/vdb /data

# Make permanent in /etc/fstab
echo '/dev/vdb /data ext4 defaults 0 2' | sudo tee -a /etc/fstab

# Move MySQL data to new volume
sudo systemctl stop mysql
sudo mv /var/lib/mysql /data/mysql
sudo ln -s /data/mysql /var/lib/mysql
sudo systemctl start mysql

Option C: Use object storage for files

For user-uploaded files, images, and backups, move to S3-compatible object storage (Backblaze B2, Cloudflare R2, Wasabi). This offloads file storage entirely from your VPS disk.


Disk Usage Best Practices

  • ✅ Always keep at least 15–20% disk space free (databases need working space)
  • ✅ Store backups on a separate VPS or object storage — never the same disk you’re backing up
  • ✅ Set logrotate to compress and delete logs older than 30 days
  • ✅ Run docker system prune weekly if you use Docker
  • ✅ Monitor disk usage with vnstat or Netdata alerts before it becomes critical

Related articles:

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!