systemd linux
systemd is 10 years old, but feelings about it in the Linux community haven’t mellowed—it’s as divisive now as it ever was. Although it’s used by many major Linux distributions, the hardcore opposition hasn’t relented.
systemd已有10年的历史了,但是在Linux社区中对此却没有丝毫的感觉–它现在和以往一样存在分歧。 尽管许多主要Linux发行版都在使用它,但坚决反对。
Linux引导顺序 (The Linux Boot Sequence)
When you power on your computer, the hardware boots, and then (according to the type of boot sector your computer uses) either the master boot record (MBR) executes or the Unified Extensible Firmware Interface (UEFI) runs. The last action of both of these is to fire up the Linux kernel.
当您打开计算机电源时,硬件会引导,然后(根据计算机使用的引导扇区的类型)执行主引导记录(MBR)或运行统一可扩展固件接口(UEFI)。 这两个的最后一个动作是启动Linux内核。
The kernel is loaded into memory, decompresses itself, and initializes. A temporary file system is created in RAM, usually by a utility called initramfs
or initrd
. This allows the required drivers to be determined and loaded. This, in turn, allows the user-space file system to load and prepare to establish the user-space environment.
内核被加载到内存中,对其自身进行解压缩并进行初始化。 通常通过称为initramfs
或initrd
的实用程序在RAM中创建一个临时文件系统。 这样可以确定并加载所需的驱动程序。 反过来,这允许用户空间文件系统加载并准备建立用户空间环境。
The creation of the user-space environment is handled by the init process, which is the first process launched by the kernel in a user space. It has a process ID (PID) of 1. All other processes are either direct or indirect children of the init process.
用户空间环境的创建由init进程处理,init进程是内核在用户空间中启动的第一个进程。 它的进程ID (PID)为1。所有其他进程是init进程的直接或间接子级。
Before systemd
, the mainstream default for the init process was a reworking of the Unix System V init. There were other choices available, but System V init was the standard option in most non-Berkeley Software Distribution (BSD) derived distributions. Because it came directly from System V Unix—the spiritual ancestor of Linux—many people regard it as “the official way” to do init.
在systemd
之前,init进程的主流默认设置是Unix System V init的重新设计。 还有其他选择,但是System V init是大多数非Berkeley软件发行版(BSD)衍生发行版的标准选项。 因为它直接来自Linux的祖先System V Unix,所以许多人将其视为进行初始化的“官方方式”。
The init process starts all the daemons and services required to make the operating system work in a meaningful, interactive way. These daemons handle things like the networking stack, enabling other hardware inside your computer, and providing a boot screen.
初始化过程启动使操作系统以有意义的交互方式工作所需的所有守护程序和服务。 这些守护程序处理诸如网络堆栈,启用计算机内部的其他硬件以及提供启动屏幕之类的事情。
Many of these background processes continue to run after they start. They do things like log event information, watch for hardware changes as you insert or remove devices, and manage user logins. Unsurprisingly, the init system also includes features to manage services.
这些后台进程中有许多在启动后仍继续运行。 它们执行诸如记录事件信息,在插入或移除设备时监视硬件更改以及管理用户登录之类的操作。 毫不奇怪,init系统还包括管理服务的功能。
We can use ps
to see the process that has PID 1. We’ll use the f
(full-format listing) and p
(PID) options:
我们可以使用ps
查看具有PID 1的进程。我们将使用f
(完整格式列表)和p
(PID)选项:
ps -fp 1
We see the process with PID 1 is systemd
. Running the same command on Manjaro Linux yielded a different result. The process with PID 1 was identified as /sbin/init
. A quick look at that file shows it is a symbolic link to systemd
:
我们看到PID 1的过程是systemd
。 在Manjaro Linux上运行相同的命令会产生不同的结果。 PID为1的进程被标识为/sbin/init
。 快速浏览该文件将显示它是systemd
的符号链接:
ps -fp 1
ls -hl /sbin/init
Using the ppid
(parent process ID) option with ps
, we can see which processes have been directly launched by systemd
:
使用ps
的ppid
(父进程ID)选项,我们可以看到systemd
直接启动了哪些进程:
ps -f --ppid 1
It’s quite a long list, as you can see in the image below.
清单很长,如下图所示。
替代方案 (The Alternatives)
Several projects have tried to produce an alternative to the traditional System V init. One of the main problems is, with System V init, all processes are started serially, one after another. To improve the efficiency of the boot sequence, many alternative projects use parallelism to start processes concurrently and asynchronously.
一些项目试图产生一种替代传统System V init的方法。 主要问题之一是,使用System V init,所有进程都一个接一个地顺序启动。 为了提高启动顺序的效率,许多替代项目都使用并行机制来并行和异步地启动进程。
Here’s some info on some of these:
以下是其中一些信息:
Upstart: Developed by Canonical, it was used in Ubuntu 9.10, Red Hat, Red Hat Enterprise Linux (RHEL) 6, CentOS 6, and Fedora 9.
暴发户:由Canonical开发,已在Ubuntu 9.10, Red Hat , Red Hat Enterprise Linux (RHEL)6, CentOS 6和Fedora 9中使用。
Runit: Runs on FreeBSD and other BSD derivatives, macOS, and Solaris, as well as Linux systems. It’s also the default init system on Void Linux.
Runit :在FreeBSD和其他BSD衍生版本,macOS和Solaris以及Linux系统上运行。 它也是Void Linux上的默认初始化系统。
s6-linux-init: This replacement for System V init was designed to closely follow the Unix philosophy, which is often reduced to the sound bite “do one thing, and do it well.”
s6-linux-init :替代System V init的目的是紧密遵循Unix哲学,该哲学通常被简化为“做一件事情,做好一件事情”。
There are many others of differing functionality and design. However, none of them created the furor systemd
did.
还有许多其他功能和设计不同的产品。 但是,他们都没有创造出狂怒的systemd
。
系统的方式 (The systemd Way)
systemd
was released in 2010 and was used in Fedora in 2011. Since then, it’s been adopted by many distributions. It was developed by Lennart Poettering and Kay Sievers, two software engineers at RedHat.
systemd
于2010年发布,并于2011年在Fedora中使用。此后,它被许多发行版采用。 它由RedHat的两位软件工程师Lennart Poettering和Kay Sievers开发。
systemd
is much more than an init replacement. Rather, it’s a suite of approximately 70 binaries that handle system initialization, daemons and services, logging and journaling, and many other functions that were already handled by dedicated modules in Linux. The bulk of these have nothing to do with system initialization.
systemd
不仅仅是一个init替代品。 相反,它是由大约70个二进制文件组成的套件,用于处理系统初始化,守护程序和服务,日志记录和日志记录,以及Linux中专用模块已经处理的许多其他功能。 其中大部分与系统初始化无关。
Some of the daemons provided by systemd
are:
systemd
提供的某些守护程序是:
systemd-udevd: Manages physical devices.
systemd-udevd:管理物理设备。
systemd-logind: Manages user logins.
systemd-logind:管理用户登录。
systemd-resolved: Provides network name resolution to local applications.
systemd-resolved:为本地应用程序提供网络名称解析。
systemd-networkd: Manages and detects network devices, and manages network configurations.
systemd-networkd :管理和检测网络设备,以及管理网络配置。
systemd-tmpfiles: Creates, deletes, and cleans up volatile and temporary files and directories.
systemd-tmpfiles:创建,删除和清除易失性和临时文件和目录。
systemd-localed: Manages system locale settings.
systemd-localed:管理系统区域设置。
systemd-machined: Detects and monitors virtual machines and containers.
systemd-machined:检测和监视虚拟机和容器。
systemd-nspawn: Can launch a command or other process in a lightweight namespace container, giving a functionality similar to chroot.
systemd-nspawn:可以在轻量名称空间容器中启动命令或其他进程,提供类似于chroot的功能。
And that’s just the tip of the iceberg, which is also the crux of the matter. systemd
has long since outstripped what’s required of an init system, which, according to its opponents, is the very definition of scope creep.
那只是冰山一角,这也是问题的症结所在。 长期以来, systemd
超越了init系统的要求,而init系统的反对者则是范围蠕变的定义。
“这个太大了。 太多了。” (“It’s Too Big. It Does Too Much.”)
Opponents of systemd
point out the large, curious mix of functionality it encompasses. All of these features already existed in Linux, and, perhaps, some of them needed a refresh or a new approach. However, to bundle all of this functionality in what is supposed to be an init system is architecturally puzzling.
systemd
反对者指出了它所包含的功能的巨大,奇特的组合。 所有这些功能已经在Linux中存在,也许其中一些功能需要刷新或采用新方法。 但是,将所有这些功能捆绑在一个应该是init系统中的架构上令人费解。
systemd
has been called a single point of failure for too many critical functions, but this doesn’t seem to be justifiable. Admittedly, it throws the Unix philosophy of creating small tools that work together instead of big pieces of software that do everything out the window. While systemd
isn’t strictly monolithic (it’s comprised of many binaries rather than a single huge one), it does include a lot of disparate management tools and commands under one umbrella.
由于太多关键功能, systemd
被称为单点故障,但这似乎没有道理。 诚然,它抛弃了Unix的哲学,即创建可以协同工作的小型工具,而不是大型软件来完成所有工作。 尽管systemd
并不是严格意义上的整体(它由许多二进制文件而不是一个巨大的二进制文件组成),但它的确包含了许多不同的管理工具和命令。
While it might not be monolithic, it is big. To get an idea of scale, we counted the lines of text in the kernel 5.6.15 codebase and the systemd
master branch of the GitHub repository.
尽管它可能不是单片的,但它很大。 为了了解规模,我们计算了内核5.6.15代码库和GitHub存储库的systemd
master分支中的文本行。
This was a relatively crude metric. It counted lines of text, not just lines of code. So, this included comments, documentation, and everything else. However, it was a like-for-like comparison and gave us a simple yardstick:
这是一个相对粗糙的指标。 它计算文本行,而不仅仅是代码行。 因此,这包括注释,文档和其他所有内容。 但是,这是一个类似的比较,它为我们提供了一个简单的准绳:
( find ./ -name '*.*' -print0 | xargs -0 cat ) | wc -l
The kernel had nearly 28 million (27,784,340, to be exact) lines of text. By contrast, systemd
had 1,349,969, or nearly 1.4 million. With our happy-go-lucky metric, systemd
comes out at about 5 percent the size of the kernel, which is crazy!
内核有将近2千8百万(准确地说是27 784 340)行文本。 相比之下, systemd
有1,349,969,即近140万。 使用我们的幸运度量, systemd
的大小约为内核大小的5%,这太疯狂了!
As another comparison, the line count for a modern implementation of System V init for the Arch Linux distribution came out to 1,721 lines.
作为另一个比较,Arch Linux发行版的System V init的现代实现的行数为1,721行。
Poettering plainly has no regard for the Institute of Electrical and Electronics Engineers (IEEE) Computer Society, nor the Portable Operating System Interface (POSIX) standard. In fact, he encouraged developers to ignore POSIX:
毫无疑问,Poettering既不考虑电气和电子工程师协会(IEEE)计算机协会,也不考虑便携式操作系统接口(POSIX)标准。 实际上,他鼓励开发人员忽略POSIX :
“So, get yourself a copy of The Linux Programming Interface, ignore everything it says about POSIX compatibility and hack away your amazing Linux software. It’s quite relieving!”
“因此,获取一份Linux编程接口的副本,忽略有关POSIX兼容性的所有说明,并破解您出色Linux软件。 真让人放松!”
There have been accusations that systemd
is a Red Hat project that only benefits Red Hat, yet it’s being force-fed to the wider Linux world. Yes, it was birthed within Red Hat and is governed and steered by it. However, of the 1,321 contributors, only a fraction work for Red Hat.
曾经有人指责systemd
是一个仅使Red Hat受益的Red Hat项目,但它却被迫送往更广阔Linux世界。 是的,它是在Red Hat中诞生的,并受它管理和指导。 但是,在1,321名贡献者中,只有很少一部分为Red Hat工作。
So, what are the benefits to Red Hat?
那么,红帽有什么好处?
Jim Whitehurst, the president of IBM, who was once the CEO of Red Hat, said:
IBM总裁Jim Whitehurst曾经是Red Hat的首席执行官,他说:
“Red Hat considered many available options and even used Canonical’s Upstart for Red Hat Enterprise Linux 6. Ultimately, we chose systemd because it is the best architecture that provides the extensibility, simplicity, scalability, and well-defined interfaces to address the problems we see today and foresee in the future.”
“ Red Hat考虑了许多可用选项,甚至使用了Canonical的Red Hat Enterprise Linux 6的Upstart。最终,我们选择systemd是因为它是提供可扩展性,简单性,可伸缩性和定义明确的界面来解决我们所遇到的问题的最佳架构。今天和未来。”
Whitehurst also said they saw benefits in embedded systems, too. Red Hat partners with “the largest embedded vendors in the world, particularly in the telecom and automotive industries where stability and reliability is the number one concern.”
Whitehurst还表示,他们也看到了嵌入式系统的好处。 红帽与“世界上最大的嵌入式供应商合作,尤其是在电信和汽车行业中,稳定性和可靠性是第一要务。”
These seem like technically sound reasons. You can understand the company’s need for reliability, and it’s not unreasonable for Red Hat to look out for its own interests, but should everyone else follow suit?
这些在技术上似乎是合理的原因。 您可以了解公司对可靠性的需求,红帽为其自身利益寻求利益并不是没有道理的,但是其他所有人也应该效仿吗?
喝系统的Kool-Aid吗? (Drinking the systemd Kool-Aid?)
Some opponents of systemd
say distributions and people are just blindly following Red Hat’s lead and adopting it.
一些反对systemd
说发行版,人们只是盲目地追随Red Hat的领导而采用它。
However, just like the phrase, “drinking the Kool-Aid,” that’s not quite right. Coined in 1978 after cult leader, Jim Jones, coerced his over 900 followers to commit suicide by drinking a grape-flavored liquid laced with cyanide, the phrase incorrectly shames Kool-Aid. The group actually drank Flavor Aid, but Kool-Aid’s been tarred by that brush ever since.
但是,就像“喝酷乐”一词一样,这不太正确。 邪教领袖吉姆·琼斯(Jim Jones)于1978年创立,他通过喝一种带有氰化物的葡萄味液体强迫他的900多名信徒自杀,这句话错误地使库尔德援助组织感到羞耻。 该小组实际上喝了Flavor Aid,但是从那以后,Kool-Aid就被那把刷子弄脏了。
Plus, Linux distributions aren’t blindly following Red Hat; they’re adopting systemd
after serious deliberation. The debate raged on the Debian mailing lists for a long time. However, in 2014, the community voted to adopt systemd
as the default init system, but to also support alternatives.
另外,Linux发行版并非紧随Red Hat之后。 经过认真考虑后,他们正在采用systemd
。 很长时间以来,辩论一直在Debian邮件列表上进行。 但是,在2014年,社区投票决定采用systemd
作为默认的init系统,但也支持替代方法。
Debian is an important example because it’s not derived from RedHat, Fedora, or CentOS. There’s no steerage applied to Debian from Red Hat. And Debian, like PID 1, has many descendants, including Ubuntu and its many spin-offs.
Debian是一个重要的示例,因为它不是源自RedHat,Fedora或CentOS。 没有从Red Hat应用于Debian的指导。 Debian和PID 1一样,有许多后代,包括Ubuntu及其衍生产品。
Decisions made by the Debian community are far-reaching. They’re also vigorously debated, and voted on using the Condorcet voting method. The community doesn’t make such choices lightly, either.
Debian社区做出的决定意义深远。 他们也进行了激烈的辩论,并使用Condorcet投票方法进行了投票。 社区也不会轻易做出这样的选择。
It voted again in December 2019 to continue to focus on systemd
and to continue to explore alternatives. The opposite of blindly following, this is actually a textbook example of democracy and freedom of choice at work.
它在2019年12月再次投票,继续专注于systemd
并继续探索替代方案。 与盲目的追随者相反,这实际上是民主和工作中的选择自由的教科书示例。
选择的局限性 (The Limitations of Choice)
You don’t generally get to choose whether to use systemd
with a particular Linux distribution. Rather, the distributions themselves choose whether they want to use it, and you can choose which Linux distro you prefer. Perhaps a Linux distribution you love switched to systemd
. Like a favorite musician who changes genres, this can be jarring.
通常,您不会选择是否在特定Linux发行systemd
中使用systemd
。 相反,发行版自己选择是否要使用它,并且您可以选择喜欢Linux发行版。 也许您喜欢Linux发行systemd
切换到systemd
。 就像最喜欢改变风格的音乐家一样,这可能会令人讨厌。
People who use Debian, Fedora, CentOS, Ubuntu, Arch, Solus, and openSUSE, and object to the adoption of systemd
, might feel they’re being edged out of using their distribution of choice. If they feel strongly enough about any of the architectural choices, scope creep, or disregard for POSIX, they might find it untenable to keep using that distribution.
使用Debian, Fedora , CentOS , Ubuntu , Arch , Solus和openSUSE的人,并反对采用systemd
,可能会觉得自己被淘汰了。 如果他们对任何体系结构选择,范围蠕变或对POSIX的漠视感足够强烈,那么他们可能会发现继续使用该发行版是站不住脚的。
There’s a spectrum, of course. At one end, you have the people who don’t understand the issues (or even care), and at the other, you have the passionate objectors. Somewhere in the middle are those who don’t like changes, but aren’t bothered enough about it to jump ship. But what about the distribution refugees, who can’t stay on their chosen distribution due to their preferences or principles?
当然有频谱。 一方面,您有不了解问题(甚至不关心)的人;另一方面,您有热情的反对者。 中间的某个地方是那些不喜欢变化,但对变化不那么感兴趣的人。 但是,分配难民又如何呢?由于他们的偏好或原则,他们不能留在他们选择的分配中吗?
Unfortunately, it’s not as easy as just installing whichever init system you want. Not everyone has the technical ability to do that, nevermind the difficulties that arise when applications or desktop environments, such as GNOME, have dependencies on systemd
.
不幸的是,这并不像安装所需的任何初始化系统那样简单。 并非每个人都有做到这一点的技术能力,不要忘记当应用程序或桌面环境(例如GNOME)依赖systemd
时出现的困难。
What about moving to another distribution? Some, like Devuan, appeared as non-systemd
forks of distributions (in this case, Debian) that had adopted systemd
. Using Devuan should be similar to the parent distribution, but that’s not the case for all non-systemd
forks. For example, if you leave Fedora and move to AntiX, Gentoo, or Slackware, you’re going to have a very different experience.
转移到另一个发行版怎么办? 像Devuan这样的软件,有些是采用systemd
非systemd
发行systemd
分支(在本例中为Debian)。 使用Devuan应该类似于父发行版,但并非所有非systemd
派生都并非如此。 例如,如果您离开Fedora并转到AntiX , Gentoo或Slackware ,您将获得完全不同的体验。
它不会去任何地方 (It’s Not Going Anywhere)
I like some of what systemd
does (simple and standardized control mechanisms for processes). I don’t understand the rationale for some of what it does (binary logs). I also dislike some of what it does (revamping home folders—who asked for that?).
我喜欢systemd
所做的一些工作(流程的简单和标准化控制机制)。 我不了解某些功能的原理(二进制日志)。 我还不喜欢它的某些功能(修改主文件夹-谁要求的?)。
Distributions like Debian are doing the smart thing and investigating alternatives to keep its options open. However, systemd
is in it for the long haul.
像Debian这样的发行版正在做聪明的事情,并且正在研究替代方案以保持其选择的开放性。 但是, systemd
可以长期使用。
If you administer Linux machines for others, learn systemd
as well as you know System V init. This way, no matter which you encounter, you’ll be able to perform your duties.
如果您为其他人管理Linux计算机,请学习systemd
并了解System V init。 这样,无论遇到哪种情况,您都可以履行职责。
Just use Linux at home? If so, choose a distribution that both meets your technical needs and complements your Linux ideology.
只是在家使用Linux? 如果是这样,请选择既要满足您的技术需求又要补充您Linux意识形态的发行版。
翻译自: https://www.howtogeek.com/675569/why-linuxs-systemd-is-still-divisive-after-all-these-years/
systemd linux