跳转至内容

systemd/FAQ

来自 ArchWiki

FAQ

有关已知问题的最新列表,请查看上游的 TODO

为什么我的控制台上会出现日志消息?

你必须自行设置内核日志级别(loglevel)。在历史上,/etc/rc.sysinit 为我们执行此操作,并将 dmesg 的日志级别设置为 3,这是一个相当安静的级别。请在你的 内核参数中添加 loglevel=3quiet

如何更改默认的 getty 数量?

目前,默认仅启动一个 getty。如果你切换到另一个 TTY,那里将启动一个 getty(采用套接字激活方式)。换句话说,Ctrl+Alt+F2 将在 tty2 上启动一个新的 getty。

默认情况下,自动激活的 getty 数量上限为 6 个。因此 F7F12 不会启动 getty。

如果你想更改此行为,请编辑 /etc/systemd/logind.conf 并修改 NAutoVTs 的值。如果你希望所有 Fx 键都启动 getty,请将 NAutoVTs 的值增加到 12。如果你将 journald 转发到 tty12,请将 NAutoVTs 的值增加到 11(从而留出 tty12)。

你也可以预先激活在启动时即运行的 getty。

要添加另一个预激活的 getty,请 启用 (enable)启动 (start) getty@ttyX.service

要删除一个 getty,请 禁用 (disable)停止 (stop) 相应的 getty@ttyX.service

systemd 不使用 /etc/inittab 文件。

如何在启动过程中获取更详细的输出?

如果在 initram 消息之后控制台上完全没有输出,这意味着你的内核启动行中包含 quiet 参数。最好将其删除(至少在第一次使用 systemd 启动时),以确认一切正常。之后,你将看到一系列绿色的 [ OK ] 或红色的 [ FAILED ]

所有消息都会被记录到系统日志中。如果你想了解系统的状态,请使用 systemctl 或使用 journalctl 查看启动/系统日志。

如何避免在启动后清除控制台?

请参阅 getty#让启动消息留在 tty1

systemd 需要哪些内核选项?

不支持 3.0 之前的内核。

如果你使用自定义内核,需要确保选择了 systemd 的相关选项。

如果你正在为已安装版本的 systemd 编译新内核,所需的和推荐的选项列在 systemd 的 README 文件 /usr/share/doc/systemd/README 中。

如果你准备安装新版本的 systemd 且正在运行自定义内核,可以在 systemd GitHub 仓库中找到该文件的最新版本。

一个单元(unit)依赖于哪些其他单元?

例如,如果你想找出像 multi-user.target 这样的目标(target)拉入了哪些服务,可以使用类似以下的操作:

$ systemctl show -p "Wants" multi-user.target
Wants=rc-local.service avahi-daemon.service rpcbind.service NetworkManager.service acpid.service dbus.service atd.service crond.service auditd.service ntpd.service udisks.service bluetooth.service org.cups.cupsd.service wpa_supplicant.service getty.target modem-manager.service portreserve.service abrtd.service yum-updatesd.service upowerd.service test-first.service pcscd.service rsyslog.service haldaemon.service remote-fs.target plymouth-quit.service systemd-update-utmp-runlevel.service sendmail.service lvm2-monitor.service cpuspeed.service udev-post.service mdmonitor.service iscsid.service livesys.service livesys-late.service irqbalance.service iscsi.service

除了 Wants,你还可以尝试 WantedBy, Requires, RequiredBy, Conflicts, ConflictedBy, Before, After 来查找相应类型的依赖关系及其反向依赖。

我的计算机已关机,但电源依然开启

请使用 systemctl poweroff 而不是 systemctl halt

如何让脚本在启动过程中运行?

创建一个新文件 /etc/systemd/system/myscript.service 并添加以下内容:

/etc/systemd/system/myscript.service
[Unit]
Description=My script
 
[Service]
ExecStart=/usr/bin/my-script
 
[Install]
WantedBy=multi-user.target

本示例假设你希望在启动 multi-user 目标时运行该脚本。请确保脚本具有 可执行权限

启用 (enable) myscript.service 以便在启动时启动该服务。

注意:如果你想启动一个 shell 脚本,请确保脚本的第一行包含 #!/bin/sh。请不要写成 ExecStart=/bin/sh /path/to/script.sh,因为那样行不通。

服务单元的激活状态显示为绿色的 "active (exited)"

对于同时使用 RemainAfterExit=yes 的 oneshot 服务,这是预期行为。详情请参阅 systemd.service(5) § OPTIONS。表现出此行为的 oneshot 服务示例包括 systemd-user-sessions.services, nftables.serviceiptables.service

在尝试 启用 (enable) 单元时,你可能会遇到以下错误:

Failed to enable unit: File /etc/systemd/system/symlink already exists and is a symlink to file.

当启用单元时创建的 symlink(符号链接)已经存在于 /etc/systemd/system/ 中时,就会发生这种情况。这通常发生在从一个显示管理器切换到另一个(例如从 GDM 切换到 SDDM,它们分别由 gdm.servicesddm.service 启用),而相应的符号链接 /etc/systemd/system/display-manager.service 已经存在。

要解决这个问题,要么在启用新管理器之前先禁用相关的旧管理器,要么在启用新管理器时使用 -f/--force 选项以覆盖任何现有的冲突符号链接(参见 systemctl(1) § OPTIONS)。

© . This site is unofficial and not affiliated with Arch Linux.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.