Yocto项目中systemd升级引发的问题及对策

最近Yocto项目中为了解决一些CVE问题,将systemdv237升级到了v242,结果根文件系统启动后发现原来可以正常工作的系统单元(包括machines.targetsystemd-networkd.service等)都不能正常工作了,初步调试发现文件系统的/etc目录下面居然没有安装这些系统单元:

$ ll /etc/systemd/system/multi-user.target.wants 
total 8.0K
drwxr-xr-x  2 root root 4.0K 4月  30 09:02 .
drwxr-xr-x 20 root root 4.0K 5月   3 15:21 ..

进一步追踪启动log发现了如下可疑错误:

systemd[1]: System cannot boot: Missing /etc/machine-id and /etc is mounted read-only.
systemd[1]: Booting up is supported only when:
systemd[1]: 1) /etc/machine-id exists and is populated.
systemd[1]: 2) /etc/machine-id exists and is empty.
systemd[1]: 3) /etc/machine-id is missing and /etc is writable.

之后在systemd的官方NEWS里面找到了v242版本的一个改动说明:

      During package installation (with `ninja install`), we would create
      symlinks for [email protected], systemd-networkd.service,
      systemd-networkd.socket, systemd-resolved.service,
      remote-cryptsetup.target, remote-fs.target,
      systemd-networkd-wait-online.service, and systemd-timesyncd.service
      in /etc, as if `systemctl enable` was called for those units, to make
      the system usable immediately after installation. Now this is not
      done anymore, and instead calling `systemctl preset-all` is
      recommended after the first installation of systemd.

翻译过来就是:

      以前的版本在包安装过程中(使用`ninja install`),会在/etc目录为如下单元创建链接:
      [email protected], systemd-networkd.service,
      systemd-networkd.socket, systemd-resolved.service,
      remote-cryptsetup.target, remote-fs.target,
      systemd-networkd-wait-online.service, and systemd-timesyncd.service。
      好像对这些单元调用了`systemctl enable`,以使
      系统安装后立即可用。现在不再使用这种方法了,而是推荐在包安装的
      时候调用`systemctl preset-all`

关于systemctl preset-all命令的说明可以参考systemd.preset,比较通俗的解释就是改用systemctl preset-all命令后所有的systemd单元在/etc目录下面的链接都是在系统启动时动态创建的(如果使用ninja install则在打包根文件系统包的时候就已经静态创建了这些链接),而不巧的是我们根文件系统一开始是以只读方式挂载的,所以解决这个问题的方式很简单,只需要重新挂载根文件系统为可读写即可:

mount  -o  rw,remount  / 

你可能感兴趣的:(Yocto)