TutorialNov 21, 20266 min read

Linux VPS Disk Full? Find and Free Space Safely

"No space left on device" on your VPS? Find what filled the disk with df and du, clear logs, package caches and Docker safely, fix inode and deleted-file cases, and stop it from happening again.

Short answer: run df -h to confirm the disk is full, then du -xh --max-depth=1 / | sort -h to find the folder that grew. On a VPS it is almost always logs, Docker images and container logs, package caches, old backups or uploads. Free space with journalctl --vacuum-size=200M, apt clean and docker image prune, put a size limit on each so it doesn't come back, and only then think about a bigger disk.

A full disk breaks things in odd ways: databases stop, a web panel shows errors, SSH logins hang, programs crash with No space left on device. The fix usually takes a few minutes once you know where to look. Everything below works on Ubuntu and Debian as root (or with sudo).

01How Big Is the Disk on Each Plan?

Linux planDiskPrice
1 vCPU, 1 GB RAM10 GB NVMe$3.90 a month
1 or 2 vCPU, 2 GB RAM20 GB NVMe$6.50 a month
4 vCPU, 6 GB RAM40 GB NVMe$13.00 a month
6 vCPU, 10 GB RAM40 GB NVMe$26.00 a month
6 vCPU, 10 GB RAM80 GB NVMe$39.00 a month
Storage VPS1, 2 or 4 TB HDD plus an NVMe system diskfrom $32.50 a month

The system itself takes a few GB, so on the 10 GB plan a couple of Docker images or a week of verbose logs is enough to fill it.

02Step 1: Is the Disk Really Full?

bash
df -h /
df -i /
  • df -h shows space. Use% at 100% (or 95% and above) is your problem.
  • df -i shows inodes, the number of files the disk can hold. If IUse% is at 100% while space is free, you have too many small files: jump to step 5 below.

03Step 2: Which Folder Filled It?

Start at the top and follow the biggest folder down:

bash
du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -n 12
du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -n 12

-x stays on this disk, so /proc and mounted volumes don't confuse the numbers. Repeat with the biggest folder each time (/var/log, /var/lib/docker, /home/...) until you find the culprit.

To list single large files anywhere on the disk:

bash
find / -xdev -type f -size +500M -exec ls -lh {} \; 2>/dev/null

04Step 3: What Is Safe to Delete?

The usual suspects, with the command that shows the size and the one that frees it:

WhatCheckFree it
systemd journal (/var/log/journal)journalctl --disk-usagejournalctl --vacuum-size=200M
Old rotated logs (/var/log/*.gz, *.1)ls -lhS /var/logfind /var/log -type f -name "*.gz" -delete
One huge live log filels -lh /var/log/app.logtruncate -s 0 /var/log/app.log (not rm, see step 5)
apt package cachedu -sh /var/cache/aptapt clean
Old kernels and unused packagesapt autoremove --dry-runapt autoremove --purge
Docker images, stopped containers, build cachedocker system dfdocker image prune -a, docker container prune, docker builder prune
Docker container logsdu -sh /var/lib/docker/containerslog limit below, then recreate the container
Old snap revisions (Ubuntu)snap list --allsnap set system refresh.retain=2
Your own backups, dumps, uploadsdu -sh /home/* /root /var/backupsMove them off the server, then delete

If you use a hosting panel, its own local backups and logs are often the biggest folder. Check the panel's backup settings and keep fewer copies on the server itself.

05Step 4: Restart What Broke

Once there is space again, restart the services that failed while the disk was full, then check they're running:

bash
systemctl --failed
systemctl restart mysql      # or nginx, postgresql, docker, your app
df -h /

If a database refused to start, read its log first (journalctl -u mysql -n 50), since a crash on a full disk can need a moment of recovery on the next start.

06Step 5: Space Is Free, but the Error Stays

Two cases explain almost every "df shows free space but I still get No space left on device":

A deleted file is still open. If you rm a log that a program is still writing to, the space is only released when that program closes it. Find such files and restart the program that holds them:

bash
lsof +L1 2>/dev/null | head -n 20

Inodes are used up. Millions of tiny files (session files, cache folders, a mail queue, a runaway script writing one file per event) fill the inode table long before the space. Find the folder with the most files:

bash
du --inodes -x / 2>/dev/null | sort -n | tail -n 12

Then delete what that folder doesn't need, or fix the program that keeps creating them.

07Step 6: How Do You Stop It from Filling Up Again?

Cleaning up fixes today. Limits fix next month.

Cap the journal

In /etc/systemd/journald.conf set SystemMaxUse=200M, then systemctl restart systemd-journald.

Cap Docker logs

Put the block below in /etc/docker/daemon.json and systemctl restart docker. It applies to containers created after the change.

Rotate your own logs

Write app logs to /var/log/yourapp/ and add a logrotate rule, or log to the journal and let the cap above handle it.

Clean on a timer

crontab -e, then 0 4 * * 0 docker image prune -af removes unused images every Sunday at 04:00.

Get warned in time

A cron job that checks df and messages you before 90% is cheaper than an outage.

json
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}

A minimal warning script, here posting to a Telegram bot of your own (put your bot token and chat id in):

bash
#!/bin/bash
USE=$(df --output=pcent / | tail -1 | tr -dc '0-9')
if [ "$USE" -ge 90 ]; then
  curl -s "https://api.telegram.org/botYOUR_TOKEN/sendMessage" \
    -d chat_id=YOUR_CHAT_ID -d text="Disk at ${USE}% on $(hostname)"
fi

Run it hourly from cron: 0 * * * * /root/disk-alert.sh. Building the bot itself takes a few minutes: see How to Host a Telegram Bot 24/7.

08When Do You Need a Bigger Disk?

When du shows the space is real data you want to keep: a growing database, media uploads, a blockchain. A running server can't be resized in place, so order the larger plan, copy the data over and let the old server run out at the end of its paid period. Both run side by side while you move, so there's no downtime. For terabytes of data, the Storage VPS has a 1 to 4 TB disk; a Bitcoin node is the classic case (Run a Bitcoin Node on a VPS).

09And on a Windows Server?

On Windows RDP the same causes apply in Windows form: downloads, logs, the update cache. Run Disk Cleanup (cleanmgr) and choose "Clean up system files", empty the Recycle Bin, and clear the component store with Dism.exe /online /Cleanup-Image /StartComponentCleanup in an administrator PowerShell.

The disk has no free space or no free inodes left. Check both with df -h and df -i.

  • vps disk full
  • no space left on device
  • linux disk full
  • free disk space linux
  • docker disk space
  • journalctl vacuum

Keep reading

All articles