Keep the systemd journal across reboots and cap its size
Make journald keep logs across reboots, set a size ceiling, verify it worked, and undo it. Applies to systemd-based Linux distributions.
Updated Reviewed
On this page
By default some systemd distributions keep the journal only in memory, so the logs you most need after a crash disappear with the reboot. This guide makes the journal persistent and puts a limit on the disk it may use.
Prerequisites
- A Linux system running systemd with
systemd-journald. - Root access or
sudo. - Enough free disk space for the size limit you choose (check with
df -h /var).
Steps
-
Check the current state. Note how many boots are listed and how much space the journal uses:
Bashjournalctl --list-boots journalctl --disk-usage -
Create the persistent storage directory. With the default
Storage=auto, journald stores logs on disk only when this directory exists:Bashsudo mkdir -p /var/log/journal -
Open the journald configuration drop-in for editing (preferred over editing the main file, so package updates do not overwrite your change):
Bashsudo mkdir -p /etc/systemd/journald.conf.d sudo nano /etc/systemd/journald.conf.d/50-persistent.conf -
Add these lines, adjusting the size to suit the disk:
INI[Journal] Storage=persistent SystemMaxUse=500MStorage=persistentstores logs under/var/log/journal(creating it if needed).SystemMaxUse=caps the total disk space used by the journal. -
Restart the journal service:
Bashsudo systemctl restart systemd-journald -
Optionally move the existing in-memory logs to disk straight away:
Bashsudo journalctl --flush
Verify it worked
-
Confirm journal files exist on disk:
Bashls /var/log/journal/*/ -
Confirm usage is reported and under your cap:
Bashjournalctl --disk-usage -
After the next reboot, confirm more than one boot is listed:
Bashjournalctl --list-boots -
Read the previous boot's errors:
Bashjournalctl -b -1 -p err
Trim the journal manually (optional)
To free space immediately, remove old archived entries by size or age:
sudo journalctl --vacuum-size=500M
sudo journalctl --vacuum-time=30d
Undo
-
Remove the drop-in file:
Bashsudo rm /etc/systemd/journald.conf.d/50-persistent.conf -
If you want logs back in memory only, remove the stored journal and the directory (this deletes the saved logs):
Bashsudo rm -r /var/log/journal -
Restart the service:
Bashsudo systemctl restart systemd-journald
Troubleshooting
- Only one boot is listed after a reboot: confirm
/var/log/journalexists and that the restart in step 5 succeeded (systemctl status systemd-journald). - A setting seems ignored: drop-in files are read in alphabetical order and later files win; check for other files with
systemd-analyze cat-config systemd/journald.conf. - Distribution defaults differ: some distributions already enable persistent storage. If step 1 already lists several boots, no change is needed.
For the full list of options, see man journald.conf and man journalctl.