Table of Contents

About

Linux systems store log files under /var/log and, depending on the setup, the log files can be very chatty with lines being written quite frequently. Writing to the log files very often can both slow down the machine in case the system uses spinning disks that must be spun up and can deteriorate SSD/NVMe drives.

For long-running servers or IoT devices where the log files are only really useful per session and do not need to be retained for longer periods, the log files can be kept in memory and, at worst, synchronized back to physical storage periodically.

This tutorial presents one of many solutions to store logs in RAM and synchronize them back to physical storage inspired from the log2ram project. Contrary

Features

Contrary to the log2ram project, log2zram benefits from some extra features:

Installing

log2zram is available in the Wizardry and Steamworks Debian repository which can be setup by following the instructions on the repository page.

Once the repository is setup, issue as root:

aptitude install log2zram

or

apt-get install log2zram

and the package will be installed.

The install procedure will prompt for the desired RAM size. Ideally, one should check in /var/log via du how much space is occupied and specify a manageable size that will not take too much away from the system RAM.

That is it - log2zram should now be active and has already pivoted the log files into RAM.

Testing

Issuing the command df -h when log2zram is running should list a zram device mounted on /var/log:

/dev/zram0       20M   13M  5.9M  69% /var/log

indicating the amount of space available and how much space has been used.

Uninstalling

To uninstall log2zram, simply uninstall the package via the Debian package tools:

aptitude uninstall log2zram

or:

apt-get uninstall log2zram

Details

The package consists of a script that, when run, creates a bind mount from the log directory (/var/log) to a different directory (/var/log.store) that will be used for persistent storage. The script then creates a RAM disk of the requested size and mounts the disk on top of the /var/log directory. Periodically, via cron, the logs kept in the RAM overlay are written to persistent storage. When the system starts, the RAM overlay is created and when the system shuts down, the logs are stored to persistent storage.