Disk full at 2 AM: a calm checklist for Linux servers

When a Linux disk fills up, things break in confusing ways. A step-by-step checklist to find what's using the space, free it safely, and stop it happening again.

AskMyServers team · · 2 min read

A full disk is rarely subtle once it happens. The database stops accepting writes, the app throws errors nobody has seen before, deploys fail, and sometimes even SSH takes an age to let you in. The good news is that it's usually quick to fix once you know where to look.

Here's the order we go in. Take it one step at a time; deleting the wrong thing in a hurry is how a bad night gets worse.

1. Confirm it's really space

df -h
df -i

The first shows space, the second shows inodes, the number of files the filesystem can hold. A disk can be "full" with plenty of gigabytes free if something has created millions of tiny files (session files and mail queues are common culprits). If df -i shows 100%, you're hunting for file count, not size.

2. Find the big directories

sudo du -xh / --max-depth=2 2>/dev/null | sort -h | tail -20

-x keeps it on one filesystem so it doesn't wander into other mounts. Follow the biggest directory down a level at a time. On most servers the answer turns out to be one of a handful of places.

3. The usual suspects

Logs. /var/log is the classic. Check the systemd journal too:

sudo journalctl --disk-usage
sudo journalctl --vacuum-size=500M

Docker. Old images, stopped containers and build cache pile up quietly:

docker system df
docker image prune -a      # removes images not used by any container
docker builder prune       # removes build cache

Read what each one will remove before saying yes. docker system prune --volumes also deletes unused volumes, which may contain data you care about.

Old backups and dumps left in home directories or /tmp.

Package caches: sudo apt-get clean is safe and often frees a surprising amount.

4. Watch out for deleted files still in use

Sometimes you delete a huge log file and df doesn't change. That's because a running process still has it open, so the space isn't released until the process lets go:

sudo lsof +L1 | sort -k7 -n | tail

Restarting (or reloading) the process that holds the file frees the space. For log files, truncating is often better than deleting while the app is running:

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

5. Stop it happening again

Once things are working again, spend ten minutes on prevention:

  • Make sure logrotate covers your application's logs, with a sensible number of copies kept.
  • Cap the journal in /etc/systemd/journald.conf with SystemMaxUse=.
  • Clean up Docker images as part of your deploy, or on a schedule.
  • Keep backups somewhere other than the disk they're backing up.

And get warned before it's full. An alert at 85% gives you days to sort it out calmly, instead of minutes at 2 AM. In AskMyServers that's a disk alert rule, and the health page lists any server above 85% at the top of its recommendations.

The short version

  1. df -h and df -i
  2. du to find the big directory
  3. Logs, Docker, old backups, package cache
  4. lsof +L1 if space doesn't come back
  5. Rotation, caps and an early alert

Get warned before the disk fills up

Disk full at 2 AM: a calm checklist for Linux servers · AskMyServers