查看: 11190|回复: 27

ubuntu 和redhat系列 启动的差别

[复制链接]
发表于 2009-11-10 14:05:40 | 显示全部楼层 |阅读模式
关键词: REDHAT , Ubuntu
rc 脚本,
这个是系统内核启动后,首先执行的。
在redhat下的/etc/inittab 在ubunbu里面没有
所以,inittab中的这个更早应该执行的文件不存在
si::sysinit:/etc/rc.d/rc.sysinit

/etc/inittab文件,如果需要,可以从redaht拷贝过来。
rc.sysinit也拷贝过来,应该会先于rc执行。

rc脚本的位置不同:
redhat : /etc/rc.d/rc
ubuntu:/etc/init.d/rc
 楼主| 发表于 2009-11-10 14:41:39 | 显示全部楼层
还有就是ubuntu特有的/etc/rcS.d
我从rc文件中,没有找到关于这个必须执行的操作,但是
网上提到:
*运行等级 S:开机进程中的第一个运行等级。若/etc/rcS.d 下的链接文件开头子母是大写的,那么它链接的在 /etc/init.d 下的对应脚本将被调用并开启,该进程将被执行。
运行等级 S 就是指的这个这个目录中的文件,
如果相信了解这些启动步骤,请读/sbin/init的源码,这个俺懒得读了。
从我的实验来看,确实是先执行rcS.d然后在执行rc的。
linux的启动过程简介:
bios启动第一个可启动设备
启动grub
启动内核,加载root分区
内核读取/bin/init /sbin/init /usr/bin/init //usr/sbin/init ,这四个文件前面优先,有前面的后面就不管了
所以详细的真是启动过程,应该从init文件读取。
这个文件可以是可执行文件,也可以是shell脚本。当然,从这个文件进一步调用其他可执行文件或者脚本再正常不过了。
 楼主| 发表于 2009-11-10 14:42:50 | 显示全部楼层
所以,估计rcS.d可能就是init读取的执行文件,当然你想修改init强制读取其他文件也没有问题。或者强制不读取某些文件也没问题。
发表于 2009-11-10 17:23:07 | 显示全部楼层
会计什么意思?想表达什么?
发表于 2009-11-10 22:01:21 | 显示全部楼层
ubuntu 不守规范,乱搞,要用正统的发行版,debian
 楼主| 发表于 2009-11-11 13:05:12 | 显示全部楼层

apt-get 错误的解决:用这个文件替换/etc/apt/sources.list

#deb cdrom:[Ubuntu 9.04 _Jaunty Jackalope_ - Release i386 (20090420.1)]/ jaunty main restricted# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to# newer versions of the distribution.deb http://hk.archive.ubuntu.com/ubuntu/ jaunty main restricteddeb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty main restricted## Major bug fix updates produced after the final release of the## distribution.deb http://hk.archive.ubuntu.com/ubuntu/ jaunty-updates main restricteddeb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu## team. Also, please note that software in universe WILL NOT receive any## review or updates from the Ubuntu security team.deb http://hk.archive.ubuntu.com/ubuntu/ jaunty universedeb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty universedeb http://hk.archive.ubuntu.com/ubuntu/ jaunty-updates universedeb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty-updates universe## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu## team, and may not be under a free licence. Please satisfy yourself as to## your rights to use the software. Also, please note that software in## multiverse WILL NOT receive any review or updates from the Ubuntu## security team.deb http://hk.archive.ubuntu.com/ubuntu/ jaunty multiversedeb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty multiversedeb http://hk.archive.ubuntu.com/ubuntu/ jaunty-updates multiversedeb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse## Uncomment the following two lines to add software from the 'backports'## repository.## N.B. software from this repository may not have been tested as## extensively as that contained in the main release, although it includes## newer versions of some applications which may provide useful features.## Also, please note that software in backports WILL NOT receive any review## or updates from the Ubuntu security team.# deb http://hk.archive.ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse# deb-src http://hk.archive.ubuntu.com/ubuntu/ jaunty-backports main restricted universe multiverse## Uncomment the following two lines to add software from Canonical's## 'partner' repository.## This software is not part of Ubuntu, but is offered by Canonical and the## respective vendors as a service to Ubuntu users.# deb http://archive.canonical.com/ubuntu jaunty partner# deb-src http://archive.canonical.com/ubuntu jaunty partnerdeb http://security.ubuntu.com/ubuntu jaunty-security main restricteddeb-src http://security.ubuntu.com/ubuntu jaunty-security main restricteddeb http://security.ubuntu.com/ubuntu jaunty-security universedeb-src http://security.ubuntu.com/ubuntu jaunty-security universedeb http://security.ubuntu.com/ubuntu jaunty-security multiversedeb-src http://security.ubuntu.com/ubuntu jaunty-security multiverse
 楼主| 发表于 2009-11-11 13:05:45 | 显示全部楼层
cn.ubuntun.com有问题。经常连不上,不知道是不是被河蟹了。
发表于 2009-11-11 13:09:21 | 显示全部楼层
会计也用ubuntu了?
发表于 2009-11-11 20:21:53 | 显示全部楼层
装了一个Ubuntu,一直还没用过~
发表于 2009-11-11 20:26:28 | 显示全部楼层
现在的源用的是163的,速度还不错。
 楼主| 发表于 2009-11-11 21:37:57 | 显示全部楼层
地址,给个具体地址。
发表于 2009-11-11 21:53:06 | 显示全部楼层
163 , 台湾的都不错。
发表于 2009-11-11 22:19:30 | 显示全部楼层
163的源:
deb http://mirrors.163.com/ubuntu/ karmic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ karmic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ karmic-backports main restricted universe multiverse
发表于 2009-11-11 22:19:47 | 显示全部楼层
安装刚发行的ubuntu,一般就看看速配指南就行了
http://wiki.ubuntu.org.cn/Qref/Source#.E6.BA.90.E5.88.97.E8.A1.A8
发表于 2009-11-11 22:19:59 | 显示全部楼层
sohu的源:
deb http://mirrors.sohu.com/ubuntu/ karmic main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ karmic-security main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ karmic-updates main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb http://mirrors.sohu.com/ubuntu/ karmic-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ karmic main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ karmic-security main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ karmic-updates main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ karmic-proposed main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ karmic-backports main restricted universe multiverse
发表于 2009-11-12 11:34:26 | 显示全部楼层
看来我要顺应潮流换ubuntu了~~~
发表于 2009-11-12 22:27:39 | 显示全部楼层
linuxsir 那边的老鸟都玩gentoo和archlinux。。。
还记得上课时老师对我们说:你们现在还太粉了所以在玩 linux,和我当年一样,高手玩的是 FreeBSD和OpenBSD...
发表于 2009-11-12 22:38:40 | 显示全部楼层
学到词了,粉……
 楼主| 发表于 2009-11-13 15:22:36 | 显示全部楼层
ubuntu 启动调用的不是inittab,而是/ectc/event.d/rc-default !
可能是修改了init文件吧。没看源码。
花了不少功夫才发现的。


upstart和ubuntu启动过程原理介绍
作者:贝壳汉姆   出处:IT实验室系统管理   2009年10月30日 00:00   进入论坛
相关主题:

    * ubuntu 启动
    * ubuntu 启动项
    * ubuntu 启动顺序
    * ubuntu 启动菜单
    * ubuntu 启动界面
    * ubuntu 开机启动
    * ubuntu u盘启动
    * ubuntu 启动程序
    * ubuntu mysql启动
    * ubuntu 启动ssh

    ubuntu从6.10开始逐步用upstart代替原来的sysinit,进行服务进程的管理。也正是从6.10开始,ubuntu的启动过程开始变得有点“变幻莫测”。也没办法,这是正在开发中的upstart不可避免的。为了对原有的 init实现向后兼容,upstart可以说是在表象上保留了大部分原来init的特性,因而目前linux初始化进程名仍然叫init,而改变的核心,乃是Event机制。理解并讲清楚这个改变的重要意义和内在机理可不是件容易的事,所以我只打算研究一下目前 upstart(0.3.9, ubuntu 8.04)在系统启动中的表象行为。[注:据Scott James Remnant在其博客上所说,upstart 0.5.0版本将在未来几周发布。]

    关于系统启动,熟悉Linux的人大多应该知道,init进程(PID=1)乃是所有进程的父进程,所有进程由它控制。init进程的运行时间是内核完成文件系统的加载后。那么init进程是如何开启系统中的其它进程的呢?在阐述这个问题之前,大致地说明一下目前ubuntu中与init相关的几个目录和应用程序,可以方便后面的论述。这些目录和程序包括:

    init

    telinit

    runlevel

    /etc/event.d/ /etc/init.d/ /etc/rcX.d/

    前三个是应用程序(注意哦,它们都不是shell脚本),可以理解为是由内核调用的。关于它们的功能,从manpage查看就可以了。我们的重点是后面给出的三个目录。

    首先是/etc/event.d/目录,这是upstart的核心,upstart不同于原有的init的地方就在于它引入了event机制。Event 机制通俗的讲就是将所有进程的触发、停止等等都看作event(事件)。/etc/event.d/中就存放了目前upstart需要识别的event。这其中主要有三种rc-default, rcX(x=0,1,...6,S。sysv-rc-conf这个工具里就显示了0,1,...6,S这几个级别)以及ttyX。这rc-default 就类似于那大名鼎鼎的inittab文件,它就是设置默认运行级别的 [注:upstart中实际并没有运行级别的概念,这么称呼是为了init向后的兼容性]。现在你应该知道了ubuntu里没有了inittab文件后该到哪里设置默认运行级别的了吧!cat rc-default一下吧!rcX文件是发生相应运行级别事件(可以注意到event这个词在upstart里真是无处不见啊)时,需要运行程序的脚本,而ttyX则是设置伪终端数目的,也就是你Ctrl+Alt+F(1~6)调出的那个Console。我们以rc2为例,cat rc2:

    start on runlevel 2

    stop on runlevel [!2]

    console output

    script

    set $(runlevel --set 2 || true)

    if [ "$1" != "unknown" ]; then

    PREVLEVEL=$1

    RUNLEVEL=$2

    export PREVLEVEL RUNLEVEL

    fi

    exec /etc/init.d/rc 2

    end script

    ..

    不去考虑细节,只要注意到前两行和倒数第二行就可以了。可以看到,rc2文件是定义在发生运行级别2的时候所要执行的东西,核心就是这句:exec /etc/init.d/rc 2。这样,我们就可以自然地过渡到下一个重要的目录,/etc/init.d/了。

    你可以ls /etc/init.d/看一下里面的内容,对它有个大致的了解。/etc/init.d/中存放的是服务(services)或者任务(tasks)的执行脚本。可以这么说,只要你安装了一个程序(特别是服务程序daemon),它可以在系统启动的时候运行,那么它必定会在/etc/init.d/中有一个脚本文件。我们还回到上面的rc2文件,它执行了一个exec /etc/init.d/rc 2的命令。也就是说,给/etc/init.d/rc脚本传递了一个参数"2",让它执行。我们仔细查看一下rc脚本(很长,耐心点),能看到这样的一段:

    # Now run the START scripts for this runlevel.

    # Run all scripts with the same level in parallel

    ....... for s in /etc/rc$runlevel.d/S* .......

    这说明,当给rc脚本传递一个数字参数"X"的时候,它在经过一系列的设置后,将会开始执行/etc/rcX.d/下S开头的脚本。这就过渡到下一个目录/etc/rcX.d/了。

    进入/etc/rcX.d/,ls -l /etc/rcX.d/看看有些什么内容?哈哈,没错,都是一些到/etc/init.d/中脚本的符号链接。不同的是它们的开头加上了S和一个数字。熟悉原本init的人应该知道,S表示在启动时运行,数字则表示执行的先后顺序。

    这样一来,upstart管理的ubuntu启动过程应该就清楚了。梳理一下:1,内核启动init 2,init找到/etc/event.d/rc-default文件,确定默认的运行级别(X) 3,触发相应的runlevel事件,开始运行/etc/event.d/rcX 4,rcX运行/etc/init.d/rc,传入参数X 5,/etc/init.d/rc脚本进行一系列设置,最后运行相应的/etc/rcX.d/中的脚本6,/etc/rcX.d/中的脚本按事先设定的优先级依次启动,直至最后给出登录画面(启动X服务器和GDM)

    理解了这些,手动配置开机服务的启动与否就很简单了。Ubutnu默认的启动级别是2,不想启动的程序,只要把相应的符号链接从/etc/rc2.d/中删去即可!
 楼主| 发表于 2009-11-13 15:25:02 | 显示全部楼层
现在搞linux,真的觉得容易太多了。网上资料很多,只要知道大概,总能找到。
我记得,俺最初搞的时候,只能自己看英文官方文档。
把程序源码看一遍。现在,会google就行啦。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表