我正在努力让
/var/log
坚持我的fido构建。
poky 的默认设置是,/var
中有一个指向 log -> volatile/log
的符号链接。 volatile
是安装在 tmpfs 上的。
到目前为止,我发现符号链接应该由
base-files
配方创建:
volatiles = "log tmp"
do_install () {
...
for d in ${volatiles}; do
ln -sf volatile/$d ${D}${localstatedir}/$d
done
...
我附加了基本文件配方,因此未创建链接,但它仍然出现在我的 rootfs 中。那么它从哪里来呢?我怀疑也许
fs-perms.txt
与此有关。但我尝试创建一个没有
${localstatedir}/log link volatile/log
line 并且它仍然创建了该链接。有线索吗?
Yocto 2.4 中提供了持久日志数据选项: https://bugzilla.yoctoproject.org/show_bug.cgi?id=6132
现在可以通过在发行版配置中定义以下内容来使日志数据持久化:
VOLATILE_LOG_DIR = "no"
基本文件配方创建基本系统目录并创建易失性符号链接。还有第二个文件会影响,它是一个初始化脚本,用于在启动期间检查易失性目录、符号链接,并在丢失时创建。您应该附加
base-files
和 initscripts
食谱。最后,您必须更新fs-perms.txt
中的基础文件相关链接。
我建议,如果您的硬盘上有足够的空间,您可以将
/var/log
安装到与 rootfs 不同的分区。如果您的 rootfs 分区发生问题,这是更实用、更安全的方法。
在本例中,new_log_part
是我的日志分区。
如果您为日志创建新分区,则应将其添加到 fstab 以在启动时自动挂载。在基本文件配方中包含新的 fstab。
要附加的基本文件配方:
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
}
初始化脚本附加:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://volatiles"
易失性文件:
# 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 更改:
# 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
然后在层的layer.conf文件中添加此行以包含新的fs-perms.txt:
FILESYSTEM_PERMS_TABLES = "${LAYER_PATH}/fs_files/fs-perms.txt"
注意:您可以创建自己的 fs-perm 文件并将默认文件附加到 conf.layer 中。
FILESYSTEM_PERMS_TABLES = "fs-perm.txt my-fs-perm.txt"
我知道这是一个老问题并且已经得到了解答,但是要结合 Bl00dh0und 和 alpi 的答案,您可以在
VOLATILE_LOG_DIR = "no"
中定义 local.conf
,自动挂载 new_log_part
中的 fstab
,然后添加类似的内容到图像配方:
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;"
根据 poky/documentation/ref-manual/features.rst:
要使目标上的
/var/log
目录持久存在,请使用 VOLATILE_LOG_DIR
变量,将其设置为“no”。
实际上,在基本文件配方中,有一行:
易失性 =“${@'log' if oe.types.boolean('${VOLATILE_LOG_DIR}') else ''} tmp”
VOLATILE_LOG_DIR='no' 将从挥发物中丢弃
log
...