How to make /var/log persistent in Yocto Fido (poky)

半城伤御伤魂 提交于 2019-12-10 04:29:17

问题


I'm trying to get /var/log to be persistent in my fido build. The default setting on poky is, that there is a symlink in /var which points log -> volatile/log. volatile is a mounted on a tmpfs.

So far i figured out that the symlink should be created by the base-files recipe:

volatiles = "log tmp"

do_install () {
  ...
    for d in ${volatiles}; do
        ln -sf volatile/$d ${D}${localstatedir}/$d
    done
  ...

I appended the base-files recipe so the link was not created, but it still turned up in my rootfs. So where does it come from? I suspect that maybe the fs-perms.txt has something to do with it. But i tried to create one without the

${localstatedir}/log    link    volatile/log

line and it still created that link. Any clues?


回答1:


The base-files recipe creates the basic system directories and makes the volatile symlinks. There is also a second file that affects, it's an initscript that checks volatile directories, symlinks during startup and creates if missing. You should append both base-files and initscripts recipes. Finally, you have to update base-files related links in fs-perms.txt.

I suggest that If there is enough space on your hard drive you could mount /var/log to a different partition from rootfs. That's more practical and safe way if there is something happen on your rootfs partition.

new_log_part is my log partition in this case.

If you create a new partition for logs, you should add it to fstab to automount on startup. Include new fstab in base-files recipe.

The base-files recipe to append:

  FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

  SRC_URI += "file://fstab"

  dirs755_remove = "${localstatedir}/volatile/log"
  volatiles_remove = "log"

  do_install_append () {
    ln -snf new_log_part ${D}${localstatedir}/log
  }

initscripts append:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

SRC_URI += "file://volatiles"

volatiles file:

# This configuration file lists filesystem objects that should get verified
# during startup and be created if missing.
#
# Every line must either be a comment starting with #
# or a definition of format:
# <type> <owner> <group> <mode> <path> <linksource>
# where the items are separated by whitespace !
#
# <type> : d|f|l : (d)irectory|(f)ile|(l)ink
#
# A linking example:
# l root root 0777 /var/test /tmp/testfile
# f root root 0644 /var/test none
#
# Understanding links:
# When populate-volatile is to verify/create a directory or file, it will first
# check it's existence. If a link is found to exist in the place of the target,
# the path of the target is replaced with the target the link points to.
# Thus, if a link is in the place to be verified, the object will be created
# in the place the link points to instead.
# This explains the order of "link before object" as in the example above, where
# a link will be created at /var/test pointing to /tmp/testfile and due to this
# link the file defined as /var/test will actually be created as /tmp/testfile.
d root root 0755 /var/volatile/cache none
d root root 1777 /var/volatile/lock none
d root root 0755 /var/new_log_part none
d root root 0755 /var/volatile/run none
d root root 1777 /var/volatile/tmp none
l root root 0755 /var/cache /var/volatile/cache
l root root 1777 /var/lock /var/volatile/lock
l root root 0755 /var/log /var/new_log_part
l root root 0755 /var/run /var/volatile/run
l root root 1777 /var/tmp /var/volatile/tmp
d root root 0755 /var/lock/subsys none
f root root 0664 /var/new_log_part/wtmp none
f root root 0664 /var/run/utmp none
l root root 0644 /etc/resolv.conf /var/run/resolv.conf
f root root 0644 /var/run/resolv.conf none

fs-perms.txt changes:

# Items from base-files
# Links
${localstatedir}/run    link    volatile/run
${localstatedir}/log    link    new_log_part
${localstatedir}/lock   link    volatile/lock
${localstatedir}/tmp    link    volatile/tmp

Then in the layer's layer.conf file add this line to include new fs-perms.txt:

FILESYSTEM_PERMS_TABLES = "${LAYER_PATH}/fs_files/fs-perms.txt"

Note: You can create your own fs-perm file and append the default one in your conf.layer.

FILESYSTEM_PERMS_TABLES = "fs-perm.txt my-fs-perm.txt"



回答2:


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

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

VOLATILE_LOG_DIR = "no"



回答3:


I know this is an old question and that it has been answered, but to combine Bl00dh0und's and alpi's answers you could define VOLATILE_LOG_DIR = "no" in the local.conf, automount the new_log_part in fstab and then add something like this to the image recipe:

create_log_link_to_new_partition() {
   cd ${IMAGE_ROOTFS}
   rm -rf var/log
   ln -s ../path/to/auto/mounted/new_log_part var/log
}

IMAGE_PREPROCESS_COMMAND += "create_log_link_to_new_partition;"


来源:https://stackoverflow.com/questions/41507365/how-to-make-var-log-persistent-in-yocto-fido-poky

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!