ubuntu中update-rc.d命令使用说明

一、linux系统主要启动步骤

读取mbr的信息,启动boot manager。加载系统内核,启动init进程,init进程是linux的根进程,所有的系统进程都是它的子进程。

init进程读取/etc/inittab文件中的信息,并进入预设的运行级别。通常情况下/etc/rcS.d/目录下的启动脚本首先被执行,然后是/etc/rcN.d/目录。

二、运行级别

级别 描述
0 关闭系统
1 单用户模式,只允许root用户对系统进行维护
2 ~ 5 多用户模式,其中3为字符界面,5为图形界面
6 重启系统

三、切换运行级别

命令:init [0123456Ss]

# 命令关机 init 0# 命令重新启动 init 6

四、update-rc.d命令说明

从所有的运行级别中删除指定启动项

 update-rc.d -f remove

按指定顺序、在指定运行级别中启动或关闭

 update-rc.d start|stop

五、update-rc.d使用实例

 update-rc.d apachectl start 20 2 3 4 5 . stop 20 0 1 6 .

这个例子表示在2、3、4、5这五个运行级别中,由小到大,第20个开始运行apachectl,在0、1、6这3个运行级别中,第20个关闭apachectl。这是合并起来的写法,注意它有2个点号,效果等于下面方法:

 update-rc.d apachectl defaults

A启动后B才能启动,B关闭后A才关闭

 update-rc.d A defaults 80 20 update-rc.d B defaults 90 10

启动和关闭顺序为90,级别默认

 update-rc.d defaults 90

以下为帮助手册中的一些示例:

 update-rc.d foobar defaults

Equivalent command using explicit argument sets:

 update-rc.d foobar start 20 2 3 4 5 . stop 20 0 1 6 .

More typical command using explicit argument sets:

 update-rc.d foobar start 30 2 3 4 5 . stop 70 0 1 6 .
 update-rc.d foobar remove

Example of disabling a service:

 update-rc.d -f foobar remove update-rc.d foobar stop 20 2 3 4 5 .

Example of a command for installing a system initialization-and-shut‐down script:

 update-rc.d foobar start 45 S . start 31 0 6 .

Example of a command for disabling a system initialization-and-shutdown script:

 update-rc.d -f foobar remove update-rc.d foobar stop 45 S .

References

  1. http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html
  2. http://blog.wangyan.org/ubuntu-update-rc-d.html