我在尝试使用该命令时在 Raspberry Pi 上遇到问题timedatectl
。当我执行时,timedatectl status
我收到以下错误消息:
spaikon@raspberrypi:~ $ timedatectl status
Failed to query server: Transport endpoint is not connected
spaikon@raspberrypi:~ $ sudo timedatectl status
Failed to query server: The name org.freedesktop.timedate1 was not provided by any .service files
$ sudo timedatectl show
Failed to parse bus message: No route to host
$ sudo systemctl status systemd-timedated.service
● systemd-timedated.service - Time & Date Service
Loaded: loaded (/lib/systemd/system/systemd-timedated.service; static)
Active: inactive (dead)
Docs: man:systemd-timedated.service(8)
man:localtime(5)
man:org.freedesktop.timedate1(5)
我尝试在网上寻找解决方案,但到目前为止还没有任何运气。我不确定这些错误的含义或如何解决它们。还有其他人遇到过这个问题并找到解决方案吗?
任何帮助将不胜感激。
先感谢您!
编辑:
$ sudo systemctl status systemd-timedated.service
● systemd-timedated.service - Time & Date Service
Loaded: loaded (/lib/systemd/system/systemd-timedated.service; static)
Active: inactive (dead)
Docs: man:systemd-timedated.service(8)
man:localtime(5)
man:org.freedesktop.timedate1(5)
$ sudo timedatectl
Failed to query server: The name org.freedesktop.timedate1 was not provided by any .service files
$ dlocate -S systemd-timedated.service
systemd: /lib/systemd/system/systemd-timedated.service
systemd: /usr/share/man/man8/systemd-timedated.service.8.gz
编辑 2:来自 systemd-timedate 的响应
$ journalctl -fu systemd-timedated.service
-- Journal begins at Thu 2023-06-08 20:47:15 EEST. --
Jun 09 12:07:52 raspberrypi systemd[1]: Starting Time & Date Service...
Jun 09 12:07:52 raspberrypi systemd-timedated[46085]: /lib/systemd/systemd-timedated: error while loading shared libraries: li bsystemd-shared-247.so: cannot open shared object file: Permission denied
Jun 09 12:07:52 raspberrypi systemd[1]: systemd-timedated.service: Main process exited, code=exited, status=127/n/a
Jun 09 12:07:52 raspberrypi systemd[1]: systemd-timedated.service: Failed with result 'exit-code'.
Jun 09 12:07:52 raspberrypi systemd[1]: Failed to start Time & Date Service.
编辑3:
$ namei -mov /lib/systemd/libsystemd-shared-247.so
f: /lib/systemd/libsystemd-shared-247.so
drwx------ spaikon spaikon /
lrwxrwxrwx root root lib -> usr/lib
drwxr-xr-x root root usr
drwxr-xr-x root root lib
drwxr-xr-x root root systemd
-rw-r--r-- root root libsystemd-shared-247.so
答案1
org.freedesktop.timedate1
是出现在 的定义中的 D-Bus 名称systemd-timedated.service
。
systemctl cat systemd-timedated.service | grep org.freedesktop.timedate1
Documentation=man:org.freedesktop.timedate1(5)
BusName=org.freedesktop.timedate1
systemd-timedated.service
仅当系统 D-Bus 上有需要时才应由 systemd 启动。这正是该timedatectl
命令的作用:
root@raspiw2:/home/pi# systemctl status systemd-timedated.service
● systemd-timedated.service - Time & Date Service
Loaded: loaded (/lib/systemd/system/systemd-timedated.service; static)
Active: inactive (dead)
Docs: man:systemd-timedated.service(8)
man:localtime(5)
man:org.freedesktop.timedate1(5)
root@raspiw2:/home/pi# timedatectl
Local time: Fri 2023-06-09 17:57:26 EEST
Universal time: Fri 2023-06-09 14:57:26 UTC
RTC time: n/a
Time zone: Europe/Helsinki (EEST, +0300)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
root@raspiw2:/home/pi# systemctl status systemd-timedated.service
● systemd-timedated.service - Time & Date Service
Loaded: loaded (/lib/systemd/system/systemd-timedated.service; static)
Active: active (running) since Fri 2023-06-09 17:57:26 EEST; 5s ago
Docs: man:systemd-timedated.service(8)
man:localtime(5)
man:org.freedesktop.timedate1(5)
Main PID: 1284 (systemd-timedat)
Tasks: 1 (limit: 2057)
CPU: 328ms
CGroup: /system.slice/systemd-timedated.service
└─1284 /lib/systemd/systemd-timedated
Jun 09 17:57:26 raspiw2 systemd[1]: Starting Time & Date Service...
Jun 09 17:57:26 raspiw2 systemd[1]: Started Time & Date Service.
systemd-timedated.service
是主systemd
包的一部分,因此错误消息会表明服务定义已被更改或删除。您是否将该服务设置为屏蔽,或者甚至将其完全删除?
dlocate -S systemd-timedated.service
systemd: /lib/systemd/system/systemd-timedated.service
systemd: /usr/share/man/man8/systemd-timedated.service.8.gz
的输出journalctl -fu systemd-timedated.service
表明系统库存在权限问题(为了清楚起见,分为多行):
Jun 09 12:07:52 raspberrypi systemd-timedated[46085]: /lib/systemd/systemd-timedated:
error while loading shared libraries:
libsystemd-shared-247.so: cannot open shared object file:
Permission denied
该库应该位于/lib/systemd/libsystemd-shared-247.so
.
您可以使用 立即列出该文件和所有父目录的权限namei -mov /lib/systemd/libsystemd-shared-247.so
。输出应该是:
f: /lib/systemd/libsystemd-shared-247.so
drwxr-xr-x root root /
drwxr-xr-x root root lib
drwxr-xr-x root root systemd
-rw-r--r-- root root libsystemd-shared-247.so
如果文件的读取权限或r-x
任何父目录的读取和访问 ( ) 权限丢失,请使用chmod
来恢复它们。
$ namei -mov /lib/systemd/libsystemd-shared-247.so
f: /lib/systemd/libsystemd-shared-247.so
drwx------ spaikon spaikon /
[...]
其他权限似乎是正确的,但根目录的所有权似乎被意外设置为“spaikon”并且仅对该用户具有权限。这显然是不正确的。
由于该systemd-timedated.service
定义包含许多安全限制,因此即使该服务以 root 身份运行,它也无法访问完整的 root 权限。这里最相关的限制是CapabilityBoundingSet=CAP_SYS_TIME
:它排除CAP_DAC_OVERRIDE
,这是赋予root
其忽略文件和目录权限检查的能力的功能。如果没有它,负责启动的 systemd 子进程/lib/systemd/systemd-timedated
必须尊重文件和目录权限即使从技术上讲它是以 root 用户身份运行的。
要修复权限,请运行以下两个命令,按这个顺序:
sudo chmod go+rx /
sudo chown root:root /