修改Ubuntu的runlevel


Ubuntu的默认开机的runlevel是2,可以用runlevel来查看当前的默认运行级别。

debian系(ubuntu是基于debian)的Linux一直是用runlevel 2来默认启动,并且runlevel定义也与redhat有区别。

debian的runlevel级别定义如下:
0 - Halt
1 - Single
2 - Full multi-user with display manager (GUI)
3 - Full multi-user with display manager (GUI)
4 - Full multi-user with display manager (GUI)
5 - Full multi-user with display manager (GUI)
6 - Reboot

可以发现2~5级是没有任何区别的。

######而redhat的runlevel级别定义如下:
######0 - Halt
######1 - Single
######2 - Not used/User definable
######3 - Full multi-user NO display manager
######4 - Not used/User definable
######5 - Full multi-user with display manager (GUI)
######6 - Reboot

对应的配置文件夹如下:
/etc/rc0.d Run level 0
/etc/rc1.d Run level 1
/etc/rc2.d Run level 2
/etc/rc3.d Run level 3
/etc/rc4.d Run level 4
/etc/rc5.d Run level 5
/etc/rc6.d Run level 6

这里的runlevel3-5都是进入图形界面。这与其他的linux发行版不太一致,通常runlevel 3是Multi user mode,即直接登录到字符界面;而runlevel 5是Multi user mode with GUI,即登录到图形界面。

现在把runlevel3改为Multi user mode需要如下步骤:

一、删除gdm的启动项
找到/etc/rc3.d中的gdm项,把它删除,如果想恢复,可以重新建立一个到/etc/init.d中的gdm链接。

二、修改默认的runlevel
如果暂时修改,可以使用telinit N,这里的N可以是runlevel的代码[0-6]。如果想长期修改,可以在/etc/下建立inittab文件(这个文件在其他发行版中是存在的,而在Debian及其衍生版中是没有的)。文件内容如下

id:3:initdefault:
注意最后的冒号,这样就说明启动时默认为runlevel 3。

sudo reboot试试看是不是到了文本界面下。

参考文献:
http://www.linuxdiyf.com/viewarticle.php?id=92001

Debian and Ubuntu Linux Run Levels

PS: GDM

GDM (The GNOME Display Manager)是GNOME显示环境的管理器,并被用来替代原来的X Display Manager。与其竞争者(X3DM,KDM,WDM)不同,GDM是完全重写的,并不包含任何XDM的代码。GDM可以运行并管理本地和远程登录的X 服务器(通过XDMCP)。详情请看http://www.gnome.org/projects/gdm/。gdm仅仅是一个脚本,实际上是通过他来运行GDM二进制可执行文件。gdm-stop是用来迅速终止当前正在运行的gdm守护进程的一个脚本。gdm-restart脚本将迅速重启当前守护进程。然而gdm-safe-restart会当所有人都注销后再重启。gdmsetup是一种可以很简单的修改多数常用选项的图形化界面工具。GNOM的帮助里有更完整的文档,在“应用程序”/“系统工具”这一章节。

  选项:

(gdm脚本和二进制文件都接受一下选项)
-nodaemon 不启动到后台;
--no-console 不运行控制台(本地)服务器;
--preserve-ld-vars 持续维持的LD_*变量;
--version 查看GDM版本信息;
--help 查看gdmsetup接受选项的简单描述

   配置

  可以直接运行gdmsetup或修改/etc/X11/gdm/gdm.conf文件来进行配置GDM(或/etc/gdm/gdm.conf文件)。图形化工具并不支持所有的选项,所以,有时有必要通过修改配置文件来达到目的。

PS: ubuntu's runlevel

refer http://linux.chinaunix.net/techdoc/system/2008/10/12/1037590.shtml

Ubuntu default init setting:
/etc/event.d/rc-default:
Modify the 3rd line from bottom to the default runlevel you like.
Here, to modify rcX.d to configure how different runlevel behaves.
########################Linux run levels are numbered 0 through 6. Run levels stop at six for practical and historical reasons, but it is entirely possible to have more if desired.
The following table summarizes the User
Linux
run levels:
* 0 System Halt
* 1 Single user
* 2 Full multi-user mode (Default)
* 3-5 Same as 2
* 6
System
Reboot
Special Run Levels
Run level 0 is the system halt condition. Nearly all modern X86
computers
will power off automatically when run level 0 is reached. Older X86 computers, and various different architectures will remain powered on and display a message referring to the halt condition.
Run Level 1 is known as ’single user’ mode. A more apt description would be ‘rescue’, or ‘trouble-shooting’ mode. In run level 1, no daemons (services) are started. Hopefully single user mode will allow you to fix whatever made the transition to rescue mode necessary.
(You can boot into single user mode typically by using your boot loader, lilo or grub, to add the word ’single’ to the end of the kernel command line).
Run levels 2 through 5 are full multi-user mode and are the same in a default User Linux (
Debian
) system. It is a common practice in other
Linux distributions
to use run level 3 for a text console login and run level 5 for a graphical login.
Run level 6 is used to signal system reboot. This is just like run level 0 except a reboot is issued at the end of the sequence instead of a power off.
In the interests of completeness, there is also a runlevel ‘S’ that the system uses on it’s way to another runlevel. Read the man page for the init command (”For manpage click here”) for more information, but you can safely skip this for all practical purposes.
Run Levels Location
Like everything else in a Linux system, run levels are defined by files in the
file system
. All the run level files are found in the /etc directory according to the following table:
/etc/rc0.d Run level 0
/etc/rc1.d Run level 1
/etc/rc2.d Run level 2
/etc/rc3.d Run level 3
/etc/rc4.d Run level 4
/etc/rc5.d Run level 5
/etc/rc6.d Run level 6
Each defined run level should have an rcX.d directory where X is the run level number. The contents of the rcX.d directory determines what happens at that run level.
Change run levels in Debian and Ubuntu Linux
Before we change run levels it might help to find out which run level is current. Use the ‘runlevel’ command to tell you two things: The last run level, and the current run level. Here is the command and the output shown together due to the sparsity of the output:
# runlevel N 2
The ‘N’ stands for none, meaning there has been no run level change since powering up.
The init system controls run levels, but then again, the init system pretty much controls everything. The init system will be looked at in detail in a future article.
The primary command used to change run levels is ‘telinit’.
#telinit 3
telinit takes one argument on the command line. As always, see the man page for full details. Normally the argument will be one of: 0,1,2,3,4,5,6, or the letter ‘S’. As you may have guessed, the numbers correspond to the run level you wish to move to. Using the ‘S’, for single-user, is the same as the number 1, but don’t do it; the ‘S’ runlevel is intended for use by the UserLinux (Debian)system.
A note of caution is warranted here. You can easily use the telinit command to reboot (run level 6), or shutdown (run level 0) the system, but it is not recommended. Certain programs need special processing for an orderly shutdown. Bypassing the expected shutdown sequence can have dire effects on your data. Older _Unix_ systems are especially sensitive to shutdown/bootup operations.
The preferred method for a serious runlevel change is ’shutdown’. There are easier mnemonics, but in a running system they all point to the ’shutdown’ command. You can use the ‘halt’, or ‘poweroff’ command to stop a system and the ‘reboot’ command to restart your system. In each case they call the ’shutdown’ command with different parameters.
If you wanted runlevel 3 to be the default, then you need to edit /etc/inittab.
# The default runlevel.
id:2:initdefault:
You’d change the ‘2′ to a ‘3′. Next time you reboot, your system will start in runlevel 3. There will be no display manager running in runlevel 3, because you turned it off. Therefore, runlevel 3 will become text only, and it will be the default. If that’s what you want to do.
Adding a new service
You can only add a new service to the boot sequence if a script in /etc/init.d exists. In that case the following command will install it with default settings (foo being the name of a script in /etc/init.d).
#update-rc.d foo default
Removing a service
A service may only be removed after the script in /etc/init.d as deleted already. If so, the following command will remove its references (foo being the name of a script in /etc/init.d).
#update-rc.d foo remove
If you want to remove a service without removing the start/stop script as well, you may consider using the file-rc package and editing the runlevel configuration file /etc/runlevel.conf. When using the SysV method you should rename the start/stop script, then call update-rc.d and then rename the start/stop script back to its old name.

Author Info :
  • From:修改Ubuntu的runlevel
  • URL:http://blog.ihipop.info/2009/06/88.html
  • Please Reserve This Link,Thanks!
  • 发表评论

    电子邮件地址不会被公开。 必填项已用*标注