Introduction
If you’re using Fedora and find your system running low on disk space, the /var/log/journal
directory is one area to investigate. This directory contains journal logs generated by systemd-journald
, and over time, these logs can accumulate and consume a significant amount of disk space. While it’s essential to manage disk space efficiently, it’s equally important to understand the implications of removing these log files.
Can I Delete Files in /var/log/journal/?
Yes, you can safely delete the contents inside the /var/log/journal/
directory to free up space on your system. However, it’s crucial to note that you should not delete the directory. The journal logs help troubleshoot and diagnose issues, and removing the directory might lead to unintended consequences.
Checking Disk Usage
Before taking any action, it’s a good idea to check how much disk space the journal logs are currently occupying. You can use the journalctl
command with the --disk-usage
option:
$ journalctl - disk-usage\
Archived and active journals take up 4.0G in the file system.
This command provides information on the disk space consumed by the journal logs.
Controlling Log Size
To prevent the journal logs from taking up too much space, you can configure the maximum disk space usage in the /etc/systemd/journald.conf
file. Open the file using a text editor, and look for the SystemMaxUse
parameter. Adjust the value to set the maximum size for the log directory. For example:
SystemMaxUse=50M
This setting limits the total disk space used by the journal logs to 50 megabytes.
Method 1 Vacuum
A particularly effective method for managing the size of these logs is through the use of the journalctl
command with the -- vacuum-size
option. By executing the following command:
$ sudo journalctl --vacuum-size=50M
This command initiates a process that systematically removes old log files from the /var/log/journal
directory until the total size falls below the specified threshold (50 megabytes in this example). This method provides a more nuanced and automated approach to log maintenance, ensuring that only the necessary logs are retained, optimizing both disk space usage and system performance.
Method 2 Forcing Log Rotation
Log rotation helps in managing log files and preventing them from growing indefinitely. To force log rotation, you can use the following command:
$ sudo systemctl kill --kill-who=main --signal=SIGUSR2 systemd-journald.service
This command sends a signal to systemd-journald
to rotate its logs. Note that you may need to restart the logging service if the signal does not trigger the log rotation. Restart the service using:
$ sudo systemctl restart systemd-journald.service
This ensures that the journal logs are rotated and older entries are archived or deleted based on the configured settings.
After this optimization, we can check the actual size again:
$ journalctl --disk-usage\
Archived and active journals take up 49.1M in the file system.
Conclusion
In conclusion, managing log files in /var/log/journal
is a valid approach to free up disk space. However, it’s essential to exercise caution and understand the potential impact on system diagnostics. Configuring size limits and performing log rotations are effective strategies to keep the journal logs in check without compromising system stability.
Academy
Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate