Troubleshooting Massive `systemd-journald` Log File Storage on Ubuntu 22.04 LTS
Diagnose and resolve excessive disk space consumption by `systemd-journald` log files on Ubuntu 22.04 LTS, preventing costly downtime.
Diagnose and resolve excessive disk space consumption by `systemd-journald` log files on Ubuntu 22.04 LTS, preventing costly downtime.
As an experienced Systems Administrator, few issues are as frustrating and critical as a server running out of disk space. On modern Debian-based systems like Ubuntu 22.04 LTS, systemd-journald is often the silent culprit behind rapidly diminishing free disk space, especially on busy web servers, database servers, or systems with numerous Docker containers. This guide will walk you through diagnosing, temporarily resolving, and permanently configuring journald to prevent future storage crises.
Symptom & Error Signature
The primary symptom is a server becoming unresponsive, services failing to start, or applications crashing due to a lack of available disk space on the root filesystem. You might observe:
- Disk Full Errors: Applications, web servers (e.g., Nginx, Apache), or databases logging "No space left on device" errors.
- System Sluggishness: The server performing poorly or hanging due to disk I/O bottlenecks or inability to write temporary files.
- Failed Service Starts:
systemctlcommands might show services failing to start with disk-related errors.
You can verify the issue using standard disk usage tools:
# Check overall disk space usage, particularly for the root partition (/)
df -h /
Expected output showing high usage:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 98G 2.0G 98% /
Further investigation will likely reveal systemd-journald as the primary consumer:
# Check the size of the journald log directory
sudo du -sh /var/log/journal
Example output:
45G /var/log/journal
To specifically query journald's reported disk usage:
# Query systemd-journald for its current disk usage
journalctl --disk-usage
Example output:
Archived and active journals take up 45.0G in the /var/log/journal directory.
Root Cause Analysis
systemd-journald is the logging daemon for systemd. It collects and stores logging data from all systemd units, kernel messages, standard output/error of services, and other sources. While powerful, its default configuration, especially on systems with high log volumes, can lead to excessive disk space consumption.
The underlying reasons for massive journald log files typically include:
- Persistent Logging by Default: Unlike older
syslogsetups where logs might be cleared on reboot,systemd-journaldby default stores logs persistently in/var/log/journal(Storage=persistentinjournald.conf). This means logs accumulate over time unless explicitly managed. - Insufficient Default Limits: While
journaldhas built-in size limits (SystemMaxUse,RuntimeMaxUse), the default values (often 10% of the filesystem size or 4GB, whichever is smaller forSystemMaxUse) can still be too large for the root partition, especially on virtual machines with smaller allocated disk sizes or extremely chatty applications. - High Log Volume:
- Verbose Applications: Applications running in
DEBUGmode, or those with misconfigurations leading to continuous error reporting. - Frequent Service Restarts: Services crashing and restarting repeatedly will generate a large number of log entries.
- Web Server Traffic: High-traffic Nginx or Apache web servers, especially with extensive access logging or error conditions.
- Containerized Workloads (Docker/Kubernetes): Containers often log their
stdout/stderrdirectly tojournald, and a large number of containers or verbose container logs can quickly fill up disk space. - Security Events: Brute-force attacks or other security incidents can generate a flood of authentication logs.
- Verbose Applications: Applications running in
- Lack of Proactive Management: Without explicit configuration,
journaldwill continue to grow its log files until its configured limits are hit, or until the disk is completely full. Many system administrators overlookjournaldconfiguration, assuming default log rotation mechanisms (likelogrotatefor traditionalsyslogfiles) handle everything.
Step-by-Step Resolution
This section details how to immediately free up space and then configure systemd-journald for long-term sustainable log management.
1. Assess Current Disk Usage and Journal Size
Before making any changes, confirm journald is indeed the culprit and understand the scale of the problem.
# Check overall disk usage (confirm / is full or near full)
df -h /
# Check the specific size of the journal directory
sudo du -sh /var/log/journal
# Check journald's reported disk usage
journalctl --disk-usage
2. Perform Immediate Cleanup (Temporary Solution)
If your disk is already full, you need to free up space immediately. journalctl provides commands to purge old or oversized logs.
# Delete journal files older than a specified time (e.g., 7 days)
# This will remove logs that are older than "7 days" from now.
sudo journalctl --vacuum-time="7d"
# Delete journal files until the total size is below a specified limit (e.g., 500 MB)
# This will remove the oldest logs until the total size is less than "500M".
sudo journalctl --vacuum-size="500M"
Running
journalctl --vacuum-sizeorjournalctl --vacuum-timewill immediately free up space without requiring a service restart. This is crucial for systems that are already experiencing "disk full" issues. Choose parameters carefully based on your auditing requirements. For example,--vacuum-time="1d"will keep only the last day's logs.
After cleanup, verify the space has been freed:
journalctl --disk-usage
sudo du -sh /var/log/journal
df -h /
3. Configure Permanent Journald Log Retention Limits
To prevent journald logs from consuming excessive disk space again, you need to configure its retention policies. This is done by editing the journald configuration file.
Open the journald configuration file:
sudo nano /etc/systemd/journald.conf
Inside the file, you'll find various commented-out lines. Uncomment and modify the following parameters in the [Journal] section to set your desired limits. If they don't exist, add them.
[Journal]
# Ensure logs are persistent across reboots. Change to 'volatile' if you
# want logs to be deleted on reboot (not recommended for production).
Storage=persistent
# Limit total persistent journal size to 500MB (example).
# This is the most critical setting for controlling disk usage.
# Adjust based on your disk size and log volume.
SystemMaxUse=500M
# Always leave at least 100MB free on the filesystem (example).
# Journald will stop writing if this threshold is hit.
SystemKeepFree=100M
# Limit individual persistent journal file size to 50MB (example).
# This can make individual files easier to manage or transfer.
SystemMaxFileSize=50M
# Limit the number of persistent journal files (example).
# Useful in conjunction with SystemMaxFileSize.
# SystemMaxFiles=5
# For volatile (runtime) logs (if Storage=volatile or auto)
# RuntimeMaxUse=50M
# RuntimeKeepFree=20M
# RuntimeMaxFileSize=10M
# RuntimeMaxFiles=3
Setting
SystemMaxUsetoo low might discard critical logs needed for debugging complex issues, especially on busy servers. A common recommendation for typical production servers is500Mto2G, depending on available disk space, overall logging verbosity, and compliance requirements. For heavily trafficked services or systems running many containers, consider a higher limit combined with central log management.
4. Apply New Journald Configuration
After saving changes to /etc/systemd/journald.conf, you must restart the systemd-journald service for the new settings to take effect.
sudo systemctl restart systemd-journald
Restarting
systemd-journaldis critical for the new settings in/etc/systemd/journald.confto apply. It will not cause service interruptions for running applications; they will continue to log, andjournaldwill resume collecting them under the new rules.
5. Verify New Configuration and Monitor
After restarting, journald will apply the new limits. It might take some time for the old logs to be vacuumed if they exceed the new SystemMaxUse.
# Check the current disk usage again to ensure the limits are being respected.
journalctl --disk-usage
# You can also inspect the active configuration:
sudo systemd-analyze cat-config systemd/journald.conf
Monitor your disk space (df -h) over the next few hours or days to ensure the problem does not recur and that journald logs remain within acceptable limits.
6. Advanced Considerations: Centralized Log Management
For highly active servers, large clusters, or environments requiring long-term log retention and advanced analysis, local journald management might not be sufficient. Consider implementing a centralized log management solution:
- Log Aggregation Tools: Solutions like the ELK Stack (Elasticsearch, Logstash, Kibana), Grafana Loki, Splunk, or Graylog can collect logs from multiple servers.
- Log Forwarding: You can configure
journaldto forward logs to a remotesyslogserver (usingForwardToSyslog=yesinjournald.confandrsyslog), or directly to ajournaldforwarding service (systemd-journal-upload). Docker provides logging drivers (e.g.,syslog,json-file,fluentd) that can also be configured to send container logs to external systems.
By carefully configuring systemd-journald and potentially implementing a centralized logging strategy, you can prevent disk space emergencies and maintain the stability and auditability of your Ubuntu 22.04 LTS servers.
Our Production Verification Guarantee
Encountering a bug not covered here or running a non-standard kernel configuration? Our solutions are continually refined against real production incidents. Submit an environment trace for our editorial team to replicate.