Chinaunix首页 | 论坛 | 博客
  • 博客访问: 333602
  • 博文数量: 107
  • 博客积分: 2825
  • 博客等级: 少校
  • 技术积分: 795
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-19 12:19
文章分类

全部博文(107)

文章存档

2013年(2)

2012年(31)

2011年(18)

2010年(12)

2009年(44)

我的朋友

分类: LINUX

2009-10-28 06:32:28

简单总结
1 启动过程
init 进程通过/etc/inittab来决定启动的顺序和工作流程 init会执行所有/etc/runlevels/boot目录下的符号链接所指向的/etc/init.d目录下的脚本, 当/etc/runlevels/boot目录所引用的脚本都执行完毕后,将继续运行/etc/runlevels/default目录下的符号链接所指向的脚本
   相关说明
在inittab有运行级别的定义
l1:S1:wait:/sbin/rc single     
l2:2:wait:/sbin/rc nonetwork
l3:3:wait:/sbin/rc default      
l4:4:wait:/sbin/rc default      
l5:5:wait:/sbin/rc default      
l6:6:wait:/sbin/rc reboot       

下面的定义si::sysinit:/sbin/rc sysinit这是init进程将初始化交给rc  由/sbin/rc sysinit来初始化系统,/sbin/rc脚本是负责系统初始化的在rc::bootwait:/sbin/rc boot中
rc脚本的参数(boot)和要用的/etc/runlevels的子目录是一样的。
rc 执行完了以后 init将会决定哪些虚拟终端需要被激活以及每个终端需要运行什么样的命令:
在inittab中有以下定义
c1:12345:respawn:/sbin/agetty 38400 tty1 linuxc2:12345:respawn:/sbin/agetty 38400 tty2 linuxc3:12345:respawn:/sbin/agetty 38400 tty3 linuxc4:12345:respawn:/sbin/agetty 38400 tty4 linuxc5:12345:respawn:/sbin/agetty 38400 tty5 linuxc6:12345:respawn:/sbin/agetty 38400 tty6 linux这段代码定义了当运行在某个运行级别上的时候哪些虚拟终端需要被激活以及每个终端需要运行什么样的命令
 2 启动服务和调整
/etc/init.d/xxxx status 查看服务运行状态     /etc/init.d/xxxx zap    手动把信息设置为停止/etc/init.d/xxxx ineed  查看依赖服务/etc/init.d/xxxx needsme哪些服务需要这个服务(needsme)或者哪些服务可以使用这个服务(usesme)rc-update add xxx default 添加服务到default 级别rc-update del xxx default 删除服务rc-update -v show 命令将会显示出所有已存在的初始化脚本,并列出它们在哪个运行级别中运行增加独立的额外配置 这样做的好处是重装某个软件后不会覆盖自己的配置gentoo的配置是在/etc/conf.dgentoo官方文档的参考
首先,你的引导程序会把你在引导程序配置文件中定义的内核镜像加载到内存中,之后它就告诉CPU可以运行内核了。当内核被加载且运行后,内核会初始化所有内核专有的结构体和任务,并开启init进程。
然后,这个进程确保所有的文件系统(在/etc/fstab中定义的)都已被挂载且能使用。接着,该进程会执行位于/etc/init.d下的一些脚本,这些脚本会启动一些你需要的服务,以使你能获得一个成功启动的系统。
最终,当所有的脚本执行完毕,init将激活终端(大多情况下只是激活虚拟终端,可以使用Alt-F1、Alt-F2等来访问),并把一个叫agetty的特殊进程附于其上。这个进程会确保你可以通过运行login从这些终端登录到你的系统中。
 gentoo不会随机的执行/etc/init.d下的脚本。甚至,它不会运行/etc/init.d下所有的脚本,只会去执行/etc/runlevels 下的

init会运行所有/etc/runlevels/boot目录下的符号链接所指向的/etc/init.d目录下的脚本。通常,它会按照字母顺序执行这些脚本,但是有些脚本中含有依赖关系,意味着系统要在执行另一个脚本之后才能运行此脚本。
当/etc/runlevels/boot目录所引用的脚本都执行完毕后,init将继续运行/etc/runlevels/default目录下的符号链接所指向的脚本。同样它们会按照字母顺序执行这些脚本,除非一个脚本有依赖关系,那样的话现有次序就会被改变以使启动顺序更加合理。
当然init自己不会决定所有的启动顺序。它需要一个配置文件来指定它的工作流程。这个配置文件就是/etc/inittab。
如果你还记得我们刚刚描述的启动顺序,你会记得init首先做的是挂载所有的文件系统。这个功能其实是在/etc/inittab这个配置文件中定义好的。如下:
si::sysinit:/sbin/rc sysinit这一行告诉init必须运行/sbin/rc sysinit来初始化系统。/sbin/rc脚本是负责系统初始化的,所以你可能会说init它本身并没做太多的事情——它只是把初始化系统任务交给了另一个进程。
接下来,init会执行所有在/etc/runlevels/boot目录下的具有符号链接的脚本。这是由下面这行定义的:
rc::bootwait:/sbin/rc boot什么是运行级别
已经看到init使用一种数字的方式来决定需要激活的运行级别。运行级别表示你系统运行的状态,它包含了你进入或退出一个运行级别时需要执行的一组脚本(运行级别脚本或者初始化脚本)。
在Gentoo中定义了七种运行级别:三个内部运行级别和四个用户自定义运行级别。这些内部运行级别分别叫做sysinit、shutdown和reboot,它们所做的就如同像它们的名字那样:初始化系统、关闭系统和重启系统。
用户定义的运行级别都在/etc/runlevels目录下有同名的子目录:boot、default、nonetwork和single。运行级别boot会启动所有其他运行级别必须要使用到的系统服务。其余的三个运行级别的不同之处主要在于它们要启动的服务:default是用来日常工作用的;nonetwork是在无网络的情况下使用的;还有single是用户修复系统时用的。
使用初始化脚本
实际上rc进程调用的脚本都称为初始化脚本。每个在/etc/init.d下的脚本都可以在执行时带上以下参数,如:start、stop、restart、pause、zap、status、ineed、iuse、needsme、usesme或者broken。
要启动、停止或者重启一个服务(和所有依赖于它的服务),应该用参数
start
stop
restart
如果状态信息告诉你服务正在运行,但是你知道它实际上没有运行,这种情况下你可以使用参数zap将状态信息重设为“停止” Gentoo的初始化系统使用依赖关系树(dependency-tree)来决定什么服务会首先被启动。因为这是个很乏味的工作,我们不想让我们的用户去手动来完成它,所以我们创建了简化运行级别和初始化脚本的管理工具(rc-update)。
使用rc-update你可以从一个运行级别中添加或删除初始化脚本。rc-update工具会自动调用/sbin/depscan.sh脚本来重新创建依赖关系树。
添加和删除服务
在Gentoo的安装过程中你已经添加初始化脚本到“default”运行级别。那时你可能还不清楚“default”是干什么的,但是现在你应该知道了。rc-update脚本需要由第二个参数来决定其行为:add、del或者是show。
要添加或删除一个初始化脚本,只需要给rc-update add或者del参数,并随后跟上初始化脚本和运行级别。如下:
代码 2.1: 从default级别中删除Postfix服务
 
# rc-update del postfix default
rc-update -v show命令将会显示出所有已存在的初始化脚本,并列出它们在哪个运行级别中运行:
代码 2.2: 获得初始化脚本的信息
 
# rc-update -v show
你也可以运行rc-update show(没有-v参数)来只查看已经启用的初始化脚本和他们的运行级别。
*************************************************************************
启动时挂载设备 文件系统
*************************************************************************
/etc/fstab
一个例子说明
/dev/sda1        /boot   ext3    defaults                1 2
/dev/sda2        none            swap            sw              0 0
/dev/sda3        /       ext3    defaults                0 1
none        /proc     proc    defaults          0 0
none        /dev/shm  tmpfs   defaults          0 0
 

1. 需要挂载的设备或者文件系统
       The first field, (fs_spec), describes the block special device or remote filesystem to be mounted.
       For ordinary mounts it will hold (a link to) a block special device node (as created by mknod(8)) for the device to  be  mounted,  like  `/dev/cdrom'  or  `/dev/sdb7'.  For NFS mounts one will have :, e.g., `knuth.aeb.nl:/'.  For procfs, use `proc'.
2. 没啥说的挂载点 注意swap等
       The second field, (fs_file), describes the mount point for the filesystem.  For swap partitions, this field should be specified as `none'. If the name of  the mount point contains spaces these can be escaped as `\040'.
3. 文件系统的格式
        The third field, (fs_vfstype), describes the type of the filesystem.  Linux supports lots of filesystem types, such as adfs, affs, autofs,  coda,  coher-ent, cramfs, devpts, efs, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, ntfs, proc, qnx4, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs,umsdos, vfat, xenix, xfs, and possibly others. For more details, see mount(8).  For the filesystems  currently  supported  by  the  running  kernel,  see /proc/filesystems.   An  entry  swap  denotes a file or partition to be used for swapping, cf. swapon(8).  An entry ignore causes the line to be ignored.This is useful to show disk partitions which are currently unused.
4. 挂载之后的访问状态
        The fourth field, (fs_mntops), describes the mount options associated with the filesystem.

        It is formatted as a comma separated list of options.  It contains at least the type of mount plus any additional options appropriate to  the  filesystem type.   For  documentation on the available options for non-nfs file systems, see mount(8).  For documentation on all nfs-specific options have a look at nfs(5).  Common for all types of file system are the options ``noauto'' (do not mount when "mount -a" is given, e.g., at boot time),  ``user''  (allow  a user  to  mount),  and  ``owner'' (allow device owner to mount), and ``comment'' (e.g., for use by fstab-maintaining programs).  The ``owner'' and ``com-ment'' options are Linux-specific.  For more details, see mount(8).
5. 提供DUMP功能,在系统DUMP时是否需要BACKUP的标志位,其内定值是0。
        The fifth field, (fs_freq), is used for these filesystems by the dump(8) command to determine which filesystems need to be dumped.  If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped.
6. 设定此filesystem是否要在开机时做check的动作,除了root的filesystem其必要的check为1之外,其它皆可视需要设定,内定值是0
          The  sixth  field,  (fs_passno),  is  used  by  the  fsck(8) program to determine the order in which filesystem checks are done at reboot time.  The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2.  Filesystems within a  drive  will  be  checked sequentially,  but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware.  If the sixth field  is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked.
 
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/RainyTooo/archive/2008/08/07/2782144.aspx
阅读(1330) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~