journald and journalctl

Intermediate · 20 min

How the systemd journal stores logs as structured, indexed entries, the journalctl filters that matter, and how persistence and disk limits work.

Before thisUnits, targets and dependencies

Learn Linux TV · 20 min

journald and journalctl

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Learn Linux TVReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • journald collects stdout and stderr of every service, syslog messages, kernel messages and native journal calls into one store, with metadata attached to every line.
  • Each entry is a set of fields. Fields starting with an underscore, like _PID and _SYSTEMD_UNIT, are added by journald and cannot be faked by the program.
  • The everyday filters are -u for a unit, -b for a boot, -p for priority, --since/--until for time, -g for a pattern, -k for the kernel and -f to follow. They combine.
  • Logs survive a reboot only if they are stored under /var/log/journal. With Storage=auto, the existence of that directory decides.
  • By default the journal may use 10% of its filesystem and must leave 15% free, each capped at 4G. `journalctl --disk-usage` and `--vacuum-size=` manage it.
  • Members of the systemd-journal, adm or wheel groups can read the whole journal without sudo.

The problem with a pile of text files

A service fails at 02:14. On a classic syslog box you open /var/log/syslog, then daemon.log, then the app’s own file in /var/log/myapp/, and grep each for the time. If the service printed something to stderr before it died, that went nowhere at all, because no file was attached to it. And every line is a string, so “show me only errors from this one service since the last boot” means a grep pattern you hope matches.

journald, the logging half of systemd, changes the unit of storage from a line of text to a record with fields. Once logs are records, filtering by service, boot, priority and time are lookups, not text searches.

What journald collects

systemd-journald.service receives:

  • the stdout and stderr of every service systemd starts, so a print() in your app is logged with no setup,
  • messages sent to the syslog socket /dev/log,
  • kernel messages, the ones dmesg shows,
  • structured messages from programs that call the journal API directly.

It stores each message with metadata. Fields beginning with an underscore are what systemd.journal-fields(7) calls trusted fields: journald adds them from the sending process’s credentials, and the program cannot set them. _PID, _UID, _COMM, _EXE, _SYSTEMD_UNIT, _BOOT_ID and _TRANSPORT are among them. Fields without an underscore, such as MESSAGE, PRIORITY and SYSLOG_IDENTIFIER, come from the client. That difference matters when you investigate an intrusion: a process can claim any SYSLOG_IDENTIFIER, but not a different _SYSTEMD_UNIT.

journalctl -o verbose prints every field of each entry, and -o json prints one JSON object per line for scripts.

The filters

All from journalctl(1). I had no Linux machine to run them on, so there is no output here.

journalctl -u nginx.service           # one unit (adds a _SYSTEMD_UNIT= match and friends)
journalctl -b                         # this boot only
journalctl -b -1                      # the boot before this one
journalctl --list-boots               # which boots the journal holds
journalctl -p err                     # err and everything more severe
journalctl --since "2026-11-28 02:00" --until "2026-11-28 02:30"
journalctl --since -1h                # relative times work too
journalctl -g 'timeout|refused'       # regex over MESSAGE
journalctl -k                         # kernel messages, like dmesg
journalctl -f -u nginx                # follow, like tail -f
journalctl _PID=4123                  # any field match, FIELD=VALUE
journalctl -e                         # jump to the end in the pager

They combine. journalctl -b -1 -p warning -u postgresql is “warnings and worse from postgres during the previous boot”, which with text files is an afternoon.

Priorities are the eight syslog levels: emerg (0), alert, crit, err, warning, notice, info, debug (7). A single value shows that level and everything more important. -p also takes a FROM..TO range when you want one band only.

Who can read it

Your own processes’ logs are readable to you. Per journalctl(1), members of the systemd-journal, adm and wheel groups can read all journal files. Adding an operator to systemd-journal gives log access without full sudo.

Volatile or persistent

journald.conf(5) offers four Storage= values:

  • volatile: in memory under /run/log/journal, gone at reboot.
  • persistent: on disk under /var/log/journal, falling back to /run early in boot.
  • auto: persistent if /var/log/journal exists, volatile otherwise.
  • none: keep nothing, only forward.

I downloaded Debian 13’s systemd 257.13 package and unpacked it on this Mac. Its /etc/systemd/journald.conf is all comments showing compile-time defaults, starting:

[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=10000

So Debian uses auto. Its install script then does this:

# Enable persistent journal, in auto-mode, by default on new installs
if [ -z "$2" ]; then
    mkdir -p "$DPKG_ROOT/var/log/journal"
fi

A fresh Debian install keeps logs across reboots. A machine upgraded from an old release, a minimal image or another distribution may not. Check with ls /var/log/journal, and if journalctl --list-boots shows only one boot on a machine that has rebooted, you are volatile. To change it, create the directory or set Storage=persistent in a drop-in such as /etc/systemd/journald.conf.d/persist.conf, then restart systemd-journald. The comment at the top of that Debian file recommends drop-ins over editing it.

Disk limits

The journal manages its own size. SystemMaxUse= (how much it may use) defaults to 10% of the filesystem, and SystemKeepFree= (how much it must leave) to 15%, each capped at 4G. journald respects whichever is smaller. The man page adds a catch: only archived files are deleted, so usage can briefly exceed the limit, and if something else fills the disk, journald stops growing but does not shrink.

For an immediate cut:

journalctl --disk-usage
journalctl --vacuum-size=500M      # delete oldest archived files until under 500M
journalctl --vacuum-time=2weeks    # or by age

Vacuuming is a one-off. Put SystemMaxUse= in a drop-in to make the limit stick.

The rate limit above is per service: by default more than 10,000 messages in 30 seconds and the rest are dropped, with a message saying how many. The man page adds that the burst is scaled up with the free disk space, so the real threshold is usually higher. A chatty service that seems to have gaps in its logs may be hitting it.

About the video

The embed is all of Learn Linux TV’s “journalctl Basics: How to Easily Check Your Linux Logs”, March 2025, about 20 minutes. Its chapters cover what journalctl is, basic use, inspecting a service, following output, troubleshooting OpenSSH with it, viewing a time range, entries from one user, and shrinking size with vacuum. That is most of the filter section. From the chapters it does not cover structured fields, persistence or the size defaults, so the lesson goes further there. English was judged from the channel and its English auto-caption track. I judged it from its chapters, not a full watch. The Akamai video in deeper is also a deeper link in the devops systemd lesson.

What was run: downloading and unpacking Debian 13’s systemd package and reading journald.conf and the package’s install script on macOS. Everything about journald’s behaviour is from the systemd 262 man pages, checked 2026-11-28.

Where this fits

Many servers still run a syslog daemon beside the journal, to write classic text files or ship logs elsewhere, and those files need rotating. That is next: syslog and log rotation.

Check yourself

  1. 01A service crashed and the server rebooted. `journalctl -b -1 -u myapp` says there are no entries. What is the likely reason?

    The journal is not persistent, so the previous boot's logs lived in /run/log/journal and were lost at reboot. Create /var/log/journal or set Storage=persistent.

  2. 02How do you show only errors and worse from the current boot?

    `journalctl -b -p err`. A single priority shows that level and everything more severe.

  3. 03Why can you trust _SYSTEMD_UNIT in an entry more than SYSLOG_IDENTIFIER?

    Underscore fields are trusted fields that journald adds itself from the sending process's credentials. SYSLOG_IDENTIFIER is supplied by the client and can say anything.

  4. 04The disk is full and /var/log/journal holds 4 GB. How do you cut it to 500 MB now, and how do you stop it growing back?

    Run `journalctl --vacuum-size=500M` to delete the oldest archived files. Set SystemMaxUse=500M in a journald.conf.d drop-in and restart systemd-journald so the limit holds.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark