Sub topic 3
The systemd journal
This chapter assumes you can use systemctl and read unit status, and that you know the /var/log directory. It covers what the journal is, how it stores entries, how to query it, and how it connects to rsyslog. Size limits and retention come in a later chapter.
What the journal is
systemd-journald is the service that collects log output on a systemd host. It receives messages from several sources:
- Kernel messages, from the kernel ring buffer.
- Standard output and standard error of services run by systemd.
- Messages sent to the syslog socket, for example by
loggeror by programs that callsyslog(). - Messages sent through the native journal API.
- Audit records, when auditing is enabled.
Unlike a plain syslog daemon, journald does not write text lines. It stores each entry as a set of key=value fields in a binary, indexed file. The entry keeps the message text, and it also keeps metadata that journald reads from the kernel at the moment the message arrives. A process cannot easily forge that metadata, so you can trust it more than a hostname or program name typed into a text line.
Some fields you will use often:
| Field | Meaning |
|---|---|
| `MESSAGE` | The log text |
| `PRIORITY` | Syslog severity, 0 (emerg) to 7 (debug) |
| `SYSLOG_IDENTIFIER` | The program tag, such as `sshd` |
| `_SYSTEMD_UNIT` | The unit that owns the process |
| `_PID`, `_UID` | Process and user IDs of the sender |
| `_HOSTNAME` | Host that produced the entry |
| `_TRANSPORT` | How the entry arrived: `journal`, `syslog`, `kernel`, `stdout`, `audit` or `driver` |
Fields that start with an underscore are trusted fields added by journald. Fields without one are set by the sender.
How the journal relates to rsyslog and /var/log
The journal does not replace rsyslog on most servers. The two run side by side. Journald collects and indexes everything locally. rsyslog then takes a copy and does what journald cannot do well: write classic text files under /var/log and forward messages over the network.
How rsyslog gets its copy depends on the distribution. Red Hat-family systems load the imjournal input module, which reads the journal directly. Debian-family systems have journald pass messages to a socket that rsyslog's imuxsock module listens on. The later chapters on forwarding rely on this arrangement.
Volatile and persistent storage
Where the journal lives on disk is controlled by the Storage= setting in journald.conf:
volatilekeeps the journal in/run/log/journal. This is a tmpfs, so the journal is lost at every reboot.persistentkeeps it in/var/log/journaland creates that directory if it is missing. It falls back to/runearly in boot, before/varis mounted.autois the default. It writes to/var/log/journalonly if that directory already exists. Otherwise it behaves likevolatile.nonediscards all stored logs. Forwarding still works.
The auto default surprises people. Some distributions ship without /var/log/journal, so the journal is volatile and journalctl -b -1 (the previous boot) reports nothing. That is a real problem after a crash, because the evidence is gone. To check which mode you are in:
ls -d /var/log/journal /run/log/journal
journalctl --list-boots
journalctl --disk-usageIf --list-boots shows only one boot, your journal is not persistent. To make it persistent, either create the directory or set Storage=persistent (the retention chapter shows the drop-in file):
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journaldThe systemd-tmpfiles call sets the correct ownership and ACLs on the new directory.
Querying with journalctl
journalctl reads the journal. Filters combine with AND, and several matches on the same field combine with OR.
# Everything from one unit since the last hour
journalctl -u sshd.service --since "1 hour ago"
# Warnings and worse, current boot only
journalctl -b -p warning
# Previous boot, kernel messages only
journalctl -b -1 -k
# Follow new entries as they arrive
journalctl -f -u nginx.service
# Match any journal field directly
journalctl _SYSTEMD_UNIT=cron.service _PID=812
# See the raw fields of the newest entry
journalctl -n 1 -o json-prettySome details matter in practice:
-p warningmeans "warning and anything more severe", so it includes error, critical, alert and emergency. Use-p warning..errfor a range.--sinceand--untilaccept timestamps such as"2026-11-28 03:00"and words such asyesterday.- Unit names usually need the right suffix. On Debian-family systems the SSH service is
ssh.service, notsshd.service. journalctl -F _SYSTEMD_UNITlists every value a field has taken. This is a quick way to discover what is in the journal.-oselects the output format.shortis the default.short-isogives sortable timestamps,jsonsuits scripts, andcatprints only the message.
Who can read the journal
By default, only root and members of the systemd-journal group can read system-wide entries. Members of adm and wheel can also read them, through ACLs that journald sets on the journal files. An unprivileged user sees only their own entries and gets a hint such as "Hint: You are currently not seeing messages from other users and the system". To give an operator read access without sudo, add them to the group:
sudo usermod -aG systemd-journal aliceIntegrity and limits of the format
The binary format has trade-offs you should know about:
- Ordinary tools such as
grepandtailcannot read the files. Usejournalctl, or export entries withjournalctl -o exportor-o json. - A journal file that was open during a crash or power loss can be corrupted. journald renames the damaged file with a
~suffix and starts a new one.journalctl --verifychecks the files for consistency. - Forward Secure Sealing (
journalctl --setup-keys) can make tampering detectable, but it is rarely used. Shipping logs to another host is the stronger protection, because an attacker who gains root on a server can still alter that server's local files. - A journal entry is not a rotated file. journald manages its own file rotation and deletion, so logrotate does not apply to the journal.
Common mistakes
- Assuming the journal survives reboots. Check
journalctl --list-bootsbefore you depend on it. - Filtering with the wrong unit name. Use
systemctl list-units --type=serviceto find the exact name. - Reading
-p erras "only errors". It includes everything more severe as well. - Running
journalctlas a normal user and concluding the logs are empty.
Exercise
A server crashed overnight. After it came back, journalctl -b -1 prints "no persistent journal was found". What is the likely cause, and what two steps would you take so the next crash can be investigated?
Show answer
The journal is volatile. Storage=auto is the default, and it writes to /var/log/journal only if that directory exists, so the journal lived in /run/log/journal and was lost at reboot. Make it persistent by creating /var/log/journal (then run systemd-tmpfiles --create --prefix /var/log/journal) or by setting Storage=persistent, and restart systemd-journald. After that, journalctl --list-boots will show previous boots.
Exercise
Write a journalctl command that shows only messages of severity error or worse from the nginx service during the current boot.
Show answer
journalctl -b -u nginx.service -p err. The -p err filter includes err, crit, alert and emerg.