Sub topic 7
Limiting journal size and age
This chapter shows how to cap the systemd journal by size and by age, so it can't fill the disk. It assumes you can edit files as root, use systemctl, and know what /var/log holds. It also assumes you know what systemd-journald is from the earlier chapter on the journal.
Why the journal needs limits
journald stores entries in binary files. These are not rotated by logrotate. journald rotates and deletes them itself, according to its own settings. If you leave those settings alone, the journal can grow to a large share of the disk. The defaults are conservative, but they are percentages of the filesystem. On a small root volume that is shared with databases or application data, those percentages can still be too much.
The limits matter more once you centralise logs. If every server forwards its messages to a central host, the local journal only needs a short window for debugging. You can then size it deliberately instead of accepting a default.
Where the journal is stored
The Storage= setting decides where journald keeps data.
| Value | Behaviour |
|---|---|
| `volatile` | Keeps the journal in `/run/log/journal`, which is memory-backed. It is lost at reboot. |
| `persistent` | Writes to `/var/log/journal` and creates the directory if needed. It falls back to `/run` early in boot, before `/var` is available. |
| `auto` | Writes to `/var/log/journal` only if that directory already exists. Otherwise it behaves like `volatile`. This is the default. |
| `none` | Discards all stored data. Forwarding to syslog or the console still works. |
Debian and Ubuntu usually ship with /var/log/journal present. Some other distributions do not, so their journal disappears on reboot until you create the directory or set Storage=persistent.
The settings that cap the journal
Two groups of settings exist, because journald uses two locations. Settings starting with System apply to /var/log/journal. Settings starting with Runtime apply to /run/log/journal. Each group has the same parameters.
| Setting | Meaning | Default |
|---|---|---|
| `SystemMaxUse=` | The most disk space the persistent journal may use in total. | 10% of the filesystem, capped at 4 GB |
| `SystemKeepFree=` | The free space journald leaves on the filesystem for other uses. | 15% of the filesystem, capped at 4 GB |
| `SystemMaxFileSize=` | The size at which one journal file is rotated. | 1/8 of `SystemMaxUse=` |
| `SystemMaxFiles=` | The most journal files to keep. | 100 |
| `MaxRetentionSec=` | The oldest age an entry may reach before it is removed. | 0 (off) |
| `MaxFileSec=` | The time after which a journal file is rotated, even if it is small. | 1 month |
Values accept the suffixes K, M, G and T for sizes, and s, min, h, day, week, month and year for times.
Journald applies whichever limit is hit first. If SystemMaxUse= says 500 MB but SystemKeepFree= would leave less free space than configured, journald stops earlier. SystemMaxUse= is also used to derive the per-file size, so a small cap produces small files, and that gives finer-grained deletion.
A retention drop-in
Do not edit /etc/systemd/journald.conf directly. Put your changes in a drop-in file, so package upgrades never overwrite them and you can manage the file with configuration tools.
# /etc/systemd/journald.conf.d/retention.conf
[Journal]
Storage=persistent
SystemMaxUse=500M
MaxRetentionSec=1monthThis keeps the journal on disk across reboots. It limits the persistent journal to 500 MB, and removes entries older than one month. Whichever limit is reached first wins. On a busy server the size cap usually triggers first. On a quiet one the age cap does.
Create the directory if it doesn't exist, write the file, then restart the service.
sudo mkdir -p /etc/systemd/journald.conf.d
sudoedit /etc/systemd/journald.conf.d/retention.conf
sudo systemctl restart systemd-journaldCheck that journald actually read your values. This command prints the merged configuration with the file each part came from.
systemd-analyze cat-config systemd/journald.confIf you just switched from volatile to persistent storage, journalctl --flush copies the data from /run/log/journal into /var/log/journal immediately.
Inspecting and trimming the journal by hand
You don't have to wait for journald to enforce limits. These commands show the current state and clear space immediately.
# How much space the journal uses now
journalctl --disk-usage
# Delete archived files until the journal is at most 200 MB
sudo journalctl --vacuum-size=200M
# Delete entries older than two weeks
sudo journalctl --vacuum-time=2weeks
# Keep only the newest 10 journal files
sudo journalctl --vacuum-files=10
# Check the files for corruption
sudo journalctl --verifyVacuuming only removes archived files. The file journald is writing to right now is never deleted. To free that data too, rotate first, so the active file becomes an archive.
sudo journalctl --rotate
sudo journalctl --vacuum-time=1sVacuum commands are one-off. They do not change the configuration, so the journal can grow back to the configured limits. Use them in emergencies, and use the drop-in for the lasting policy.
Choosing values
There is no universal number. These questions help.
- How far back do you debug on the machine itself? If everything is forwarded centrally, a few days is often enough, and 200 MB to 500 MB covers it on most servers.
- How big is the filesystem? On a 20 GB root volume, the default of 10% is 2 GB. That is probably more than you want to give away.
- How chatty are the services? Measure first. Run
journalctl --disk-usageafter a week, and compare with the number of days of history you can reach withjournalctl --list-bootsandjournalctl --since. - Do you need logs to survive reboots? Almost always yes. A crash or kernel panic is the moment you most need the previous boot's logs, and volatile storage loses them.
Setting both a size and an age is deliberate. The size cap protects the disk during an error storm. The age cap stops very old data lingering on quiet machines, which matters if you have a data retention policy.
Common problems
- The limits seem ignored. A drop-in with a typo in a key name, or a missing
[Journal]header, is skipped silently or with only a message in the journal. Runsystemd-analyze cat-config systemd/journald.confand look at the section header and spelling. - Usage is above
SystemMaxUse=. The cap is enforced when files rotate, and the active file counts toward the total. Short overshoots happen. If usage stays above the cap, look for another filesystem layout, such as/var/log/journalon a different mount with its own limits. - Logs are missing after reboot. Storage is still
autoand/var/log/journaldoesn't exist. SetStorage=persistentand restart journald. - A noisy service floods the journal. journald rate-limits each service with
RateLimitIntervalSec=andRateLimitBurst=. Dropped messages are reported in the journal. Fix the noisy service first, and raise the rate limit only if you are losing wanted messages.
Exercise
A server has a 40 GB root filesystem and journald uses its defaults. You want the journal to persist across reboots, use at most 1 GB, and drop entries older than 14 days. Write the drop-in contents, and give the command that confirms how much space the journal uses now.
Show answer
Contents of /etc/systemd/journald.conf.d/retention.conf:
[Journal]
Storage=persistent
SystemMaxUse=1G
MaxRetentionSec=2week
Restart with sudo systemctl restart systemd-journald. Confirm current usage with journalctl --disk-usage. You can verify the merged settings with systemd-analyze cat-config systemd/journald.conf. MaxRetentionSec=14day is equivalent.
Exercise
You run sudo journalctl --vacuum-time=1d, but journalctl --disk-usage still reports a large size. Give one likely reason and a way to free more space.
Show answer
Vacuuming deletes only archived files, and the active file is untouched. If most of the data sits in the active file, or in archives younger than one day, it remains. Run sudo journalctl --rotate to turn the active file into an archive, then repeat the vacuum command, or use --vacuum-size= to cap the total.