蓝海战略演讲:linux系统启动脚本

来源:百度文库 编辑:九乡新闻网 时间:2024/04/30 17:48:38
  When you boot your computer, the first thing that it will do is load the bootloader -- either GRUB or LILO in most cases. The bootloader will then load the Linux kernel -- the core operating system. Next, a process called init starts. This process reads the file /etc/inittab to establish the runlevel to use. The runlevel is the start mode for the computer.
    Once init knows the runlevel it will look for the appropriate files or directories as defined in /etc/initab.
    Init will then either run the script files defined by /etc/initab, or run the script files in the directories defined by /etc/initab (depending on the set up of your system).
    Finally, init will present you with the logon mode that you've selected.
  Fedora 下是有/etc/inittab文件的,而在Ubuntu中是没有这一个文件的,因为在ubuntu中,inittab软件包已经被upstart软件包替换了,所有的配置信息都在/etc/event.d/目录下。inittab文件在inittab里面这样描述的,This inittab file describes how the INIT process should set up the system in a certain run-level.即在linux启动时,会运行一个init程序,然后由它启动后面的任务,包括用户环境,网络等。到底什么是运行级呢?简单的说,运行级就是操作系统当前正在运行的功能级别。这个级别从1 到6 ,具有不同的功能。这些级别在/etc/inittab(在Fedora下是这样,别的发行版中不可能存在这个文件) 文件里指定。这个文件是init程序寻找的主要文件,最先运行的服务是那些放在/etc/rc.d(Fedora下有这个目录,其他Linux发行版中不一定有些目录) 目录下的文件。
   Fedora(8.0)在/etc目录下有一个rc.d目录,里面有rcn.d目录(n代表从1-6的数字),init.d目录,还有三个脚本rc.local,rc,rc.sysinit.
而/etc目录下的 rc,rc0.d/,rc1.d/,rc2.d/,rc3.d/,rc4.d/,rc5.d/,rc6.d/,rc.local,rc.sysinit 均是到/etc/rc.d目录下的软链接。
   Ubuntu(7.10)下/etc目录下没有rc.d目录,/etc目录下直接存放着rc0.d/,rc1.d/,rc2.d/,rc3.d/,rc4.d/,rc5.d/,rc6.d/,rc.local,rcS.d/,init.d/
    其中,在init.d目录下存放着一些系统启动脚本。rc*.d目录下都是一些到/etc/init.d目录下的软链接。
   rc后面的数字,不言而明,其实是代表系统的runlevel,由于Linux的发行版本众多,所以数字级别在不同的发行版里所代表含义不一样,如需更改你的linux发行版,务必先仔细阅读自己所用linux版本的发行文档。比如,Fedora 的runlevel 3是无GUI的多用户模式,而UBUNTU的2才是多用户模式,且在Server版本里2是默认启动级别。
   rc.local只运行一次,仅在系统启动时.它是在系统里其他脚本已经运行完毕,在登录提示符出现前运行.在Debian里是不用rc.local里作启动脚本的.Ubuntu中的rc3.d目录下的S99rc.local是到/etc/init.d/rc.local的软链接.而/etc/下的rc.local文件是一个空文件.Fedora下的/etc/rc3.d/SSlocal是到/etc/rc.local文件的链接.
    改变运行级别(runlevel)和系统启动什么服务,更改rc.local这样的脚本,手动更改配置文件是可以的,但手动改写不是必要的.在Fedora中有chkconfig命令,在Debian中有update-rc.d命令能帮我们做这些事.
  
    通过了解这些文件,我们能够增加自己需要的服务,检查自己不需要的系统启动项,还有拖慢系统,或者让系统负载的Services.还能清楚是否有危险用户增加可怕脚本到init.d,rc.d目录中.