systemd/FAQ

出自 Arch Linux 中文维基

常見問題[編輯 | 編輯原始碼]

最新的已知問題,參見:TODO

為什麼控制台上會顯示日誌信息?[編輯 | 編輯原始碼]

請自行設置內核日誌等級(loglevel)。以前,/etc/rc.sysinit 幫我們把 dmesg 的日誌等級設置為 3,是比較合適的。 內核參數中加入 loglevel=3quiet 即可。

如何修改默認的 tty 控制台(getty)數量?[編輯 | 編輯原始碼]

目前默認僅啟動一個 getty,如果切換到其它 tty, 一改新的 getty 會通過 socket 激活方式啟動。例如 [Ctl] [Alt] [F2] 會在 tty2 啟動 getty。

默認情況下,最多可以自動啟動 6 個 getty。[F7] 到 [F12] 不會啟動 getty。要修改最大值,在 /etc/systemd/logind.conf 中修改 NAutoVTs。如果要啟用所有的 [Fx],可以將其設置為 12。如果要把 systemd/日誌#轉發 journald 到 /dev/tty12[損壞的連結:無效的章節],可以把 NAutoVTs 設置為 11。

修改啟動時啟用的 tty 個數,可以採取下面方法:

添加新的 getty:

/etc/systemd/system/getty.target.wants/ 添加新的軟連結即可:

# ln -sf /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty9.service
# systemctl start getty@tty9.service

移除 getty:

/etc/systemd/system/getty.target.wants/ 刪除對應的軟連結即可:

# rm /etc/systemd/system/getty.target.wants/getty@tty5.service /etc/systemd/system/getty.target.wants/getty@tty6.service
# systemctl stop getty@tty5.service getty@tty6.service

systemd 不使用 /etc/inittab 文件。

怎樣輸出更詳細的開機信息?[編輯 | 編輯原始碼]

如果內核信息輸出後就什麼信息都不輸出了,很可能是因為你在內核參數中添加了 quiet。刪除即可,然後你就可以看到一列列綠色的 [ OK ] 和紅色的 [ FAILED ]了。

所有信息都記錄在系統日誌,可以通過 $ systemctl 查看系統狀態,通過 journalctl 查看日誌。

開機後控制台信息會被清空,如何避免?[編輯 | 編輯原始碼]

創建 /etc/systemd/system/getty@.service.d 目錄,創建文件 nodisallocate.conf,將 TTYVTDisallocate 設置為 no.

/etc/systemd/system/getty@.service.d/nodisallocate.conf
[Service]
TTYVTDisallocate=no

Systemd 需要哪些內核模塊?[編輯 | 編輯原始碼]

systemd 不支持 3.0 版本之前的內核。

如果是自己編譯內核,需要開啟一些選項。請參考/usr/share/doc/systemd/README.

自己編譯 Systemd,請參考systemd git 中的版本.

怎樣知道一個目標需要哪些進程服務?[編輯 | 編輯原始碼]

例如,你可能想搞明白目標單元 multi-user.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,還可以查看各種形式的依賴和被依賴信息:WantedByRequiresRequiredByConflictsConflictedByBeforeAfter

電腦關閉了但電源沒有斷。[編輯 | 編輯原始碼]

使用systemctl poweroff 而不是 systemctl halt.

如何在啟動的時候,運行自定義的一個腳本?[編輯 | 編輯原始碼]

/etc/systemd/system 中新建一個文件(名稱可以為 myscript.service) 然後在其中寫入如下內容:

[Unit]
Description=My script

[Service]
ExecStart=/usr/bin/my-script

[Install]
WantedBy=multi-user.target 

然後開啟該守護進程

# systemctl enable myscript.service

本例是說當目標multi-usr載入的時候,會啟動你這個自定義腳本。腳本需要有可執行權限。

注意: 如果要啟動 shell 腳本,請把 #!/bin/sh 加到腳本的第一行,下面的做法不會成功ExecStart=/bin/sh /path/to/script.sh

.service 狀態顯示綠色的 "active (exited)" (例如 iptables)[編輯 | 編輯原始碼]

如果單次執行的程序配置了 RemainAfterExit=yes,這是正常的狀態。詳情請參考 systemd.service(5) § OPTIONSsystemd-user-sessions.servicesnftables.serviceiptables.service 等單次執行服務均是這樣。

因為軟連結已經存在,無法啟用服務[編輯 | 編輯原始碼]

啟用 單元時,可能出現如下錯誤:

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

此錯誤一般發生在啟用指令要創建的/etc/systemd/system/軟鏈已經存在的時候。典型的例子是在切換顯示管理器的時候(例如切換 GDMSDDM需要啟用 gdm.servicesddm.service),這時/etc/systemd/system/display-manager.service 已經存在。

要解決此問題,先禁用原來的顯示管理器或者使用 -f/--force 選項強制覆蓋原有連結,請參考 systemctl(1) § OPTIONS