How to Stop a Log File from Filling Your SSD in 5 Minutes

The problem

On a fresh SSD a single log file can grow fast enough to fill the drive in minutes.
Typical culprits are:

  • Systemd journal when systemd-journald is left to write to /var/log/journal/ without limits.
  • Application logs that never rotate, e.g. nginx, docker, postgres, or custom scripts.
  • Debug or verbose modes that are left enabled in production.

When the disk is full, services stop, new writes fail, and the machine can become unresponsive. Below is a hands‑on guide that shows how to stop a log file from filling an SSD in 5 minutes, using tools that are already part of most distributions.


1. Identify the culprit

Start by checking the biggest files in /var/log:

sudo du -ah /var/log | sort -rh | head -n 20

If you spot something like /var/log/journal/…/system.journal or a huge nginx/access.log, that’s the source.

You can also peek at the journal’s footprint with:

sudo journalctl --disk-usage

If the output reads “X GB used”, you’re already in trouble.


2. Limit the systemd journal

Systemd’s journal is very flexible. The default in 2026 is to keep all logs on disk until the disk is full, which is why it can grow uncontrollably.

2.1. Edit /etc/systemd/journald.conf

sudo nano /etc/systemd/journald.conf

Find the following lines (they may be commented out):

#Storage=auto
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=

Uncomment and set sensible limits. Example:

Storage=persistent
SystemMaxUse=500M
SystemKeepFree=200M
SystemMaxFileSize=50M
SystemMaxFiles=10
  • SystemMaxUse – total space the journal can occupy.
  • SystemKeepFree – space that will always be left free for other data.
  • SystemMaxFileSize – size of an individual journal file.
  • SystemMaxFiles – maximum number of journal files.

After editing, reload systemd:

sudo systemctl restart systemd-journald

2.2. Verify

sudo journalctl --disk-usage

You should see the new limits reflected. If the journal is already full, you may need to truncate it:

sudo journalctl --vacuum-size=200M

This keeps the most recent 200 MB of logs.


3. Rotate application logs

Most applications ship with a logrotate configuration. Verify that /etc/logrotate.d/ contains a file for the offending service.

3.1. Example: Nginx

/etc/logrotate.d/nginx usually looks like:

/var/log/nginx/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 0640 www-data adm
    sharedscripts
    postrotate
        if [ -f /run/nginx.pid ]; then
            kill -USR1 `cat /run/nginx.pid`
        fi
    endscript
}

If daily is missing, add it. The rotate 14 keeps 14 old copies; adjust as needed.

3.2. Force a rotation

sudo logrotate -f /etc/logrotate.d/nginx

Check the size again:

ls -lh /var/log/nginx/*.log

3.3. Custom scripts

If you have a custom script that writes to /var/log/myapp.log, add a minimal logrotate entry:

/var/log/myapp.log {
    weekly
    rotate 4
    compress
    missingok
    notifempty
}

Place it in /etc/logrotate.d/myapp and run logrotate -f /etc/logrotate.d/myapp to test.


4. Use tmpfs for transient logs

Some services produce logs that are needed only during a session. Mounting a small tmpfs can keep them out of the SSD.

Example: Docker daemon logs.

Create a systemd drop‑in:

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/tmpfs.conf

Add:

[Service]
StandardOutput=journal
StandardError=journal

Then create a tmpfs mount for /var/log/docker:

sudo mkdir /var/log/docker
sudo mount -t tmpfs -o size=50M tmpfs /var/log/docker

Add to /etc/fstab for persistence:

tmpfs   /var/log/docker   tmpfs   defaults,size=50M   0   0

Now Docker logs stay in RAM and never hit the SSD.


5. Monitor disk usage proactively

A single alert can prevent a full disk. Use incron or a cron job that checks /var/log size.

5.1. Simple cron job

Create /etc/cron.daily/logwatch:

#!/bin/bash
MAX=2000000   # 2 GB in kilobytes
USED=$(du -s /var/log | cut -f1)
if [ "$USED" -gt "$MAX" ]; then
    echo "Log directory is over 2 GB" | mail -s "Log alert" root
fi

Make it executable:

sudo chmod +x /etc/cron.daily/logwatch

5.2. Using incron

Install:

sudo apt install incron

Add your user to /etc/incron.allow and create /etc/incron.d/logwatch:

/var/log  IN_MODIFY,IN_CREATE,IN_DELETE  /usr/local/bin/logwatch.sh

logwatch.sh can run the same size check and truncate the largest file if needed.


6. Trade‑offs and caveats

Approach Pros Cons
Systemd journal limits Centralized, no extra tools May lose older logs if you set limits too low
Logrotate Mature, configurable Requires per‑service config; may miss custom logs
tmpfs mounts Keeps hot logs off SSD RAM consumption; logs lost on reboot
Proactive monitoring Early warning Needs email/alert setup; false positives

6.1. Security note

When truncating logs, be mindful of audit requirements. Some compliance standards require retaining logs for a minimum period. Adjust SystemMaxUse or rotate counts accordingly.

6.2. SSD wear

Frequent writes to a log file can accelerate wear on an SSD. By limiting log size and rotating, you reduce write amplification. If you’re running a high‑write‑volume system, consider using a separate SSD for logs or a log‑specific partition with a lower write‑counters policy.


7. Common pitfalls

Symptom Likely cause Fix
journalctl --disk-usage still shows >1 GB journald.conf not reloaded systemctl restart systemd-journald
Logrotate never runs logrotate cron job disabled Enable /etc/cron.daily/logrotate
Custom script logs keep growing No logrotate entry Add entry as shown in §3.3
tmpfs mount disappears after reboot Not in /etc/fstab Add entry to /etc/fstab

8. Quick checklist

  1. Identify the largest log file(s).
  2. Limit systemd journal via /etc/systemd/journald.conf.
  3. Rotate application logs with logrotate.
  4. Move transient logs to tmpfs if appropriate.
  5. Set up a monitoring job to alert before disk fills.
  6. Verify after each change with du or journalctl --disk-usage.

9. Wrap‑up

Stopping a log file from filling an SSD in minutes is mostly a matter of setting sane limits and ensuring rotation. The steps above are applicable to most Debian‑based, Arch, or Red Hat systems in 2026. Once you have the configuration in place, the system will self‑manage logs, keeping your SSD healthy and your services running.

See also