When a Linux host drops off a load balancer or runs low on disk space under /var, systemctl and journalctl are almost always the fastest path to the actual answer. Across years of debugging production Linux nodes, the biggest mistake I see people make is reaching for systemctl restart or rm -rf /var/log/journal/* before reading the binary journal. Restarting wipes transient clues, and deleting active journal files out from under systemd-journald leaves file descriptors open or corrupts your audit trail.
These steps apply to any modern systemd distribution, including Ubuntu 24.04/26.04 LTS, Debian 12/13, Fedora, RHEL/Alma/Rocky, and Arch Linux.
Diagram: Original SVG schematic by Ajay Kumar Chaturvedi.
Prerequisites and Safety Checks
Confirm these basics before inspecting or pruning logs:
- Shell access with
sudo(or membership in theadmgroup on Ubuntu/Debian,wheelon Fedora/RHEL, orsystemd-journalon Arch). - Read-only triage comes first; do not restart units or trim logs until you capture any error lines needed for an incident report.
Backup and Data-Loss Warning: Pruning journal logs with--vacuum-sizeor--vacuum-timepermanently deletes archived binary log files. If you are investigating a crash or security event, copy or export the relevant journal slice (journalctl -b -1 > /tmp/prev-boot.log) before rotating and vacuuming.
Step-by-Step Procedure
Step 1: Identify Failed Units Without Clearing State
Target OS: All systemd distributions (Ubuntu, Debian, Fedora, Arch).
List every unit currently in a failed state across the system:
systemctl --failedIf you suspect a user-level background job (for example a rootless container service or desktop daemon), check the per-user service manager as your normal user:
systemctl --user --failedInspect the unit's current metadata, exit code, and trailing log lines:
systemctl status <unit>.service --no-pagerAs the ArchWiki Systemd guide notes, avoid running systemctl reset-failed until you finish debugging, because resetting can unload the unit depending on CollectMode and make systemctl status stop showing its failure context.
Step 2: Filter Unit Logs by Boot, Priority, and Pattern
Target OS: All systemd distributions (Ubuntu, Debian, Fedora, Arch).
Instead of scrolling through thousands of info lines, filter directly in journalctl by unit, current boot (-b), and syslog priority (err through alert, or 0..3):
sudo journalctl -u <unit>.service -b -p err..alert --no-pagerFor user services, use --user-unit instead of -u. When you need context right before a crash, constrain by relative time and native regex filtering via --grep rather than piping to external grep:
sudo journalctl -u <unit>.service --since "30 min ago" --grep="timeout|denied"According to the ArchWiki Journal guide, native --grep avoids formatting lines that do not match, which is noticeably faster on multi-gigabyte journals.
Step 3: Catch Logs for Short-Lived Processes and Previous Boots
Target OS: All systemd distributions (Ubuntu, Debian, Fedora, Arch).
Two common edge cases make beginners think journalctl lost their logs:
- Short-lived processes: If a service crashes milliseconds after launch,
systemd-journaldreads/procmetadata asynchronously and may fail to attach_SYSTEMD_UNITbefore the PID disappears. Grab theMain PIDnumber fromsystemctl status <unit>.serviceand query the kernel PID field directly:
sudo journalctl -b _PID=<pid>- Previous crashed boot: If the host rebooted or panicked, query the previous boot with
-b -1(or list recorded boots withjournalctl --list-boots):
sudo journalctl -b -1 -p err..alertIf --list-boots shows only the current boot, the distro's Storage= mode is likely auto without /var/log/journal created (volatile logs in /run/log/journal vanish on reboot). Ubuntu, Fedora, and Arch enable persistent storage by default, whereas minimal Debian images sometimes omit /var/log/journal unless configured.
Step 4: Check Journal Disk Usage and Trim Safely
Target OS: All systemd distributions (Ubuntu, Debian, Fedora, Arch).
Before pruning logs, measure how much disk space the binary journal currently occupies:
journalctl --disk-usagePer the `journalctl(1)` manual page, --vacuum-size= and --vacuum-time= only operate on archived journal files, never the active system.journal currently open for writing. Running vacuum alone often leaves gigabytes untouched until you rotate first.
Back up any crash logs you still need, then rotate and trim in one atomic command:
sudo journalctl --rotate --vacuum-size=200MAlternatively, prune archived journals older than two weeks:
sudo journalctl --rotate --vacuum-time=2weeksI would skip --vacuum-files= unless you specifically want a fixed file count, because individual journal files vary in size up to SystemMaxFileSize. Bounding by total bytes (--vacuum-size=200M) is far more predictable on small root partitions.
Step 5: Set a Permanent Journal Size Cap with a Drop-In File
Target OS: All systemd distributions (Ubuntu, Debian, Fedora, Arch).
By default, the `journald.conf(5)` manual caps persistent logs at 10 percent of the underlying filesystem (soft-capped at 4 GiB) and tries to leave 15 percent free (SystemKeepFree=). On a 200 GiB server volume, 4 GiB of old logs can still crowd out /var alerts.
Rather than editing /etc/systemd/journald.conf directly (which package upgrades can prompt on), create a numeric drop-in directory override in the recommended 60-90 administrator range:
sudo mkdir -p /etc/systemd/journald.conf.d
sudo tee /etc/systemd/journald.conf.d/60-size-limit.conf >/dev/null <<'EOF'
[Journal]
Storage=persistent
SystemMaxUse=200M
SystemKeepFree=1G
EOFRestart the journal daemon to apply the new limits:
sudo systemctl restart systemd-journald.serviceVerification and Expected Result
Verify both the effective size limits and current disk usage after restarting systemd-journald:
journalctl --disk-usage
sudo journalctl -b -u systemd-journald.service -n 20 --no-pagerExpected result: journalctl --disk-usage reports total usage near or under 200M, the systemd-journald unit log shows the active SystemMaxUse / SystemKeepFree limits with no syntax errors, and systemctl --failed stays clean after you resolve the underlying unit failure.
Troubleshooting
- Short-lived service prints zero lines even with `_PID=`: If a process exits immediately due to a missing binary or bad
WorkingDirectory=, checkjournalctl -b _COMM=systemdorsystemctl status <unit>forstatus=203/EXECorstatus=200/CHDIRemitted by PID 1 itself. - Permission denied / missing logs as a regular user: Non-root users only see their own user journal unless added to the system journal group (
admon Ubuntu/Debian,systemd-journalon Arch,wheelon Fedora) or running withsudo. - Logs show truncated lines in terminal: Pass
--no-pagerwhen redirecting or copying, or overrideSYSTEMD_LESS=FRXMK(removingS) solesswraps long stack traces instead of chopping them at the right margin.
