Skip to main content
Modern Linux distributions using systemd include a structured logging service called systemd-journald. The journal aggregates logs from multiple sources: the kernel, system services, applications, and the stdout/stderr streams of systemd-managed services. This guide shows how to enable persistent journal storage and how to use the journalctl command to query and follow logs effectively. What you’ll learn
  • How to enable persistent on-disk journaling.
  • How to verify journal files and disk usage.
  • Common journalctl filters and usage patterns for troubleshooting.

Understanding systemd-journald

systemd-journald stores logs in a binary, indexed format that supports structured fields (e.g., _PID=, _COMM=, _SYSTEMD_UNIT=). You can query those fields with journalctl to produce focused, high-signal output for debugging and operational tasks.

Enable persistent journal storage

Many distributions default to in-memory journaling (volatile storage). To keep the journal across reboots, set Storage=persistent in /etc/systemd/journald.conf. Steps:
  1. If an /etc/systemd/journald.conf doesn’t already exist, copy the vendor-provided configuration:
  1. Edit the file and set Storage=persistent:
  1. Reload systemd unit files and restart journald:
Note: If your distribution already provides /etc/systemd/journald.conf, edit that file directly instead of copying from /usr/lib/....

Verify the journal directory and disk usage

When Storage=persistent is enabled, journals are stored under /var/log/journal. Verify presence and usage: List /var/log to confirm a journal directory:
Check how much disk space the journal occupies:

Common journalctl filters and examples

journalctl supports a rich set of filters. Below is a quick reference of the most commonly used options, followed by examples. Examples (kept in the original sequence for clarity):
  1. Entries from the current boot:
  1. Entries for a specific unit (example: sshd):
  1. Filter by priority (show errors and worse):
  1. Show only the last N entries (example N=10):
  1. Follow logs in real time:

Additional tips and configuration for long-term retention

  • Use structured-field matches: journalctl _PID=1234 or journalctl _COMM=sshd.
  • Limit disk usage and retention by configuring /etc/systemd/journald.conf:
    • SystemMaxUse= — maximum disk space for all system journals.
    • SystemKeepFree= — amount of disk space to keep free for other uses.
    • SystemMaxFileSize= — maximum size for individual journal files.
  • For targeted troubleshooting of services, prefer:
    • journalctl -u <unit> -n 100 (last 100 lines for a unit)
    • journalctl -u <unit> -f (follow unit logs in real time)
For examinations or deeper troubleshooting, use man journalctl to review all flags and structured-field matching. Familiarity with journalctl options is valuable for both ops and troubleshooting scenarios.

Man page excerpt (reference)

This concludes the lesson. You should now be able to enable persistent journaling and use journalctl effectively to inspect and follow system logs.

Watch Video