Troubleshoot
LinuxDiskErrorsServer Admin

VPS Out of Disk Space: Fix 'No space left on device' Error

How to fix 'No space left on device' on a Linux VPS. Find what is consuming disk space, clean up safely, and prevent it from happening again.

May 9, 2026·3 min read

VPS Out of Disk Space: Fix 'No space left on device' Error

No space left on device stops services cold — nginx can't write logs, databases refuse writes, and package managers fail mid-install. Here is how to diagnose and fix it quickly.

Step 1: Confirm the Disk Is Actually Full

df -h

Look for a filesystem at or near 100% use. Note the mount point (usually /).

Also check inode usage — you can run out of inodes before running out of blocks:

df -i

If IUse% is at 100% but Use% is not, you have an inode exhaustion problem (too many small files). Skip to the inode section below.

Step 2: Find What Is Taking Up Space

# Top-level directory sizes
du -sh /* 2>/dev/null | sort -rh | head -20

# Drill into the biggest directory
du -sh /var/* 2>/dev/null | sort -rh | head -10

Common culprits:

PathWhat fills it
/var/log/Runaway logs (especially syslog, auth.log, nginx/error.log)
/var/lib/mysql/Database data files, binary logs
/tmp/Temp files left by crashed processes
/home/User uploads, backups
/var/cache/apt/Cached package downloads
/root/Accidental downloads or builds

Step 3: Clean Up Safely

APT package cache (safe to clear entirely):

apt clean
apt autoremove --purge -y

Old log files:

# Truncate a specific bloated log without deleting it (keeps the file handle open)
truncate -s 0 /var/log/syslog

# Rotate and compress logs immediately
logrotate -f /etc/logrotate.conf

# Delete rotated compressed logs older than 7 days
find /var/log -name "*.gz" -mtime +7 -delete
find /var/log -name "*.1" -mtime +7 -delete

MySQL binary logs (if you do not use replication):

-- In MySQL shell
SHOW BINARY LOGS;
PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;

Or disable binary logging entirely in /etc/mysql/mysql.conf.d/mysqld.cnf:

# Comment out this line:
# log_bin = /var/log/mysql/mysql-bin.log

Docker images and containers (if you use Docker):

docker system prune -af --volumes

Find and delete large files:

find / -type f -size +100M 2>/dev/null | sort -k5 -rn

Step 4: Fix Inode Exhaustion

Inode exhaustion means millions of tiny files. Common cause: PHP session files, email queues, or cache directories.

# Find directory with most files
find / -xdev -printf '%h\n' 2>/dev/null | sort | uniq -c | sort -k1 -rn | head -10

Once you identify the directory:

# Count files
ls /path/to/dir | wc -l

# Delete all files in directory (safer than rm -rf /path/to/dir/*)
find /path/to/dir -type f -delete

PHP session cleanup:

find /var/lib/php/sessions -type f -mtime +1 -delete

Step 5: Prevent It From Happening Again

Configure logrotate to limit log sizes in /etc/logrotate.d/YOUR_APP:

/var/log/yourapp/*.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    maxsize 100M
}

Set MySQL binary log expiry:

# /etc/mysql/mysql.conf.d/mysqld.cnf
binlog_expire_logs_seconds = 259200

Monitor disk usage with a simple cron alert:

# Add to crontab -e
*/30 * * * * df -h / | awk 'NR==2 {if ($5+0 > 85) print "Disk at " $5}' | mail -s "Disk Alert" [email protected]

If you consistently hit disk limits, VMHeaven allows volume upgrades from the control panel. You can also attach additional storage without reprovisioning your VPS.

VPS Out of Disk Space: Fix 'No space left on device' Error | VMHeaven Troubleshoot