journald: persistent storage and log size limits
Enable persistent journald storage, read the logs of an offline system and limit their size.
By default, systemd-journald does not always keep logs across reboots, and their size is not always limited. This article explains how to enable persistent storage, read the journals of an offline system and cap the disk space they use. For background, see Enable persistent logging in systemd-journald and freedesktop bug 86034.
Enable persistent storage
In /etc/systemd/journald.conf, the default is Storage=auto. To force persistent storage:
sudo sed -i 's/#Storage=auto/Storage=persistent/' /etc/systemd/journald.conf
sudo systemctl restart systemd-journald.service
Then create the /var/log/journal directory if it does not exist:
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journald
Read the journals of an offline system
When the system is mounted from another machine or environment, journalctl can be pointed at its root directory:
| Command | Effect |
|---|---|
journalctl --root=<root-path> -m |
Reads the journals under the given root |
journalctl --directory=<root-path>/var/log/journal/<machine-id> |
Reads the journal directory of one specific machine |
The -m option merges the journals from all directories found in /var/log/journal/.
Alternatively, chroot into the host system, then use journalctl --directory=/var/log/journal/<machine-id> or journalctl -m.
Limit the journal size
Status and cleanup commands:
journalctl --list-boots
journalctl --disk-usage
journalctl --verify
sudo journalctl --vacuum-size=200M
--vacuum-size deletes old archived journal files until the total size is below the given value.
To limit the size permanently, add the following to /etc/systemd/journald.conf:
[Journal]
SystemMaxFileSize=100M
SystemMaxUse=300M
Then restart the service:
sudo systemctl restart systemd-journald
Search example
Show the clamd and clamav logs for the current boot:
journalctl -u 'clamd*' -u 'clamav*' -b
-b limits the output to the current boot.