NewHalo Edge 3 is here: HTTP/3 everywhere and 42 edge locations.Learn more
Docs / Tools and troubleshooting

Free up disk space on your VPS

Tools and troubleshooting6 min readUbuntu 24.04 LTS

A full disk causes strange failures: databases stop writing, logs freeze, and deployments fail halfway. This guide shows you how to see where the space went, then clean up safely. You will delete only things that can be recreated, and you will look before you remove anything.

Before you begin

  • SSH access to your VPS as a user with sudo rights, such as alex.
  • Permission to remove the files in question. Never clean up data you do not understand, such as database folders.

Step 1: Check how full the disk is

df reports space per filesystem. The -h flag prints sizes in human-friendly units. The line that matters most is the one mounted on /, the root of the system.

df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G   37G  2.0G  95% /

Above about 85 percent, plan a cleanup. At 95 percent, act now. Also check inodes, which are the file-count limit. A disk can be "full" with plenty of bytes free if it holds millions of tiny files:

df -i /

Step 2: Find the biggest folders

du measures folder sizes. The -x flag stays on this filesystem, --max-depth=1 shows one level at a time, and sort -rh sorts the largest first. Use sudo so you can see folders owned by services.

sudo du -xh / --max-depth=1 2>/dev/null | sort -rh | head -n 10
21G     /var
9.4G    /usr
3.1G    /home
1.2G    /opt
...

Then drill down into the biggest one. Here we look inside /var:

sudo du -xh /var --max-depth=1 2>/dev/null | sort -rh | head -n 10
14G     /var/lib
5.8G    /var/log
1.1G    /var/cache

Step 3: Clear the journal and package caches

The system journal grows over time. Check its size, then shrink it to a limit you choose. The --vacuum-size option deletes the oldest entries until the journal fits.

sudo journalctl --disk-usage
sudo journalctl --vacuum-size=200M
Archived and active journals take up 5.8G in the file system.
Vacuuming done, freed 5.6G of archived journals from /var/log/journal.

Next, clear the package cache that apt keeps, and remove packages nothing needs anymore:

sudo apt clean
sudo apt autoremove --purge -y

Step 4: Review old logs before deleting them

Rotated log files usually end in .gz or a number, such as nginx/access.log.2.gz. List the old ones older than 14 days first, with no deletion, so you can read the list:

sudo find /var/log -type f -name '*.gz' -mtime +14 -print

When the list looks right, you can add -delete to the same command. Keep the current log files; the logging service rotates them for you.

sudo find /var/log -type f -name '*.gz' -mtime +14 -delete

Step 5: Check the container engine and other caches

If you run containers, old images and stopped containers often take most of the space. See what the container engine uses, then remove unused items. The prune command only touches things nothing is using.

sudo docker system df
sudo docker system prune -f

Temporary files in /tmp are normally cleaned at boot. Look there too, but do not delete files you cannot identify.

Step 6: Find deleted files still holding space

Sometimes you delete a huge log, yet df still shows the space as used. A running program keeps the file open. lsof +L1 lists open files with no remaining name. Restart the program that holds them, and the space comes back. Install lsof first if it is missing:

sudo apt install -y lsof
sudo lsof +L1
Careful: Do not delete files under /var/lib, such as database folders, or anything inside your web root unless you know what it is. Those folders hold live data, and removing them can destroy your site or database. Make a backup first.
Tip: Use ncdu, a terminal tool you can install with sudo apt install -y ncdu, to browse folder sizes interactively. Run sudo ncdu / and press q to quit.

Troubleshooting

  • The journal vacuum does nothing. Your journal may be stored in memory only. Check the Storage setting in /etc/systemd/journald.conf, and set a limit there with SystemMaxUse=200M if you want it kept permanently.
  • df shows space still full after deleting files. A running process still holds the file open. Use sudo lsof +L1 to find it, then restart that service.
  • apt is slow or reports a lock. Another package process is running. Wait for it to finish, then try again.
  • The disk is full and commands fail. Run sudo journalctl --vacuum-size=200M and sudo apt clean first. They free space quickly and safely.

Next steps

Set a regular reminder to check df -h /, or better, set an alert. Consider a larger plan if your data genuinely keeps growing. LightServe plans such as Cirrus or Nimbus offer more storage than a starter plan, and Afterglow snapshots can protect data before large cleanups.

Something not working? Chat or email our support team and we will help you get unstuck.

Contact support