Limit Disk Space Used by Journald on Linux

Limit Disk Space Used by Journald on Linux

Journald is a service for collecting and storing log data and is a component of the systemd used in many Linux distributions. While these logs are crucial for troubleshooting and monitoring, they can also consume a significant amount of disk space over time. To address this concern, Linux administrators can set limits on the disk space used by Journald. This tutorial demonstrates how to limit disk space used by Journald on Linux.

Firstly, modify the configuration file for Journald. This file is typically located at /etc/systemd/journald.conf. Open the file using a text editor and locate the line that starts with #SystemMaxUse=. This line is usually commented out with a # at the beginning. Uncomment the line and set the desired maximum disk space in megabytes (M). This process can be automated by using the following command:

sudo sed -i 's/#SystemMaxUse=/SystemMaxUse=50M/' /etc/systemd/journald.conf

Let's break down the command:

  • sed - is a command line utility that parses and transforms text.
  • -i - this option stands for "in-place." It tells sed to edit the file in place, meaning it modifies the file directly rather than producing output to the terminal.
  • s/#SystemMaxUse=/SystemMaxUse=50M/ - it searches for the line in the file that contains #SystemMaxUse= and replaces it with SystemMaxUse=50M.

After modifying the configuration file, we need to restart the Journald service to apply the changes:

sudo service systemd-journald restart

This simple but effective measure helps prevent log files from consuming excessive disk space and ensures a more efficient use of the storage resources. Adjust the SystemMaxUse value according to the specific disk space requirements.

Leave a Comment

Cancel reply

Your email address will not be published.