如何在Ubuntu中添加另一个运行级别(级别7)?

时间:2020-03-06 14:31:18  来源:igfitidea点击:

Ubuntu有8个运行级别(0-6和S),我想添加运行级别7.

我已经完成以下工作:

1.创建文件夹/etc/rc7.d/,其中包含一些指向/etc/init.d/的符号链接

2.创建文件/etc/event.d/rc7,这是它的内容:

# rc7 - runlevel 7 compatibility
#
# This task runs the old sysv-rc runlevel 7 ("multi-user") scripts.  It
# is usually started by the telinit compatibility wrapper.

start on runlevel 7

stop on runlevel [!7]

console output
script
    set $(runlevel --set 7 || true)
    if [ "" != "unknown" ]; then
        PREVLEVEL=
        RUNLEVEL=
        export PREVLEVEL RUNLEVEL
    fi

    exec /etc/init.d/rc 7
end script

我以为就足够了,但是telinit 7仍然会抛出此错误:telinit:非法运行级别:7

解决方案

你不能;运行级别被硬编码到实用程序中。但是为什么需要呢?运行级别4本质上是未使用的。虽然这不是最好的主意,但我们可以根据是否始终使用X来重新定义运行级别3或者运行级别5.

请注意,某些* nix系统支持超过6个运行级别,但Linux并非其中之一。

我不确定如何添加它们(不需要),但是我很确定/ etc / inittab是我们添加运行级别的地方。

尽管我不得不同意Zathrus的说法,其他运行级别可用但未使用。实际上,在Debian上仅使用1和2. 不过,我不确定Ubuntu的设置方式。但是,如果我们有特定的目的,则应该可以做到。我只是从未有过。