16.6 Linux /etc/inittab

简介: 在 CentOS 6.x 中,/etc/inittab 配置文件只能用来设置系统的默认运行级别。

在 CentOS 6.x 中,/etc/inittab 配置文件只能用来设置系统的默认运行级别。

那么,什么是运行级别呢?其实 Linux 是通过运行级别来确定系统启动时到底启动哪些服务的。Linux 默认有 7 个运行级别,具体如表 1 所示。

运行级别 含 义
0 关机
1 单用户模式,可以想象为 Windows 的安全模式,主要用于系统修复
2 不完全的命令行模式,不含 NFS 服务
3 完全的命令行模式,就是标准字符界面
4 系统保留
5 图形模式
6 重新启动

在 Linux 系统中可以使用 runlevel 命令来查看系统的运行级别,命令如下:

[root@localhost ~]# runlevel
N 3
\#N代表在进入这个级别前,上一个级别是什么;3代表当前级别

在这个命令的结果中,"N 3"中的N代表在进入这个级别前,上一个级别是什么;3 代表当前级别。"N" 就是 None 的意思,也就是说,系统是开机直接进入 3 运行级别的,没有上一个运行级别。那如果从图形界面切换到字符界面,再查看运行级别,就应该是这样的:

[root@localhost ~]# runlevel
5 3
\#代表由5级别进入3级别

那么,可以手工改变当前的运行级别吗?当然可以了,只需使用 init 命令(注意这不是 init 进程)即可,命令如下:

[root@localhost ~]# init 5
\#进入图形界面,当然要已经安装了图形界面才可以
[root@localhost ~]# init 0
\#关机
[root@localhost ~]# init 6
\#重新启动

不过要注意,使用 init 命令关机和重启并不是太安全,容易造成数据丟失。所以推荐大家使用 shutdown 命令进行关机和重启。

系统默认运行级别

知道了运行级别的作用,我们回到系统启动过程中来。/etc/inittab 配置文件的功能就是确定系统的默认运行级别,也就是系统开机后会进入那个运行级别。此文件的内容如下:

[root@localhost ~]#vim /etc/inittab
\# inittab is only used by upstart for the default runlevel.
\#
\# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
\#
\# System initialization is started by /etc/init/rcS.conf
\#系统会先调用/etc/init/rcS.conf
\# Individual runlevels are started by /etc/init/rc.conf
\#在调用/etc/init/rc.conf,在不同的运行级别启动不同的服务
\# Ctrl-Alt-Delete is handled by/etc/init/control-alt-delete.conf
\#通过这个配置文件判断Ctri+Alt+Delete热启动键是否可用
\# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
\# with configuration in /etc/sysconfig/init.
\#判断系统可以启动的本地终端数量及终端的基本设置(如颜色)
\# For information on how to write upstart event handlers, or how
\# upstart works, see init(5), init(8), and initctl(8).
\#
\# Default runlevel. The runlevels used are:
\# 0 - halt (Do NOT set initdefault to this)
\# 1 - Single user mode
\# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
\# 3 - Full multiuser mode
\# 4 - unused
\# 5-X11
\# 6 - reboot (Do NOT set initdefault to this)
\#很眼熟吧,就是刚刚的 0~6运行级别的说明
id:3:initdefault:
\#这就是系统的默认运行级别,也就是系统开机后直接进入哪个运行级别

注意,这里的默认运行级别只能写 3 或 5,其他的级别要么是关机重启,要么是保留或单用户,都不能作为系统默认运行级别。

目录
相关文章
|
16小时前
|
Linux Shell
linux之/etc/default/useradd文件
linux之/etc/default/useradd文件
37 0
|
16小时前
|
Linux 网络安全
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
35 1
|
16小时前
|
Linux 数据安全/隐私保护
linux之/etc/login.defs文件
linux之/etc/login.defs文件
31 5
|
16小时前
|
Linux
linux之/etc/skel目录
linux之/etc/skel目录
137 2
|
16小时前
|
网络协议 Linux 开发工具
Linux中 /etc/sysconfig/network-scripts/ifcfg-<interface> 网络接口配置 详解 看这一篇够用
Linux中 /etc/sysconfig/network-scripts/ifcfg-<interface> 网络接口配置 详解 看这一篇够用
|
16小时前
|
Shell Linux
linux shell脚本实现/etc/passwd文件是否被更改
linux shell脚本实现/etc/passwd文件是否被更改
17 3
|
16小时前
|
存储 Web App开发 Linux
Linux文件:/etc/fstab
Linux文件:/etc/fstab
59 0
|
8月前
|
安全 Unix Linux
15.3.2 【Linux】系统的配置文件:/etc/crontab,/etc/cron.d/*
15.3.2 【Linux】系统的配置文件:/etc/crontab,/etc/cron.d/*
104 0
|
10月前
|
Linux
Linux系统无法启动问题及解决方案(/etc/fstab文件损坏,GRUB文件损坏)
Linux系统无法启动问题及解决方案(/etc/fstab文件损坏,GRUB文件损坏)
449 0
|
Linux 数据安全/隐私保护
Linux 改动inittab文件及忘记密码等导致无法进入系统的解决办法
Linux 改动inittab文件及忘记密码等导致无法进入系统的解决办法
92 0