# 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
# Individual runlevels are started by /etc/init/rc.conf
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
# 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)
id:5:initdefault:
在CentOS 7下运行vim /etc/inittab结果如下:
[linuxidc@localhost linuxidc.com]$ vim /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
可以看到,里面除了注释,什么也没有,并没有CentOS 6中设置默认运行级别的方式。
注释内容大意是说,
# multi-user.target类似于runlevel 3;
# graphical.target类似于runlevel5
获得当前默认运行级别的方式为
systemctl get-default
设置默认运行级别的方式
systemctl set-default TARGET.target
设置运行级别命令格式:
systemctl [command] [unit.target]
需要命令 systemctl
设置默认的运行级别为 1 则命令为:systemctl set-default xxx
中对系统的级别对应是
init级别 systemctl target
0 shutdown.target
1 emergency.target
2 rescure.target
3 multi-user.target
4 无
5 graphical.target
6 无
备注:以上命令均需要超级管理员权限,如果需要临时切换 直接 init + 需要切换到的数字。
5、使用/etc/systemd/system/default.target文件系统的默认运行级别在systemd System的/etc/systemd/system/default.target文件中指定,它不适用于SysVinit系统:
[linuxidc@localhost linuxidc.com]$ cat /etc/systemd/system/default.target
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
After=multi-user.target rescue.service rescue.target display-manager.service
AllowIsolate=yes
详情见 https://www.linuxidc.com/Linux/2015-04/116648.htm
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx