Linux and servers · Intermediate · 14 min
Keep the systemd journal small and persistent
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · systemd 259
You will have a journal that survives reboots, stays under a size and age you chose, copes with noisy services, and that you can shrink and check on demand.
On this page
The systemd journal is where your services' output, kernel messages and login records end up. Left at its defaults it can surprise you in two opposite ways. On a server where it is volatile, everything lives in memory under /run/log/journal and disappears at every reboot, which is exactly when you wanted to read why the server went down. Where it is persistent, it may keep up to 10% of the file system, capped at 4 GB. On a 25 GB VPS that is 2.5 GB of logs you never decided to keep.
In this tutorial you make both decisions yourself. You check which mode the journal is in, write a drop-in file that makes it persistent with a size, free-space and age limit, set a rate limit for services that flood the log, and practise shrinking the journal on a copy before you do it for real. Ubuntu 26.04 ships systemd 259.
None of this touches /var/log/syslog. That file belongs to rsyslog and is rotated by logrotate, which the last step covers briefly.
Step 1 · Find out where the journal is stored now
journald picks its storage from the Storage= setting:
persistentwrites to/var/log/journal, creating the folder if needed, so logs survive a reboot.volatilekeeps logs in memory under/run/log/journalonly.autois persistent if/var/log/journalalready exists, and volatile if it does not.nonedrops everything.
The default is chosen when systemd is built, so check your own server rather than assume. Start with the folders:
ls -ld /var/log/journal /run/log/journalIf /var/log/journal is listed, it holds one folder named after your machine ID with files such as system.journal. If ls says No such file or directory for it, journald has nowhere on disk to write. /run/log/journal usually exists as well; on a persistent server it only holds logs until they are flushed to disk, so it stays small or empty. If /var/log/journal is missing, your journal is volatile.
Then ask how much space the journal takes, and how much room the file system has:
journalctl --disk-usage
df -h /var/logLast, see the settings journald reads. systemd-analyze cat-config prints the packaged file and every drop-in after it, in the order they apply:
systemd-analyze cat-config systemd/journald.conf | grep -E '^#?(Storage|SystemMaxUse|SystemKeepFree|SystemMaxFileSize|MaxRetentionSec|RateLimit)'Lines that start with # are defaults shown for reference; a line without # is a value someone set.
Check it worked
You can answer three questions about your server: is the journal persistent (does /var/log/journal exist), how big is it (the figure in Archived and active journals take up ...), and how big is the file system under /var/log (the Size column from df). Write the numbers down; you use them to pick limits in the next step.
Step 2 · Write a drop-in that sets storage, size and age
Do not edit the packaged journald.conf. A package upgrade may replace it, and a drop-in shows the next admin what you changed at a glance. Files in /etc/systemd/journald.conf.d/ ending in .conf are read after the main file, and their values win.
sudo mkdir -p /etc/systemd/journald.conf.d
sudo tee /etc/systemd/journald.conf.d/50-size.conf > /dev/null <<'EOF'
# Local policy: keep the journal across reboots, but bounded.
[Journal]
Storage=persistent
SystemMaxUse=500M
SystemKeepFree=1G
SystemMaxFileSize=50M
MaxRetentionSec=1month
EOFWhat each line does:
Storage=persistentmakes journald create/var/log/journalif it is missing, so the setting no longer depends on whether a folder happens to exist.SystemMaxUse=500Mis the most the persistent journal may use in total. When it is reached, journald deletes the oldest archived files.SystemKeepFree=1Gmakes journald leave at least this much free on the file system, whateverSystemMaxUse=says. On a nearly full disk this is the limit that bites first.SystemMaxFileSize=50Mis how big one file grows before journald archives it and starts a new one. journald only ever deletes whole archived files, so smaller files mean it can trim in smaller steps. The default is an eighth ofSystemMaxUse=, which here would be 62.5M.MaxRetentionSec=1monthis a maximum age. journald deletes archived files that contain entries older than a month, even if there is space, so a few entries newer than a month can go with them. The default, 0, keeps logs for as long as space allows. It cannot promise a minimum:SystemMaxUse=andSystemKeepFree=can still delete logs sooner. If a policy says you must keep logs for a set time, also sizeSystemMaxUse=to hold that much.
Pick numbers from what you wrote down in the last step. 500M holds weeks of logs for a typical small web server. On a small, low-cost disk, a modest cap like this keeps the logs from competing with your data.
Check it worked
systemd-analyze cat-config systemd/journald.conf | grep -A 8 -Fx '# /etc/systemd/journald.conf.d/50-size.conf'The output starts with the # /etc/systemd/journald.conf.d/50-size.conf header, then your comment, [Journal] and your five settings. If nothing is printed, the header is missing: check the file name ends in .conf and sits in journald.conf.d, not journal.conf.d.
Step 3 · Set a rate limit for services that flood the log
A service stuck in a loop can write thousands of lines a second and push everything useful out of a 500M journal in minutes. journald limits each service separately: it accepts RateLimitBurst= messages per RateLimitIntervalSec=, then drops the rest until the interval ends. The default is 10000 messages in 30 seconds, and journald raises the burst on file systems with more free space (four times the value with up to 4 GB free, for example).
Write the limit in its own drop-in, so you can change it without touching the size policy:
sudo tee /etc/systemd/journald.conf.d/60-ratelimit.conf > /dev/null <<'EOF'
# Per service: at most 5000 messages in any 30 seconds (before journald's disk-space multiplier).
[Journal]
RateLimitIntervalSec=30s
RateLimitBurst=5000
EOFLowering the limit is a trade. It protects the journal from one runaway service, but during an incident you lose some of that service's lines. When journald drops messages it says so in its own log, with a line like Suppressed 1520 messages from demo-app.service. The number is how many lines that service lost in that interval. Search for these lines on your server:
journalctl -u systemd-journald.service -g Suppressed --no-pagerIf one service you trust shows up here often, give it its own limit instead of raising the limit for everyone. systemctl edit opens a drop-in for that unit; replace demo-app.service with your service:
sudo systemctl edit demo-app.serviceAdd these lines in the editor, save, then restart the service:
[Service]
LogRateLimitIntervalSec=30s
LogRateLimitBurst=20000Setting LogRateLimitIntervalSec=0 turns rate limiting off for that service. Do that only for a service whose volume you have measured.
Check it worked
systemd-analyze cat-config systemd/journald.conf | sed -n '\|^# /etc/systemd/journald.conf.d/50-size.conf$|,$p'You see the 50-size.conf block, then the # /etc/systemd/journald.conf.d/60-ratelimit.conf header, its comment, [Journal] and your two settings. Drop-ins apply in file-name order, whichever folder they sit in, and the number prefixes keep that order predictable. On Ubuntu the list usually ends with # /usr/lib/systemd/journald.conf.d/syslog.conf, a drop-in the package ships that sets only ForwardToSyslog=yes. Its name sorts after yours, so it comes last, but it does not touch any setting you chose. The journalctl -g Suppressed search either prints -- No entries --, meaning nothing has been dropped, or lists the services you need to look at.
Step 4 · Restart journald so the settings apply
journald reads its configuration when it starts. Restart it:
sudo systemctl restart systemd-journaldIf the journal was volatile until now, move what is in memory to disk, so you do not lose the logs from the current boot:
sudo journalctl --flush--flush is safe to run more than once; it does nothing if the data has already moved.
Check it worked
journalctl -u systemd-journald.service -n 5 --no-pager
ls /var/log/journalAfter the restart journald logs a summary with the limit it worked out, something like System Journal (/var/log/journal/3f2a...) is 48.0M, max 500.0M, 451.9M free. The max figure is the smaller of SystemMaxUse= and what SystemKeepFree= leaves, so it can be lower than 500M on a full disk. A warning naming the drop-in file and line number, something like Unknown key 'SystemMaxUsage' in section [Journal], ignoring., means a typo in a drop-in; journald skips that line and carries on. ls /var/log/journal shows the folder named after your machine ID.
Step 5 · Practise vacuuming on a copy
journald trims the journal on its own from now on. You still need to shrink it by hand sometimes, for example when a disk fills at 2 a.m. and you want space back now. journalctl --vacuum-size= and --vacuum-time= do that, and their deletions cannot be undone. Try them on a copy first.
The copy is as big as journalctl --disk-usage said. Check that your home folder has that much free (df -h ~) before you run this:
sudo cp -a /var/log/journal ~/journal-demo
sudo journalctl --directory ~/journal-demo --disk-usage--directory makes journalctl work on the files in that folder instead of the live journal. Read the newest few entries from the copy to be sure it holds real data:
sudo journalctl --directory ~/journal-demo -n 3 --no-pagerNow remove everything older than 30 days from the copy:
sudo journalctl --directory ~/journal-demo --vacuum-time=30dThen cap the copy at a total size:
sudo journalctl --directory ~/journal-demo --vacuum-size=200M
sudo journalctl --directory ~/journal-demo --disk-usageBoth vacuum commands only delete archived files, the ones with @ in their names. The active files, system.journal and user-1000.journal for example, are never touched. So on a server that has run for only a few days the copy may have nothing to delete. That is expected, and it is why a cap can never get the journal below the size of its active files.
Check it worked
Each vacuum command ends with a line like Vacuuming done, freed 96.0M of archived journals from /home/you/journal-demo/3f2a.... The --disk-usage figure after --vacuum-size=200M is 200M or less, unless only active files remain. Run sudo ls ~/journal-demo/*/ and you see that the oldest archived files, the ones with the lowest sequence numbers in their names, have gone first. To see the oldest entry that is left, run sudo journalctl --directory ~/journal-demo --list-boots.
Step 6 · Shrink and check the live journal
When you need space back on the server, run the same command without --directory. Choose the size or age you can afford to lose:
sudo journalctl --vacuum-time=1month
sudo journalctl --vacuum-size=500MTo include what journald is writing right now, ask it to archive the active files first. --rotate combined with a vacuum option rotates, then vacuums:
sudo journalctl --rotate --vacuum-size=500MAfter an unclean shutdown, or before you hand logs to someone investigating an incident, check the files for damage:
sudo journalctl --verifyCheck it worked
journalctl --verify prints a PASS: line for each file. A file reported as corrupted after a power cut is not a crisis: journald archives a damaged active file and starts a new one, and journalctl reads what it can from the old one. Run journalctl --disk-usage again; the figure is within the limits you set.
Step 7 · See where rsyslog and logrotate fit
Some Ubuntu servers run rsyslog too. It reads messages from journald and writes plain text files such as /var/log/syslog and /var/log/auth.log. Those files are not part of the journal: SystemMaxUse= does not limit them and journalctl --vacuum-size= does not shrink them. Check whether rsyslog runs on your server and how its files are rotated:
systemctl is-active rsyslog
ls -lh /var/log/syslog*
cat /etc/logrotate.d/rsyslogIf rsyslog is active, the same message is stored twice: once in the journal, once in /var/log/syslog. That is fine if a tool you run reads the text files. Size those with logrotate, covered in /tutorials/manage-log-files-with-logrotate, and count both against your disk.
Check it worked
You know whether your server has one log store or two. If systemctl is-active rsyslog prints active, /etc/logrotate.d/rsyslog names the files and how many old copies it keeps. If it prints inactive or says the unit is not found, the journal is your only system log, and the limits in your drop-ins are the whole policy.
Step 8 · Remove the practice copy
The drop-ins are the point of this tutorial, so leave them in place. The next command deletes only the copy you made for practice. Check the path before you run it:
sudo rm -rf ~/journal-demoIf you ever want journald's defaults back, delete /etc/systemd/journald.conf.d/50-size.conf and 60-ratelimit.conf, then restart systemd-journald as before.
Check it worked
ls ~ no longer lists journal-demo, and ls /etc/systemd/journald.conf.d still shows 50-size.conf and 60-ratelimit.conf.
Next steps
- Query the journal you now keep:
/tutorials/search-the-systemd-journal-with-journalctl. - Rotate the plain-text logs that rsyslog and your apps write:
/tutorials/manage-log-files-with-logrotate. - Find out what else is filling the disk:
/tutorials/find-what-is-using-disk-space-linux.
Related tutorials
- Write safer Bash scripts with strict mode and trapsYou will build a small Bash release script that stops on the first error, says which line failed, survives file names with spaces and always removes its temporary files.
- Write least-privilege sudo rules with visudoYou will replace blanket sudo access with checked rule files in /etc/sudoers.d that let two operators restart one service and edit one file, give an automation account a password-free command list, and audit what every account can run.
- Upgrade a server from Ubuntu 24.04 LTS to 26.04 LTSYou will take a backed-up Ubuntu 24.04 server through do-release-upgrade to 26.04 LTS over SSH with a fallback login, then confirm services, repositories and language runtimes work on the new release.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials