如何使用 systemd-firstboot.service?

如何使用 systemd-firstboot.service?

我正在制作 Debian Jessie 的映像。启动时系统没有/etc/machine-id文件。这导致 journald 出现一些问题,无法启动。

我在 systemd repo 中发现:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=First Boot Wizard
Documentation=man:systemd-firstboot(1)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=systemd-sysusers.service sysinit.target shutdown.target
ConditionPathIsReadWrite=/etc
ConditionFirstBoot=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootbindir@/systemd-firstboot --prompt-locale --prompt-timezone --prompt-root-password
StandardOutput=tty
StandardInput=tty
StandardError=tty

它应该放在哪里才能运行?

在 systemd 215 中,ConditionFirstBoot 不可用。如何处理?

答案1

我有点惊讶你没有通过简单地安装 systemd 来准备这个脚本,但(一般来说)我认为答案是你应该把它放入/etc/systemd/system

在这种情况下(因为你正在做这一切来尝试获取机器 ID,以使 journald 工作),我想我可能会用检查你关心的文件来代替 ConditionFirstBoot /etc/machine-id

因此我可能会将 Unit 部分重写为:

[Unit]
Description=First Boot Wizard
Documentation=man:systemd-firstboot(1)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=systemd-sysusers.service sysinit.target shutdown.target
ConditionPathIsReadWrite=/etc
ConditionPathExists=!/etc/machine-id

话虽如此,如果可以使用你的镜像来发布更新的 systemd(我不擅长使用 Debian,所以我找不到任何地方来检查最新支持的版本是什么),那可能值得研究 - systemd 215 有一些问题已经得到修复(https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=systemd)。

相关内容