歡迎您光臨本站 註冊首頁

gentoo系統啟動初始化

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

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官方文檔的參考www.gentoo.org/doc/zh_cn/handbook/handbook-x86.xml首先,你的引導程序會把你在引導程序配置文件中定義的內核鏡像載入到內存中,之後它就告訴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 <host>:<dir>, 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 `40'.

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


[火星人 ] gentoo系統啟動初始化已經有612次圍觀

http://coctec.com/docs/linux/show-post-52425.html