如何更改systemd上的运行级别?

很简单,我试图改变运行级别。 我在网上找到的所有内容都指向我所在的文件:

/etc/init/rc-sysinit.conf 

在这里,我尝试将“DEFAULT_RUNLEVEL”更改为3或其他任何内容,它没有任何区别(原始值为2也没有多大意义)。 无论如何,我的机器完全启动,当我检查运行级别命令时,我每次都看到“N 5”。

如何更改运行级别? 我宁愿不通过grub或其他一些解决方法来覆盖它。 我并不是在寻找如何禁用X。

我在网上找到的所有说明都有点陈旧,16.04有什么变化吗?

Ubuntu 16.04使用systemd而不是init,因此runlevels的概念被术语targets替换。 因此,基于init的运行级别和基于systemd的目标之间确实存在映射:

  Mapping between runlevels and systemd targets ┌─────────┬───────────────────┐ │Runlevel │ Target │ ├─────────┼───────────────────┤ │0 │ poweroff.target │ ├─────────┼───────────────────┤ │1 │ rescue.target │ ├─────────┼───────────────────┤ │2, 3, 4 │ multi-user.target │ ├─────────┼───────────────────┤ │5 │ graphical.target │ ├─────────┼───────────────────┤ │6 │ reboot.target │ └─────────┴───────────────────┘ 

现在,只需更改16.04中的“运行级别”,就可以使用例如:

 sudo systemctl isolate multi-user.target 

要使其成为默认的“运行级别”,您可以使用:

 sudo systemctl enable multi-user.target sudo systemctl set-default multi-user.target 

来自man systemctl

  isolate NAME Start the unit specified on the command line and its dependencies and stop all others. If a unit name with no extension is given, an extension of ".target" will be assumed. This is similar to changing the runlevel in a traditional init system. The isolate command will immediately stop processes that are not enabled in the new unit, possibly including the graphical environment or terminal you are currently using 

另请查看man systemd.special以了解有关systemd中目标的更多信息。