0

I'm building a Yocto-based distribution with systemd and journald in its core.

And unfortunately I cannot get Yocto to store all logs in /var/log -> /data/log. I need journald logs as well as some other logs that are written there after multi-user.target to be persistent. /data is the persistent partition.

I have a very similar problem to this but unfortunately I couldn't modify it to work properly in my setup.

From my understanding there's two things I need to modify:

  • volatiles file in base-files which I hope is a config file for systemd-tmpfiles. It should tell it to create at runtime everything that journald needs. Here I modified one line:

L+ root root 0755 /var/log /data/log

  • fs-perms.txt

${localstatedir}/log link /data/log

I also tried to pull it off with VOLATILE_LOG_DIR set "no" (fs-perms-persistent-log.txtmodified but to no avail. And also adding some kind ofvar.confto/etc/tmpfiles.d` with a config similar to the one above. It also hasn't worked.

I launch a watch ls -l on the resulting rootfs/var and see that var/log is getting symlinked to `/data/log for a short while but later it's overridden somewhere to point to volatile/log once again.

I would greatly appreciate any advice because it seems like I'm overcomplicating this thing. It should be very easy. After all it's just making Yocto to make a symlink. But I guess this is a rather important directory to let me ln -sf /data/log /var/log.

I would also like to hear out implications of this approach. Other than wearing out my eMMC. We can live with that because the log activity is very low compared to some other actions performed on the device. I'm mostly interested about mount order and stuff. If I remember correctly, journald will use a memory buffer until it has /var/log/journal created for it so I should be fine. But what should I do to ensure everything's in place before the logs are flushed? Do I need to modify systemd services to include RequireMountsFor or After=?

I want to be as defensive as possible so I'm looking forward to what you guys have to say on the topic.

EDIT:

Maybe I can just add a bind mount from /var/log to /data/log? If that is actually the solution I'd also like to know if there's no hidden hindrances down the road?

staroselskii
  • 365
  • 1
  • 3
  • 16

2 Answers2

0

you can mount your persistent partition via tweaking the base-files recipe (base-files_%.bbappend)

do_install_append () {
    cat >> ${D}${sysconfdir}/fstab <<EOF

# Data partition
/dev/mmcblk0p4       /data          auto       defaults,sync,noauto  0  2
EOF
}
dirs755 += "/data"

then you can tweak volatile-binds (volatile-binds.bbappend)

VOLATILE_BINDS = "\
    /data/var/lib /var/lib\n\
    /data/var/log /var/log\n\
    /data/var/spool /var/spool\n\
    /data/var/srv /srv\n\
"

This should hopefully help, I have not tested it fully here, but I hope this might provide you some starting point.

Khem
  • 1,162
  • 8
  • 8
-1

A persistent log data option has made it in Yocto 2.4: https://bugzilla.yoctoproject.org/show_bug.cgi?id=6132

Log data can be made persistent by defining the following in your distro config:

VOLATILE_LOG_DIR = "no"

(copied from here)

Musa
  • 474
  • 4
  • 9
  • your answer is just a copy from [here](https://stackoverflow.com/questions/41507365/how-to-make-var-log-persistent-in-yocto-fido-poky). You could mention this at least instead of seizing the answer from another guy. Also, this doesn't answer the question. The OP asked for a persistent symlink to a persistent storage. Making the logdir non-volatile is not enough, since the log space defaulted by yocto is very low – woodz Mar 16 '23 at 08:54
  • thank for your comment. i mentioned it. – Musa Mar 16 '23 at 16:53