运行级别(Runlevel)指的是Unix或者Linux等类Unix操作系统下不同的运行模式,本文记录相关内容。

一般情况下我们处于的运行级在3或者5,切换至 0 就是关机, 6 就是重启
在Ubuntu下可以通过
$runlevel查看当前运行级别
$ runlevel
N 5telinit num或者
init num切换运行级别。
例如可以通过以下命令重启:
telinit 6   
# or
init 6/etc/init.d这个文件夹下,就是可以运行的脚本:$ ll /etc/init.d/
总用量 232
drwxr-xr-x   2 root root 4096 11月 16 13:17 ./
drwxr-xr-x 137 root root 8192 11月 16 13:17 ../
-rwxr-xr-x   1 root root 2269 11月 28  2019 acpid*
-rwxr-xr-x   1 root root 5574 11月  5  2019 alsa-utils*
-rwxr-xr-x   1 root root 2055 7月  17  2019 anacron*
-rwxr-xr-x   1 root root 3740 4月   1  2020 apparmor*
-rwxr-xr-x   1 root root 2964 12月  7  2019 apport*
-rwxr-xr-x   1 root root 2401 8月  21  2018 avahi-daemon*
-rwxr-xr-x   1 root root 2968 2月  26  2020 bluetooth*
-rwxr-xr-x   1 root root 1232 3月  27  2020 console-setup.sh*
-rwxr-xr-x   1 root root 3059 2月  11  2020 cron*
-rwxr-xr-x   1 root root 2804 2月  17  2020 cups*
-rwxr-xr-x   1 root root 1961 4月  10  2020 cups-browsed*
-rwxr-xr-x   1 root root 3152 9月  30  2019 dbus*
-rwxr-xr-x   1 root root 3033 11月 10  2020 gdm3*
-rwxr-xr-x   1 root root  985 8月  12 17:18 grub-common*
-rwxr-xr-x   1 root root 3809 7月  29  2019 hwclock.sh*
-rwxr-xr-x   1 root root 2638 12月 13  2019 irqbalance*
-rwxr-xr-x   1 root root 3131 5月  19  2017 kerneloops*
-rwxr-xr-x   1 root root 1479 11月 27  2019 keyboard-setup.sh*
-rwxr-xr-x   1 root root 2044 2月  19  2020 kmod*
-rw-r--r--   1 root root    0 11月 16 13:17 .legacy-bootordering
-rwxr-xr-x   1 root root  695 1月  28  2020 lvm2*
-rwxr-xr-x   1 root root  586 1月  28  2020 lvm2-lvmpolld*
-rwxr-xr-x   1 root root 1942 9月  17  2020 network-manager*
-rwxr-xr-x   1 root root 5658 5月  13  2021 nfs-common*
-rwxr-xr-x   1 root root 4836 5月  25 04:51 nfs-kernel-server*
-rwxr-xr-x   1 root root 9138 7月  20 03:26 openvpn*
-rwxr-xr-x   1 root root 1366 3月  23  2020 plymouth*
-rwxr-xr-x   1 root root  752 3月  23  2020 plymouth-log*
-rwxr-xr-x   1 root root  612 2月   9  2019 pppd-dns*
-rwxr-xr-x   1 root root  924 2月  14  2020 procps*
-rwxr-xr-x   1 root root  469 10月 16  2020 pulseaudio-enable-autospawn*
...
这6种模式还有许多功能,比如说如果忘记了root密码就可以进入单用户模式,在启动后的提示符界面下输入init = /bin/sh rw就进入了模式1,把root文件挂为读写就可以跳过系统认证,直接用passwd程序来更改root用户口令了,然后再启动到正常的运行级去即可