VPS Disk Management: Expand Storage, Use LVM, Monitor Usage, and Clean Up Space
Disk space problems on a VPS are silent until they aren’t — a full disk causes application writes to fail, database corruption, and crashed services. This guide covers finding what’s consuming space, expanding disk after provider upgrades, managing volumes with LVM for maximum flexibility, and setting up proactive monitoring before the disk fills completely.
Find What’s Consuming Disk Space
# Overall disk usage summary
df -h
# Find largest directories (top 20)
du -h / --max-depth=3 2>/dev/null | sort -rh | head -20
# Find files larger than 100 MB
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null | sort -k5 -rh | head -20
# Disk usage by directory in /var (common culprit)
du -h /var --max-depth=2 2>/dev/null | sort -rh | head -20
# Docker-specific space usage
docker system df
docker system df -v # Detailed breakdown
Common Space Hogs and Fixes
Log Files
# Check log directory size
du -sh /var/log/*
# Large Nginx access logs
ls -lh /var/log/nginx/
# Rotate logs immediately (forces logrotate to run now)
sudo logrotate -f /etc/logrotate.conf
# Truncate a specific log file (keep the file but empty it)
sudo truncate -s 0 /var/log/nginx/access.log
# Set up log rotation limits in /etc/logrotate.d/nginx:
sudo nano /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
rotate 7 # Keep 7 days
compress
delaycompress
missingok
notifempty
sharedscripts
postrotate
nginx -s reopen
endscript
}
Docker Images and Containers
# Remove stopped containers
docker container prune -f
# Remove unused images
docker image prune -a -f
# Remove unused volumes
docker volume prune -f
# Remove unused networks
docker network prune -f
# Nuclear option: remove all unused Docker objects
docker system prune -a -f --volumes
# Automate cleanup with cron
0 3 * * 0 docker system prune -f >> /var/log/docker-cleanup.log 2>&1
Package Cache
<code"># Clean apt cache (often 1–3 GB on busy servers) sudo apt clean # Remove downloaded .deb files sudo apt autoremove # Remove unused packages sudo apt autoclean # Remove outdated package versions # Check recovered space df -h /
Old Kernel Images
# List installed kernels
dpkg --list 'linux-image*' | grep '^ii'
# Remove old kernels automatically
sudo apt autoremove --purge
# Or manually remove a specific old kernel
sudo apt purge linux-image-5.15.0-100-generic
Expand Disk After Provider Upgrade
When you upgrade a VPS plan with more storage, the new space is unallocated — you need to grow the partition and filesystem.
# Step 1: Verify new disk size is visible
lsblk
# Look for unallocated space at the end of your disk
# Step 2: Grow the partition (for GPT partitions)
sudo growpart /dev/vda 1 # /dev/vda is disk, 1 is partition number
# May need to specify the device your root is on:
# Check: df -h / → look for /dev/vda1 or /dev/sda1
# Step 3: Resize the filesystem
# For ext4:
sudo resize2fs /dev/vda1
# For XFS:
sudo xfs_growfs /
# Verify
df -h / # Should show larger size now
LVM: Flexible Volume Management
LVM (Logical Volume Manager) lets you resize volumes on the fly, create snapshots, and span volumes across multiple disks. Useful when you need to reorganize storage without reformatting.
Check if LVM is in Use
<code">sudo lvdisplay # List logical volumes sudo vgdisplay # List volume groups sudo pvdisplay # List physical volumes
Extend an LVM Logical Volume
<code"># After expanding the underlying disk (see above): # Step 1: Resize the physical volume to use new space sudo pvresize /dev/vda # Step 2: Extend the logical volume (e.g., add 10 GB) sudo lvextend -L +10G /dev/ubuntu-vg/ubuntu-lv # Or extend to use all available space: sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv # Step 3: Resize the filesystem sudo resize2fs /dev/ubuntu-vg/ubuntu-lv # ext4 # or: sudo xfs_growfs / # XFS # Verify df -h /
LVM Snapshot for Safe Upgrades
# Create a snapshot before a risky operation (database migration, major upgrade)
sudo lvcreate -L 5G -s -n backup-snapshot /dev/ubuntu-vg/ubuntu-lv
# If something goes wrong, revert to snapshot
sudo lvconvert --merge /dev/ubuntu-vg/backup-snapshot
# Delete snapshot when no longer needed
sudo lvremove /dev/ubuntu-vg/backup-snapshot
Add a Second Disk (Block Volume)
# After attaching a block volume in VPS control panel:
lsblk # New disk appears as /dev/vdb
# Create filesystem
sudo mkfs.ext4 /dev/vdb
# Create mount point
sudo mkdir -p /data
# Mount permanently (add to /etc/fstab)
echo '/dev/vdb /data ext4 defaults,noatime 0 2' | sudo tee -a /etc/fstab
sudo mount -a
df -h /data
Disk Usage Monitoring and Alerts
<code"># Check disk usage with alert via cron sudo nano /usr/local/bin/disk-alert.sh
#!/bin/bash
THRESHOLD=85 # Alert when disk is 85% full
TELEGRAM_TOKEN="your_bot_token"
TELEGRAM_CHAT="your_chat_id"
while IFS= read -r line; do
USAGE=$(echo "$line" | awk '{print $5}' | tr -d '%')
MOUNT=$(echo "$line" | awk '{print $6}')
if [ "$USAGE" -gt "$THRESHOLD" ]; then
MSG="⚠️ Disk Alert: $MOUNT is ${USAGE}% full on $(hostname)"
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage" \
-d "chat_id=${TELEGRAM_CHAT}&text=${MSG}" > /dev/null
fi
done < <(df -h | grep '^/dev' | grep -v 'tmpfs')
chmod +x /usr/local/bin/disk-alert.sh
# Run every hour
sudo crontab -e
0 * * * * /usr/local/bin/disk-alert.sh
Getting Started
Most Ubuntu VPS plans at VPS.DO use simple partition layouts — growpart and resize2fs are the tools for disk expansion after a plan upgrade. Start with 40 GB NVMe for a typical web server; monitor usage and upgrade the plan when you consistently exceed 70% utilization. Log rotation and Docker cleanup are the first actions when a disk fills unexpectedly.
Conclusion
Disk management on a VPS follows a clear workflow: monitor usage proactively with alerts, clean up log files and Docker objects regularly with cron, expand partitions after provider upgrades with growpart + resize2fs, and use LVM snapshots before risky changes. A disk that never fills unexpectedly is the goal — proactive monitoring and routine cleanup achieve it with minimal manual effort.