Phi*_*Bot 5 systemd yocto journalctl systemd-journald systemctl
我正在使用 Yocto 为 SystemD 版本 241 的小型嵌入式 Linux 系统生成自定义映像。根文件系统是只读的。我使用绑定安装和overlayfs 使/var/log/journal 目录存在于单独的读/写分区上。我有一个问题,systemd-journald 得到“Amnesia”并且不记得以前的引导日志,即使它们在持久的读/写文件系统上。这意味着即使日志文件在文件系统上存在且有效,日志也无法访问或清除以前启动时的旧日志文件。
# Setup overlayfs binds for various RW files
VOLATILE_BINDS_append = " \
/persistent-storage/var/log /var/log\n\
"
Run Code Online (Sandbox Code Playgroud)
路径 /var/log 存在:
root@me:/var/log# cd /var/log/
root@me:/var/log# ls -lrt
total 9
drwxr-xr-x 2 root root 1024 Jun 3 01:50 nginx
-rw-r--r-- 1 root root 5260 Jun 9 17:56 messages
drwxr-sr-x 5 root systemd-journal 1024 Jun 9 18:00 journal
root@me:/var/log# ls -lrt journal/
total 3
drwxr-sr-x 2 root systemd-journal 1024 Jun 9 17:56 5f6085cd81114e8688cf23b3bb91933e
drwxr-sr-x 2 root systemd-journal 1024 Jun 9 17:57 de59603d1ea24e7582ed7d7ed3ac8fb0
drwxr-sr-x 2 root systemd-journal 1024 Jun 9 18:00 0c34cc794e6c4241a75774bbb8324102
Run Code Online (Sandbox Code Playgroud)
我在 /lib/systemd/journald.conf.d/10-persistent-journal.conf 中有一个 journald 配置文件片段,如下所示:
# By default the maximum use limit (SystemMaxUse) is 10% of the filesystem, and the minimum
# free space (SystemKeepFree) value is 15% - though they are both capped at 4G.
# The journals should be rotated automatically when they reach the SystemMaxFileSize value,
# and the number of journals is controlled by SystemMaxFiles. If you prefer time based
# rotation you can set a MaxFileSec to set the maximum time entries are stored in a single journal.
[Journal]
Storage=persistent
SystemMaxFileSize=128M
SystemMaxFiles=10
SystemMaxUse=256M
SystemKeepFree=256M
SyncIntervalSec=30
Run Code Online (Sandbox Code Playgroud)
问题是,即使我重新启动了几次,并且 journald 成功找到并将日志写入 /var/log/journal,它也永远找不到以前的日志,也不知道以前的启动日志。这意味着我无法清空以前的日志并且我的分区空间不足,即使 journald 应该保持 50% 的分区空闲。
root@me:/# journalctl --list-boots
0 82fef865e29e481aae27bd247c10e591 Tue 2020-06-09 18:00:12 UTC—Tue 2020-06-09
18:15:23 UTC
Run Code Online (Sandbox Code Playgroud)
虽然:
root@me:/# ls -lrt /var/log/journal/
total 3
drwxr-sr-x 2 root systemd-journal 1024 Jun 9 17:56 5f6085cd81114e8688cf23b3bb91933e
drwxr-sr-x 2 root systemd-journal 1024 Jun 9 17:57 de59603d1ea24e7582ed7d7ed3ac8fb0
drwxr-sr-x 2 root systemd-journal 1024 Jun 9 18:00 0c34cc794e6c4241a75774bbb8324102
Run Code Online (Sandbox Code Playgroud)
此外,以下命令有效:
root@me:/# journalctl -b 0
<information>
root@me:/# journalctl -b 1
<information>
root@me:/# journalctl -b 2
Data from the specified boot (+2) is not available: No such boot ID in journal
Run Code Online (Sandbox Code Playgroud)
我读了这篇文章:Can be the journal path on a filesystem than /?. 我尝试了以下挂载文件,但是我看到了完全相同的行为:
[Unit]
Description=Persistent Journal Storage Bind
[Mount]
What=/anotherfs/journal
Where=/var/log/journal
Type=none
Options=bind
[Install]
WantedBy=local-fs.target
Run Code Online (Sandbox Code Playgroud)
我做错了什么,如何在绑定挂载系统上使用日志来处理持久日志?
我已经和同样的问题斗争了一段时间了。我有一个基于 Yocto 的发行版,其中有一个只读 rootfs,并且 /var/log 文件夹使用 volatile-binds 安装在不同的分区中。一旦我让日志记录到新分区,我注意到同样的事情,journalctl --list-boots只会显示当前的启动,而不是旧的启动。经过大量的尝试和错误后,我最终弄清楚了原因。
正如您所指出的,/var/log/journal显示 3 个文件夹:
root@mir-edb-intel-gen1:~# ls -lrt /var/log/journal/\ntotal 24\ndrwxr-sr-x+ 2 root systemd-journal 4096 Mar 5 09:24 7f7f3d516b554d718d688a0b0fa9648e\ndrwxr-sr-x+ 2 root systemd-journal 4096 Mar 5 09:25 93eb74229e9244a4b7f60c90acacc12f\ndrwxr-sr-x+ 2 root systemd-journal 4096 Mar 5 10:57 4a9652b4b33a4a099bdc6be8c6fb2b1a\nRun Code Online (Sandbox Code Playgroud)\n并且journalctl --list-boots仅显示 1 个条目:
0 6cb4f9f236954f69937be217f36c1ce2 Fri 2021-03-05 10:57:48 UTC\xe2\x80\x94Fri 2021-03-05 11:01:22 UTC\nRun Code Online (Sandbox Code Playgroud)\n但是,如果您运行journalctl -D /var/log/journal --list-boots所有 3 次启动,就会按预期显示:
root@mir-edb-intel-gen1:~# journalctl -D /var/log/journal --list-boots\n-2 9ab6d00dea9d41da9c76bf2a3f64895c Fri 2021-03-05 09:24:20 UTC\xe2\x80\x94Fri 2021-03-05 09:25:03 UTC\n-1 00509584245d44d599d88db8dccd4177 Fri 2021-03-05 09:25:37 UTC\xe2\x80\x94Fri 2021-03-05 10:14:42 UTC\n 0 6cb4f9f236954f69937be217f36c1ce2 Fri 2021-03-05 10:57:48 UTC\xe2\x80\x94Fri 2021-03-05 11:01:22 UTC\nRun Code Online (Sandbox Code Playgroud)\n虽然我对 systemd 不太了解,但我相信问题是由于我们每次启动时都将日志从/run/log/journal刷新到/var/log/journal而不是写入更多内容/var/log/journal中的现有日志。然后,当您调用journalctl它时,它只查看最新的文件夹,因此无法找到以前的启动,除非您明确告诉它查看整个/var/log/journal。
编辑: \n @Jaap Joris Vens似乎对此答案中的行为有一个很好的解释
\nEdit2: \n在我们的例子中,该/etc/machine-id文件是一个空文件,如以下所述poky/meta/classes/rootfs-postcommands.bbclass:
#\n# A hook function to support read-only-rootfs IMAGE_FEATURES\n#\nread_only_rootfs_hook () {\n\n [...]\n\n if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then\n # Create machine-id\n # 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable\n touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id\n fi\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1105 次 |
| 最近记录: |