1. 报错原因
系统中安装了oh-my-zsh,此软件依赖了pkg,系统启动时会检查更新pkg,但是启动时系统还没联网所以无法更新。
更新是以systemctl服务的形式进行更新的,服务文件位于/lib/systemd/system,可以看到有两个和pkg有关的服务 ,pkgfile-update.timer
先查看以下两个服务状态,可以看到pkgfile-update.timer会触发pkgfile-update.service。
分别打开两个文件看看
$ cat pkgfile-update.timer
[Unit]
Description=pkgfile database update timer
[Timer]
OnbootSec=30min
OnUnitActiveSec=1weeks
Persistent=no
[Install]
WantedBy=multi-user.target
$ cat pkgfile-update.service
[Unit]
Description=pkgfile database update
RequiresMountsFor="/var/cache/pkgfile"
After=network-online.target
Wants=network-online.target
[Timer]
OnBootSec=50min
OnUnitActiveSec=1week
Persistent=no
[Service]
Type=oneshot
ExecStart=/usr/bin/pkgfile -u
Nice=19
StandardOutput=null
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
CapabilityBoundingSet=
NoNewPrivileges=yes
可以看到,实际上service中最终执行的是ExecStart后面的/usr/bin/pkgfile -u,就是这个命令在开机时因为没网,肯定失败,我们要做的是在开机成功后过一会再执行这个联网更新命令。可以参考我上面的,上面的两个文件是我改过的。
2 结论
开机报错是因为开机时没网,但是系统有个定时服务,是 一开机就联网更新pkgfile,所以失败了。
3 解决方式
- 手动运行命令
sudo pkgfile -u
,此方式治标不治本 - 更改pkgfile-update.service,和pkgfile-update.timer,把OnbootSec时间改长一些,不要让开机马上就执行,开机瞬间可能没网
$ cat pkgfile-update.timer
[Unit]
Description=pkgfile database update timer
[Timer]
OnbootSec=30min
OnUnitActiveSec=1weeks
Persistent=no
[Install]
WantedBy=multi-user.target
$ cat pkgfile-update.service
[Unit]
Description=pkgfile database update
RequiresMountsFor="/var/cache/pkgfile"
After=network-online.target
Wants=network-online.target
[Timer]
OnBootSec=50min
OnUnitActiveSec=1week
Persistent=no
[Service]
Type=oneshot
ExecStart=/usr/bin/pkgfile -u
Nice=19
StandardOutput=null
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
CapabilityBoundingSet=
NoNewPrivileges=yes