Configure Persistent systemd Journal Storage and Retention
Before you begin
- Applies to:Linux hosts that use systemd-journald.
- Where to start:Open a shell on the host whose logs you want to keep across reboots.
- What you need:Have sudo access, a free-space target, and a retention policy. Use an approved window to apply the change and verify it after reboot.
Guide tools
The systemd journal may keep logs only in volatile storage, which disappears when a host reboots. Configure persistent storage when you need logs from previous boots, then set limits so journal files do not consume the space required by the operating system.
This walkthrough uses a systemd drop-in under /etc, so package updates are less likely to overwrite the settings. The example allows up to 1 GiB of journal data and aims to leave 2 GiB free. Adjust those values to fit the host and your log-retention policy.
Check the Active Configuration and Disk Use
BaselineCheck the effective journald configuration, current disk use, and which boots have journal records. Save any locally managed settings before changing them. systemd-analyze cat-config is available on current systemd releases; on older systems, inspect /etc/systemd/journald.conf and its drop-in directory directly.
systemd-analyze cat-config systemd/journald.confjournalctl --disk-usagejournalctl --list-boots❯ Illustrative Output (Results Vary)
Archived and active journals take up 184.0M in the file system. -2 ... -1 ... 0 ...Add a journald Drop-In
ConfigurationCreate the persistent journal directory and a dedicated configuration drop-in. The tmpfiles command applies the distribution’s expected ownership and access modes to /var/log/journal. With Storage=persistent, journald uses that path for persistent data. The size and free-space limits guide cleanup; retention by age is an additional upper bound.
sudo test ! -e /etc/systemd/journald.conf.d/60-retention.conf || { echo 'Drop-in already exists; inspect and merge it instead of overwriting.' >&2; exit 1; }sudo test ! -L /etc/systemd/journald.conf.d/60-retention.conf || { echo 'Drop-in is a symlink; inspect it before making changes.' >&2; exit 1; }sudo mkdir -p /etc/systemd/journald.conf.d /var/log/journalsudo systemd-tmpfiles --create --prefix /var/log/journalsudo tee /etc/systemd/journald.conf.d/60-retention.conf >/dev/null <<'EOF'[Journal]Storage=persistentSystemMaxUse=1GSystemKeepFree=2GMaxRetentionSec=30dayEOF❯ Illustrative Output (Results Vary)
# Confirm the new settings appear in the effective configuration:systemd-analyze cat-config systemd/journald.confRestart journald and Flush Runtime Logs
ApplyRestart journald to load the drop-in, then flush runtime journal data to persistent storage. On systems with persistent storage configured, systemd normally runs the flush service during boot; this command makes the transition now.
sudo systemctl restart systemd-journaldsudo journalctl --flushjournalctl --disk-usagejournalctl --list-boots❯ Illustrative Output (Results Vary)
Archived and active journals take up 184.0M in the file system. 0 ...Confirm Logs Survive the Next Restart
VerificationAfter the next planned reboot, check the boot list and query the previous boot. A previous-boot entry will appear only after the host has rebooted since persistent storage was enabled and journald has collected records for that boot.
What you should see · After a planned reboot, the boot list includes the preceding boot and the previous-boot command returns entries.
If you see something else · If the previous boot is absent, check that you are querying the host journal with sufficient access. Review the storage setting and flush result from Step 3 before changing retention.
journalctl --list-bootsjournalctl -b -1 -n 20 --no-pager❯ Illustrative Output (Results Vary)
-1 ... previous boot 0 ... current bootFor the available storage, retention, and cleanup settings, see the systemd journald.conf manual.
Your feedback keeps these production procedures accurate and battle-tested.