在 systemd-nspawn 容器内运行时,hostnamectl 失败并显示“连接超时”

在 systemd-nspawn 容器内运行时,hostnamectl 失败并显示“连接超时”

我正在使用systemd-nspawnqemu-arm-static启动 Raspberry Pi 操作系统映像,以将自定义应用到库存映像,然后再将其闪存到 SD 卡上。

  • 主机是Ubuntu 20.10(systemd版本:246.6-1ubuntu1)
  • 客户操作系统是Raspberry Pi OS(2020年8月,基于Debian Buster,systemd版本:241)

这非常有效:我可以使用安装软件包apt-get,使用启用服务systemctl等。

但有一个例外:hostnamectl,这是在现代 Linux 发行版上设置主机名的首选方法。

# hostnamectl
Failed to query system properties: Connection timed out

我在系统日志中看到以下输出:

Oct 26 20:08:05 raspberrypi dbus-daemon[219]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.23' (uid=0 pid=2300 comm="/usr/bin/qemu-arm-static /usr/bin/hostnamectl " label="unconfined")
Oct 26 20:08:05 raspberrypi systemd[1]: Starting Hostname Service...
Oct 26 20:08:05 raspberrypi systemd[2303]: systemd-hostnamed.service: Failed to set up network namespacing: Input/output error
Oct 26 20:08:05 raspberrypi systemd[2303]: systemd-hostnamed.service: Failed at step NETWORK spawning /lib/systemd/systemd-hostnamed: Input/output error
Oct 26 20:08:05 raspberrypi systemd[1]: systemd-hostnamed.service: Main process exited, code=exited, status=225/NETWORK
Oct 26 20:08:05 raspberrypi systemd[1]: systemd-hostnamed.service: Failed with result 'exit-code'.
Oct 26 20:08:05 raspberrypi systemd[1]: Failed to start Hostname Service.
Oct 26 20:08:30 raspberrypi dbus-daemon[219]: [system] Failed to activate service 'org.freedesktop.hostname1': timed out (service_start_timeout=25000ms)

我使用以下命令启动图像:

systemd-nspawn -b -i /dev/loop3p2

作为设置主机名的解决方法,我使用经典方法:

# echo my-pi > /etc/hostname
# echo "127.0.1.1 my-pi" >> /etc/hosts

这工作得很好,但我仍然想了解为什么该hostnamectl方法在运行时不起作用systemd-nspawn,以及这是否是预期的行为。

相关内容