如何使用 systemd-firstboot.service?

Vel*_*kan 11 linux boot systemd

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

我在 systemd 仓库中发现:

#  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
Run Code Online (Sandbox Code Playgroud)

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

在 systemd 215 中, ConditionFirstBoot 不可用。怎么处理?

iwa*_*rue 1

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

在这种情况下(因为您正在执行所有这些操作来尝试获取机器ID,以便使日志工作),我想我可能会用对您关心的文件的检查来替换 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
Run Code Online (Sandbox Code Playgroud)

话虽这么说,如果可以随您的映像一起提供更新的 systemd(我对 Debian 不太熟悉,所以我找不到任何地方来检查最新支持的版本是什么),这可能值得研究 - systemd 215 有一些问题已得到修复(https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=systemd)。