首先,systemd
不是传统的unix init
。Systemd的功能远不止如此,因此将两者进行比较有点不公平。
要回答这个问题,似乎需要一些二进制文件和以下配置文件:
/usr/lib/systemd/system/default.target
/usr/lib/systemd/system/basic.target
/usr/lib/systemd/system/sysinit.target
/usr/lib/systemd/system/getty.target
/usr/lib/systemd/system/getty@.service
/usr/lib/systemd/system/console-getty.service
发行systemctl enable console-getty.service getty@tty2.service
然后创建以下符号链接:
/etc/systemd/system/default.target.wants/getty@tty2.service-> / lib / systemd / system / getty @ service
/etc/systemd/system/getty.target.wants/console-getty.service-> /lib/systemd/system/console-getty.service
注意:要利用systemd
的特殊功能来agetty
动态启动,按Alt+ F3等时按需启动,看来您还必须至少具有以下两个文件:
/etc/systemd/logind.conf
/lib/systemd/system/autovt@.service
autovt@.service
的符号链接在哪里getty@.service
?
配置文件内容:
的default.target
,getty.target
,sysinit.target
文件可以是除空[Unit]
标签和(可能)Description=xxx
。
basic.target
还包含依赖项信息:
[单元]
Description =基本系统
需要= sysinit.target
Wants = sockets.target timers.target路径.target slices.target
After = sysinit.target sockets.target timers.target路径.target slices.target
我不确定是否需要引用文件中不存在的目标。它们在systemd.special(7)
手册页中进行了描述。
console-getty.service
:(控制台上agetty的特殊情况)
[单元]
Description =控制台盖蒂
After = systemd-user-sessions.service plymouth-quit-wait.service
之前= getty.target
[服务]
ExecStart =-/ sbin / agetty --noclear --keep-baud控制台115200,38400,9600 $ TERM
类型=空闲
重启=总是
RestartSec = 0
UtmpIdentifier =缺点
TTYPath = / dev /控制台
TTYReset =是
TTYVHangup =是
KillMode =进程
IgnoreSIGPIPE =否
SendSIGHUP =是
[安装]
WantedBy = getty.target
getty@.service
:(所有getty服务的通用配置,但控制台除外)
[单元]
描述=%I的Getty
After = systemd-user-sessions.service plymouth-quit-wait.service
之前= getty.target
IgnoreOnIsolate =是
ConditionPathExists = / dev / tty0
[服务]
ExecStart =-/ sbin / agetty --noclear%I $ TERM
类型=空闲
重启=总是
RestartSec = 0
UtmpIdentifier =%I
TTYPath = / dev /%I
TTYReset =是
TTYVHangup =是
TTYVTDisallocate =否
KillMode =进程
IgnoreSIGPIPE =否
SendSIGHUP =是
[安装]
WantedBy = getty.target
DefaultInstance = tty1
最后,您可能需要一些特殊的二进制文件(我没有尝试过哪些是至关重要的):
/ lib / systemd / systemd(/ sbin / init通常指向此)
/ lib / systemd / systemd-logind
/ lib / systemd / systemd-cgroups-agent
/ lib / systemd / systemd-user-sessions
/ lib / systemd / systemd-vconsole-setup
/ lib / systemd / systemd-update-utmp
/ lib / systemd / systemd-sleep
/ lib / systemd / systemd-sysctl
/ lib / systemd / systemd-initctl
/ lib / systemd / systemd-reply-password
/ lib / systemd / systemd-ac-power
/ lib / systemd / systemd-activate
/ lib / systemd / systemd-backlight
/ lib / systemd / systemd-binfmt
/ lib / systemd / systemd-bootchart
/ lib / systemd / systemd-bus-proxyd
/ lib / systemd / systemd-coredump
/ lib / systemd / systemd-cryptsetup
/ lib / systemd / systemd-fsck
/ lib / systemd / systemd-hostnamed
/ lib / systemd / systemd-journald
/ lib / systemd / systemd-journal-gatewayd
/ lib / systemd / systemd-journal-remote
/ lib / systemd / systemd-localed
/ lib / systemd / systemd-machined
/ lib / systemd / systemd-modules-load
/ lib / systemd / systemd-multi-seat-x
/ lib / systemd / systemd-networkd
/ lib / systemd / systemd-networkd-wait-online
/ lib / systemd / systemd-quotacheck
/ lib / systemd / systemd-random-seed
/ lib / systemd / systemd-readahead
/ lib / systemd / systemd-remount-fs
/ lib / systemd / systemd-resolved
/ lib / systemd / systemd-rfkill
/ lib / systemd / systemd-shutdown
/ lib / systemd / systemd-shutdownd
/ lib / systemd / systemd-socket-proxyd
/ lib / systemd / systemd-timedated
/ lib / systemd / systemd-timesyncd
/ lib / systemd / systemd-udevd
/ lib / systemd / systemd-update-done
总结一下systemd启动过程,我认为它的工作原理如下:
- systemd定位
basic.target
(或所有*.target
文件?)
- 依赖关系是基于解决
WantedBy=
,Wants=
,Before=
,After=
...在指令[Install]
中的部分*.service
和*.target
配置文件。
*.service
应该启动的(不是“特殊”服务)具有一个[Service]
带有ExecStart=
指令的部分,指出要启动的可执行文件。