Marcio Cunha

How to free up disk space by cleaning systemd journal

Learn how to inspect storage consumption by persistent systemd logs on Linux and apply safe retention policies to recover disk space without losing critical data.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • The systemd journal stores system logs centrally, which can consume gigabytes of storage on production servers.
  • The journalctl command allows administrators to inspect the exact space used by log files before running any deletion.
  • Configuring journald.conf sets permanent limits on disk consumption based on total size or time retention.
  • Manual cleanup can be executed by specifying size limits or retention periods to safely reclaim disk space.
  • Monitoring log growth prevents catastrophic failures caused by root partition exhaustion in critical environments.

Why the systemd journal consumes so much disk space

When administering Linux servers, one of the most silent and annoying issues is the sudden exhaustion of storage on the root partition. Often, when investigating with directory inspection commands, we discover that the culprits are not databases or code files, but rather the operating system logging subsystem. The systemd journal centralizes all messages generated by the kernel, services, and applications into compact binary files that accumulate massively over time.

In production environments running under heavy workloads or services generating repetitive debugging messages, these logs grow exponentially without proper controls. The practical impact is that once the disk reaches one hundred percent utilization, the operating system loses the ability to write temporary files, user sessions freeze, and critical applications suffer abrupt crashes. To better understand how the underlying system ecosystem operates, check out our guide on how to use journalctl to inspect Linux system logs and master essential diagnostic tools.

How to inspect storage consumption of logs

Before applying any cleanup policy or blindly deleting log files, the most prudent and recommended step is to measure exactly how much space the journal is currently consuming. The journalctl utility provides a very useful native flag for this purpose, displaying the total space occupied by persistent files in the default storage directory.

In practice, simply run the command with administrative privileges to get a clear summary of current disk usage. If you notice that the volume is out of control, remember that disk space issues in servers can also involve other common accumulators, such as the ones discussed in our article about how to clean Docker cache on Linux to recover lost gigabytes. Here is the basic command to check log size:

sudo journalctl --disk-usage

This command returns the exact value occupied in megabytes or gigabytes, allowing you to evaluate whether your current retention is sustainable for the physical capacity of your hard drive or solid-state drive (SSD).

How to define safe retention policies in journald

The best way to prevent the systemd journal from filling up your disk again in the future is to configure clear retention rules and maximum size limits in the main configuration file. This file resides within the system configuration directory and dictates the behavior of the entire event logging subsystem.

To perform this modification safely, you must open the configuration file using a text editor with superuser privileges and adjust specific parameters. The most important directives controlling space consumption are the maximum global size limit and the maximum retention time for older records.

  1. Open the journald configuration file using your preferred text editor in the terminal.
  2. Locate and uncomment the lines referring to SystemMaxUse and MaxRetentionSec, adjusting the values according to your operational needs.
  3. Restart the journal service to immediately apply the new retention policies without having to reboot the entire server.

The following command illustrates how to restart the journal service after saving the configuration file changes:

sudo systemctl restart systemd-journald

This approach ensures that the operating system itself cleans up autonomously and continuously, discarding older records as soon as the defined limits are exceeded.

How to manually clean the journal to reclaim space now

If your server is already running almost completely out of disk space and you need an immediate solution to free up disk space, manual cleanup of persistent logs is the fastest path. systemd includes built-in commands that allow purging old records based on desired size or elapsed time, maintaining the structural integrity of the remaining files.

For instance, if you want to keep only the equivalent of the last two days of logs and erase everything prior to that, the command accepts direct temporal parameters. Similarly, you can stipulate a size ceiling to force the immediate shrinkage of the storage directory.

sudo journalctl --vacuum-time=2d

Running this command instantly removes all log files older than 48 hours, returning free space to the operating system without compromising recent information that may still be useful for security audits or current troubleshooting. To explore these architectural concepts further in production, see our related technical analysis on How to test MOSFET transistors on board with multimeter.

Conclusion

Keeping the systemd journal under control is a fundamental task in Linux production server administration, ensuring stability and preventing failures due to lack of storage. By combining regular disk consumption inspection with well-defined automated retention and cleanup policies, you eliminate unnecessary operational risks.

Adopting these maintenance best practices prevents unpleasant surprises at critical moments and ensures that hardware resources are dedicated primarily to running your applications, keeping the environment healthy, predictable, and ready to scale.