folder2ram and journald

OpenMediaVault uses folder2ram on Flash devices to decrease the amount of writes.

This script mounts folders like logs, temp, collectd database into RAM and syncs them with disk on boot and shutdown.

But it breaks journald log system. Journal daemon starts before this script and writes to a previously opened log file even after the script remounts the log directory to the RAM.

There are log file errors on boot in dmesg, and journald creates a new log file on each boot, filling the log folder with broken log files.

To fix this problem we have to update start and stop systemd unit files for folder2ram. Best way to do it – use systemctl edit functionality, so there will be no conflicts with the package ones.

Start edit mode for folder2ram_startup service unit:

sudo systemctl edit --full folder2ram_startup

Add this content and save:

[Unit]
Description=folder2ram systemd start service
After=local-fs.target
Before=basic.target
DefaultDependencies=no

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/journalctl --relinquish-var
ExecStart=/sbin/folder2ram -mountall
ExecStart=/usr/bin/journalctl --flush

[Install]
WantedBy=basic.target

Before mounting of directories we ask journald to close the log file. Then start folder2ram as before, and tell journald to reopen the moved file from the RAM.

Then edit the stop service unit:

sudo systemctl edit --full folder2ram_shutdown

Add this content and save:

[Unit]
Description=folder2ram systemd stop service
After=blk-availability.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=/usr/bin/journalctl --relinquish-var
ExecStop=/sbin/folder2ram -umountall

[Install]
WantedBy=multi-user.target

We ask journald to close the file before writing it to disk.

This fix will allow journald to preserve logs between reboots and decrease space usage by broken log files


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *