systemd 文档和各种在线资源都声明 systemd 应该启动(默认情况下)名为“default.target”的“特殊”目标。可以通过 systemctl set-default 更改此设置,这基本上会创建从 default.target 到所需目标的符号链接。
但是在我的系统中没有这样的文件。没有/etc/systemd/system/default.target,没有/usr/lib/systemd/system/default.target(实际上整个系统中不存在这个文件)。系统仍在启动。我的问题是怎么会这样?
(当然我可以自己创建一个符号链接,我只是想知道如何在没有default.target的情况下定义默认值)
附加信息:
# systemctl get-default
graphical.target
所以我的默认目标是graphical.target。但它是在哪里(以及如何)定义的呢?
# find /usr/lib -iname "default.target" # no results
# find /etc -iname "default.target" # no results
# lsb_release -a
LSB Version: n/a
Distributor ID: Gentoo
Description: Gentoo Base System release 2.4.1
Release: 2.4.1
Codename: n/a
# systemctl list-units --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
machines.target loaded active active Containers
multi-user.target loaded active active Multi-User System
network-online.target loaded active active Network is Online
network.target loaded active active Network
nss-lookup.target loaded active active Host and Network Name Lookups
paths.target loaded active active Paths
remote-fs.target loaded active active Remote File Systems
slices.target loaded active active Slices
sockets.target loaded active active Sockets
sound.target loaded active active Sound Card
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
timers.target loaded active active Timers
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
18 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
答案1
根图将 systemd 文件的位置更改为/lib/systemd
2017 年 7 月。在我的系统上,我可以在以下位置看到默认符号链接/lib/systemd/system
:
$ ls -l /lib/systemd/system/default.target
lrwxrwxrwx 1 root root 16 Apr 2 15:48 /lib/systemd/system/default.target -> graphical.target
如果您添加符号链接/etc/systemd/system
(就像这样systemctl set-default
做),它将覆盖发行版的默认设置。