如何使 /var/log 在 Yocto Fido (poky) 中持久化
How to make /var/log persistent in Yocto Fido (poky)
我正在努力让 /var/log
坚持我的 fido 构建。
poky 的默认设置是,/var
中有一个 symlink 指向 log -> volatile/log
。 volatile
安装在 tmpfs 上。
到目前为止我发现 symlink 应该由 base-files
配方创建:
volatiles = "log tmp"
do_install () {
...
for d in ${volatiles}; do
ln -sf volatile/$d ${D}${localstatedir}/$d
done
...
我附加了基本文件配方,所以 link 没有创建,但它仍然出现在我的 rootfs 中。那么它是从哪里来的呢?我怀疑 fs-perms.txt
可能与它有关。但我试图创建一个没有
${localstatedir}/log link volatile/log
行,它仍然创建了 link。有什么线索吗?
基本文件配方创建基本系统目录并制作可变符号链接。还有第二个文件会影响,它是一个初始化脚本,用于检查可变目录、启动期间的符号链接并在丢失时创建。您应该附加 base-files
和 initscripts
食谱。最后,您必须更新 fs-perms.txt
.
中的基础文件相关链接
我建议如果你的硬盘上有足够的 space 你可以将 /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"
Yocto 2.4 中加入了持久化日志数据选项:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=6132
现在可以通过在您的发行版配置中定义以下内容来使日志数据持久化:
VOLATILE_LOG_DIR = "no"
我知道这是一个老问题并且已经得到解答,但是要结合 Bl00dh0und 和 alpi 的答案,您可以在 local.conf
中定义 VOLATILE_LOG_DIR = "no"
,自动挂载 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;"
我正在努力让 /var/log
坚持我的 fido 构建。
poky 的默认设置是,/var
中有一个 symlink 指向 log -> volatile/log
。 volatile
安装在 tmpfs 上。
到目前为止我发现 symlink 应该由 base-files
配方创建:
volatiles = "log tmp"
do_install () {
...
for d in ${volatiles}; do
ln -sf volatile/$d ${D}${localstatedir}/$d
done
...
我附加了基本文件配方,所以 link 没有创建,但它仍然出现在我的 rootfs 中。那么它是从哪里来的呢?我怀疑 fs-perms.txt
可能与它有关。但我试图创建一个没有
${localstatedir}/log link volatile/log
行,它仍然创建了 link。有什么线索吗?
基本文件配方创建基本系统目录并制作可变符号链接。还有第二个文件会影响,它是一个初始化脚本,用于检查可变目录、启动期间的符号链接并在丢失时创建。您应该附加 base-files
和 initscripts
食谱。最后,您必须更新 fs-perms.txt
.
我建议如果你的硬盘上有足够的 space 你可以将 /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"
Yocto 2.4 中加入了持久化日志数据选项: https://bugzilla.yoctoproject.org/show_bug.cgi?id=6132
现在可以通过在您的发行版配置中定义以下内容来使日志数据持久化:
VOLATILE_LOG_DIR = "no"
我知道这是一个老问题并且已经得到解答,但是要结合 Bl00dh0und 和 alpi 的答案,您可以在 local.conf
中定义 VOLATILE_LOG_DIR = "no"
,自动挂载 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;"