Troubleshooting

Free up disk space on a Linux VPS

Find what is using space, then safely clear package caches, systemd journal logs, old Docker data and large log files without breaking running services.

BeginnerLinux server3 min read

A full disk causes strange failures: databases stop writing, uploads fail and even SSH logins can break. Find the cause first, then clean up in order of safety.

1. See how full the disk is

Bash
df -h
df -i

df -h shows space. df -i shows inodes; if IUse% is 100%, you have too many small files (often sessions or cache) even if space is left.

2. Find the largest folders

Bash
sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -n 15

Repeat on the biggest result, for example /var, to drill down. For an interactive view, install ncdu (sudo apt install ncdu, or from EPEL on AlmaLinux/Rocky) and run sudo ncdu -x /.

To list single large files:

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

3. Clean package caches and unused packages

Ubuntu and Debian:

Bash
sudo apt clean
sudo apt autoremove --purge

AlmaLinux and Rocky Linux:

Bash
sudo dnf clean all
sudo dnf autoremove

autoremove also removes old kernels that are no longer needed. Read the list before you confirm.

4. Shrink the systemd journal

Bash
sudo journalctl --disk-usage
sudo journalctl --vacuum-size=200M

To keep it small permanently, set SystemMaxUse=200M in /etc/systemd/journald.conf and run sudo systemctl restart systemd-journald.

5. Handle large log files

Do not rm a log file that a service is still writing; the space is not freed until the service restarts. Empty it instead:

Bash
sudo truncate -s 0 /var/log/myapp/huge.log

Then make sure logrotate covers that log so it cannot grow forever.

6. Docker data

Bash
docker system df
docker system prune

prune removes stopped containers, unused networks and dangling images. Also cap container log size as shown in Install Docker and Docker Compose.

7. Deleted files still using space

If df says the disk is full but du cannot find the files, a process is holding deleted files open:

Bash
sudo lsof +L1

Restart the service named in the output to release the space.

Warning: Never delete files inside /var/lib/mysql, /var/lib/postgresql, /var/lib/docker or /boot by hand. Use the database, Docker or package tools instead, or you can lose data or stop the server booting.

Troubleshooting

  • Space comes back quickly: something is writing fast. Find it with sudo du -xh --max-depth=2 /var | sort -h | tail a few minutes apart.
  • Old backups on the server: move them off the server; see Back up your Linux VPS.
  • Extra NVMe disk may also be available as an add-on when you order.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.