Ansible Pilot

Managing Journal Logs in Fedora: Can I Remove Files in /var/log/journal?

Optimizing Disk Space and Maintenance for Fedora’s Journal Logs Ansible Pilot

November 21, 2023
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

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.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases