歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Slackware的啟動(init)過程

Slackware的啟動(init)過程

日期:2017/3/3 16:43:52   编辑:關於Linux

導言

在一次IBM於阿姆斯特丹舉辦的Linux研討會上,一位老師提出以下說法:“啟動是Linux最難的部分。但是,一旦內核已經載入,並由init接管之後,你就暢行無阻了。從那個時刻起,所有發生的事情你都可以在腳本和文檔(man page)裡面讀到。”

他當然是對的。在啟動Linux機器的過程中沒有什麼秘密。你能在ASCII文件中讀到所有東西。但是,在跟蹤這些腳本的過程中也很容易迷路。Slackware與別的發行版不同之處在於它堅持用BSD風格的啟動過程,而不是像它們那樣用Sys V的啟動過程。

在Sys V的啟動系統中,所有起動/停止的腳本都放在 /etc/rc.d目錄中。在每一個運行級(runlevel)都有一個目錄(即 /etc/rc.1, /etc/rc.2 等等),其中全是該運行級所需運行腳本的鏈接。當進入一個運行級時,有一個大的腳本來處理這些鏈接以起動(或停止)該運行級的服務。

Sys V啟動過程用在Redhat、Suse中,我將把解釋它的事留給用這類系統的人。沒有實際使用它的機器,我恐怕很快會在細節上暈頭轉向。

Slackware的用戶(Slackers)多數認為Sys V啟動過程既復雜又難於維護。老實說,Redhat和Suse用戶的想法正好相反。不過,先跟著我,然後你自己作出判斷。

在本文檔中,我將試著證明IBM的老師是正確的。我將循著Slackware(8.1)的啟動過程,用腳本和man page作為指導。會引用很多,而較少(我自己的)文字。

又及:你可能注意到,英語不是我的母語。我會盡量經常地用拼寫檢查程序,但它在語法方面的用處不大。無論在內容或語法方面的錯誤,請不吝賜教。此外,我非常喜歡大家對我寫的東西提出看法。

運行級(runlevel)

我們會很多次談到運行級,所以現在是個好機會來解釋一下運行級。運行級是決定某機器的服務等級的*nix方式。在每個運行級中,人們可以定義哪些服務要激活、哪些不用。原則上,可以有很多運行級。實際上,只有5個:

單用戶運行級,只有最少的服務在運行。這個運行級經常用於系統維護。

多用戶運行級,所有提供的服務都在運行。這些服務可能是諸如HTTP服務器、電子郵件服務器、SQL服務器之類。正是系統管理員(你)所需要的。

多用戶運行級,和前面一樣,但這次有個圖形界面的登陸管理器。

多用戶運行級之一就是機器正常的運行狀態。你可以決定另外的運行級。例如,用於遠程維護的有網絡支持的單用戶運行級。

上述運行級之外,還有兩個特殊的運行級:

停止系統(halt)的運行級。

重新啟動(reboot)的運行級。

Init

假如我想用樹狀圖表示我機器上所有的進程,我可能會得到這樣的結果:

bilbo@bilbo:~$ pstree
init-+-4*[agetty]
  |-atd
  |-bash
  |-bash---startx---xinit-+-X
  | `-xinitrc-+-bbmail
  | `-blackbox-+-mozilla-bin---mozilla-bin---4+
  | `-rxvt---bash---pstree
  |-crond
  |-dhcpcd
  |-fetchmail
  |-gpm
  |-gvim
  |-httpd---7*[httpd]
  |-inetd---in.identd---in.identd---5*[in.identd]
  |-keventd
  |-khubd
  |-klogd
  |-kreiserfsd
  |-loop0
  |-loop1
  |-lpd
  |-mdrecoveryd
  |-named
  |-2*[sendmail]
  `-syslogd
bilbo@bilbo:~$

pstree命令顯示我機器上運行的進程的樹狀圖,看起來有點像目錄結構。最引人注目(至少在我看來)的是,樹狀圖的“根”是“init”。從init派生出所有其他進程。這並非偶然。

來自manpage文檔:

INIT(8) Linux System Administrator's Manual INIT(8)
NAME
  init, telinit - process control initialization
SYNOPSIS
  /sbin/init [ -a ] [ -s ] [ -b ] [ -z xxx ] [ 0123456Ss ]
  /sbin/telinit [ -t sec ] [ 0123456sSQqabcUu ]
DESCRIPTION
  Init
  Init is the parent of all processes. Its primary role is
  to create processes from a script stored in the file
  /etc/inittab (see inittab(5)). This file usually has
  entries which cause init to spawn gettys on each line that
  users can log in. It also controls autonomous processes
  required by any particular system.

有幾個值得注意的要點:

init派生所有進程(Init is the parent of all processes.)

init從文件 /etc/inittab中啟動進程

init控制所有獨立的進程

在上面的樹狀圖中,你能看到那些獨立的進程。它們都是init的直系後代,舉幾個例子:agetty(4個)、sendmail(2個)、lpd和syslogd。

但為什麼init是“所有進程之母”,看看manpage:

BOOTING
  After init is invoked as the last step of the kernel boot
  sequence, it looks for the file /etc/inittab to see if there is an
  entry of the type initdefault (see inittab(5)). The initdefault
  entry determines the initial runlevel of the system. If there is
  no such entry (or no /etc/inittab at all), a runlevel must be
  entered at the system console.

可見內核(kernel)啟動時所做的最後一件事就是啟動init。init接著按 /etc/inittab的規定做事。

init的manpage給出了更多的信息,但對我們來說也許該看看/etc/inittab了。它似乎是個非常重要的文件。

來自manpage:

INITTAB(5) Linux System Administrator's Manual INITTAB(5)
NAME
  inittab - format of the inittab file used by the sysv-compatible
  init process
DESCRIPTION
  The inittab file describes which processes are started at bootup
  and during normal operation (e.g. /etc/init.d/boot,
  /etc/init.d/rc, gettys...). Init(8) distinguishes multiple run-
  levels, each of which can have its own set of processes that are
  started. Valid runlevels are 0-6 plus A, B, and C for ondemand
  entries. An entry in the inittab file has the following format:
       id:runlevels:action:process

啊哈,令人吃驚!它說:“用於與sysv兼容的init進程”。這是Slackware嗎?沒錯,Slackware確實是用Sys V的init。純粹為了開心,我們看看Slackware的軟件包說明:

bilbo@bilbo:~$ head -n 14 /var/log/packages/sysvinit-2.84-i386-18
PACKAGE NAME: sysvinit-2.84-i386-18
COMPRESSED PACKAGE SIZE: 232 K
UNCOMPRESSED PACKAGE SIZE: 560 K
PACKAGE LOCATION: /var/log/mount/slackware/a/sysvinit-2.84-i386-18.tgz
PACKAGE DESCRIPTION:
sysvinit: sysvinit (init, the parent of all processes)
sysvinit:
sysvinit: System V style init programs by Miquel van Smoorenburg that control
sysvinit: the booting and shutdown of your system. These support a number of
sysvinit: system runlevels, each with a specific set of utilities spawned.
sysvinit: For example, the normal system runlevel is 3, which starts agetty
sysvinit: on virtual consoles tty1 - tty6. Runlevel 4 starts xdm.
sysvinit: Runlevel 0 shuts the system down.
sysvinit:
bilbo@bilbo:~$

所以不要聽信別人說Slackware不用Sys V的init,不過它是按BSD風格來用。

inittab

玩夠了......讓我們看看 /etc/inittab 的格式。同樣來自manpage:

       id:runlevels:action:process
Lines beginning with `#' are ignored.
id is a unique sequence of 1-4 characters which iden-
tifies an entry in inittab (for versions of
sysvinit compiled with libraries < 5.2.18 or a.out
libraries the limit is 2 characters).
Note: For gettys or other login processes, the id
field should be the tty suffix of the corresponding
tty, e.g. 1 for tty1. Otherwise, the login
accounting might not work correctly.
runlevels
lists the runlevels for which the specified action
should be taken.
action describes which action should be taken.
process
specifies the process to be executed. If the pro-
cess field starts with a `+' character, init will
not do utmp and wtmp accounting for that process.
This is needed for gettys that insist on doing
their own utmp/wtmp housekeeping. This is also a
historic bug.

組成這個文件的每行都有4個部分,用“:”分隔開

id - 該行的標識

runlevels - 該行為應該發生的運行級的列表

action - 應發生的行為,你能在inittab的manpage裡面發現對它們的概述。我將在適當的時候引用。

process - 應由init啟動的進程。

復雜嗎?還不是那麼壞吧,這是我的 /etc/inittab:

bilbo@bilbo:~$ cat /etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Version: @(#)inittab 2.04 17/05/93 MvS
# 2.10 02/10/95 PV
# 3.00 02/06/1999 PV
# 4.00 04/10/2002 PV
#
# Author: Miquel van Smoorenburg, <[email protected]>
# Modified by: Patrick J. Volkerding, <[email protected]>
#
# These are the default runlevels in Slackware:
# 0 = halt
# 1 = single user mode
# 2 = unused (but configured the same as runlevel 3)
# 3 = multiuser mode (default Slackware runlevel)
# 4 = X11 with KDM/GDM/XDM (session managers)
# 5 = unused (but configured the same as runlevel 3)
# 6 = reboot
# Default runlevel. (Do not set to 0 or 6)
id:3:initdefault:
# System initialization (runs when system boots).
si:S:sysinit:/etc/rc.d/rc.S
# Script to run when going single user (runlevel 1).
su:1S:wait:/etc/rc.d/rc.K
# Script to run when going multi user.
rc:2345:wait:/etc/rc.d/rc.M
# What to do at the "Three Finger Salute".
ca::ctrlaltdel:/sbin/shutdown -t5 -r now
# Runlevel 0 halts the system.
l0:0:wait:/etc/rc.d/rc.0
# Runlevel 6 reboots the system.
l6:6:wait:/etc/rc.d/rc.6
# What to do when power fails.
pf::powerfail:/sbin/genpowerfail start
# If power is back, cancel the running shutdown.
pg::powerokwait:/sbin/genpowerfail stop
# These are the standard console login getties in multiuser mode:
c1:1235:respawn:/sbin/agetty 38400 tty1 linux
c2:1235:respawn:/sbin/agetty 38400 tty2 linux
c3:1235:respawn:/sbin/agetty 38400 tty3 linux
c4:1235:respawn:/sbin/agetty 38400 tty4 linux
c5:1235:respawn:/sbin/agetty 38400 tty5 linux
c6:12345:respawn:/sbin/agetty 38400 tty6 linux
# Local serial lines:
#s1:12345:respawn:/sbin/agetty -L ttyS0 9600 vt100
#s2:12345:respawn:/sbin/agetty -L ttyS1 9600 vt100
# Dialup lines:
#d1:12345:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS0 vt100
#d2:12345:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS1 vt100
# Runlevel 4 used to be for an X window only system, until we discovered
# that it throws init into a loop that keeps your load avg at least 1 all
# the time. Thus, there is now one getty opened on tty6. Hopefully no one
# will notice. ;^)
# It might not be bad to have one text console anyway, in case something
# happens to X.
x1:4:wait:/etc/rc.d/rc.4
# End of /etc/inittab
bilbo@bilbo:~$

只有74行文字(僅約一張A4紙的篇幅),如果你把那些注釋去掉,將只剩下16行。但你將學到那些注釋很值得讀一讀。

讓我們開始把/etc/inittab拆開:

# Author: Miquel van Smoorenburg, <[email protected]>
# Modified by: Patrick J. Volkerding, <[email protected]>

這個文件的最後版本是由Miquel van Smoorenburg(聽起來像德國人)制作的,然後由Patrick J. Volkerding(Slackware的維護者,對,Slackware是一個人的工作)為了用於Slackware而作了修改。這個注釋沒有太大作用,但它確實在那裡。我們把它當作GPL的實例好了。

# These are the default runlevels in Slackware:
# 0 = halt
# 1 = single user mode
# 2 = unused (but configured the same as runlevel 3)
# 3 = multiuser mode (default Slackware runlevel)
# 4 = X11 with KDM/GDM/XDM (session managers)
# 5 = unused (but configured the same as runlevel 3)
# 6 = reboot

又是一些注釋,當然它什麼事都不做,但它讓接下來的事情清晰了很多。你看到的是對Slackware用到的7個運行級的描述。運行級2和5都沒有用到,往後你會看到它們和運行級3用同樣的腳本。

# Default runlevel. (Do not set to 0 or 6)
id:3:initdefault:

終於要做些事情了。它是一個正常的inittab行,4個部分用“:”隔開。在這裡的行為是“initdefault”,按照manpage的說法:

initdefault
       An initdefault entry specifies the runlevel which should
be entered after system boot.
If none exists, init will ask for a runlevel on the console.
The process field is ignored.

在這裡定義了缺省的運行級,當然注釋就是這麼說的。因此,Slackware缺省的運行級是3,用控制台/文本登錄的多用戶運行級。

假如系統啟動時,Slackware沒有接到進入其他運行級的信號(例如"telinit 1"這類命令),它就會進入這個運行級。

# System initialization (runs when system boots).
si:S:sysinit:/etc/rc.d/rc.S

這裡的行為是“sysinit”(系統初始化),意思很明顯,但我們還是看看manpage:

sysinit
  The process will be executed during system boot.
It will be executed before any boot or bootwait
entries. The runlevels field is ignored.

雖然這裡指明了運行級S,但實際上被忽略了。將執行的程序是/etc/rc.d/rc.S,是個腳本。你會看到Slackware所有的啟動腳本都在/etc/rc.d。在/etc/rc.d/rc.S裡,系統將被初始化,我們接下來討論這個腳本時就會看到。

# Script to run when going single user (runlevel 1).
su:1S:wait:/etc/rc.d/rc.K

這裡的行為是wait:

wait The process will be started once when the specified
        runlevel is entered and init will wait for its
        termination.

其中定義的腳本將在進入運行級1和S(意思是single)時被調用。“wait”行為將使init保留所有其他的動作直至/etc/rc.d/rc.K執行完畢。/etc/rc.d/rc.K啟動了單用戶運行級所需的服務,遲一點你會看到那不算很多。

# Script to run when going multi user.
rc:2345:wait:/etc/rc.d/rc.M

在這裡的行為還是wait。這裡定義了運行級2、3、4、5都調用/etc/rc.d/rc.M,基本上是除了運行級1之外的所有“常規”的運行級。一會兒我們會看到那是個怎樣的腳本。

目前為止我們所看到的行是用來定義系統啟動之後所發生的事。在所有情況下,init都會等到它啟動的進程(腳本)終止。下面的幾行是init在特殊情況下應做的事,而且不屬於任何特定的運行級。

# What to do at the "Three Finger Salute".
ca::ctrlaltdel:/sbin/shutdown -t5 -r now

不單微軟知道所謂的“三指禮”(譯注:ctrl-alt-del),在Linux中你也能決定它出現時該做什麼。下面是init的manpage中關於這個行為的條目:

ctrlaltdel
       The process will be executed when init receives the SIGINT
signal. This means that someone on the system console has
pressed the CTRL-ALT-DEL key combination. Typically one wants
to execute some sort of shutdown either to get into
single-user level or to reboot the machine.

在Slackware的系統上,將會執行 /sbin/shutdown -t5 -r now 。

SHUTDOWN(8) Linux System Administrator's Manual SHUTDOWN(8)
NAME
  shutdown - bring the system down
SYNOPSIS
  /sbin/shutdown [-t sec] [-arkhncfF] time [warning-message]
DESCRIPTION
  shutdown brings the system down in a secure way. All
  logged-in users are notified that the system is going
  down, and login(1) is blocked. It is possible to shut the
  system down immediately or after a specified delay. All
  processes are first notified that the system is going down
  by the signal SIGTERM. This gives programs like vi(1) the
  time to save the file being edited, mail and news process-
  ing programs a chance to exit cleanly, etc. shutdown does
  its job by signalling the init process, asking it to
  change the runlevel. Runlevel 0 is used to halt the sys-
  tem, runlevel 6 is used to reboot the system, and runlevel
  1 is used to put to system into a state where administra-
  tive tasks can be performed; this is the default if nei-
  ther the -h or -r flag is given to shutdown. To see which
  actions are taken on halt or reboot see the appropriate
  entries for these runlevels in the file /etc/inittab.

參數 -r 的意思是重新啟動(reboot),做法是給init進入運行級6的信號。延遲時間是從現在開始5秒。如果你有保持運行時間的癖好(uptime junkie),你可以讓“三指禮”做完全不同的事情,並有效地迫使用戶明確給出shutdown命令。(假如你有個NT類系統和Linux共存的服務器群,取消ctrl-alt-del的功能並不是一件壞事。)

當然第2部分(譯注:指定運行級)就不必要了,init是對外界信號作出反應。

# Runlevel 0 halts the system.
l0:0:wait:/etc/rc.d/rc.0

這裡的行為又是wait,因此init又會等待腳本執行完畢。進入運行級0後,init將執行 /etc/rc.d/rc.0 (最後是零)。這個腳本所做的是讓所有啟動了的進程安全地停止。不是所有的程序都喜歡你直接拔出插頭的。作為最後的行動,它將調用poweroff來關閉系統或通知用戶可以拔插頭了。

# Runlevel 6 reboots the system.
l6:6:wait:/etc/rc.d/rc.6

這一行與上面那行非常像,事實上 /etc/rc.d/rc.0 是指向 /etc/rc.d/rc.6的符號鏈接,兩個腳本其實是同一個。腳本的調用方式決定了最後一步會怎麼做。在運行級6中,最後的命令將是reboot。

# What to do when power fails.
pf::powerfail:/sbin/genpowerfail start
# If power is back, cancel the running shutdown.
pg::powerokwait:/sbin/genpowerfail stop

這兩行的命令要合在一起說,因為它們有很多相關性。它們的行為是:

powerwait
  The process will be executed when the power goes
down. Init is usually informed about this by a pro-
cess talking to a UPS connected to the computer.
Init will wait for the process to finish before
continuing.
  powerfail
  As for powerwait, except that init does not wait
for the process's completion.
  powerokwait
  This process will be executed as soon as init is
  informormed that the power has been restored.

這兩行都是電力中斷(或實際上是UPS電量耗盡)時該做的事情。

/sbin/genpowerfail start由關閉系統開始,/sbin/genpowerfail stop則試圖在電力恢復時中斷關機的行為。你可能注意到用start參數時並不會等腳本執行完畢,假如等了,就不可能中斷關機的過程。 /sbin/genpowerfail是個使用shutdown命令的腳本,假如你有UPS你應該讀一讀這個腳本。

我們現在已經到了系統將要運行的關頭。系統初始化的腳本已經執行了,缺省運行級的腳本也已經執行了- 單用戶運行級是/etc/rc.d/rc.K,多用戶運行級2、3、4、5執行的是/etc/rc.d/rc.M;所有需要的後台服務也在運行。在多用戶運行級中,假如在/etc/rc.d/rc.M中啟動了telnet和ssh服務,用戶已經可以用這些方式登錄系統了。假如你的系統是一個沒有顯示器和鍵盤的服務器,你讓它這麼待著就行了。

目前還不可能做到的是從控制台登錄,有時能從控制台登錄是會很方便的。init的下一個任務就是控制台登錄。

# These are the standard console login getties in multiuser mode:
c1:1235:respawn:/sbin/agetty 38400 tty1 linux
c2:1235:respawn:/sbin/agetty 38400 tty2 linux
c3:1235:respawn:/sbin/agetty 38400 tty3 linux
c4:1235:respawn:/sbin/agetty 38400 tty4 linux
c5:1235:respawn:/sbin/agetty 38400 tty5 linux
c6:12345:respawn:/sbin/agetty 38400 tty6 linux

馬上我們有了個新的行為,在inittab的manpage裡:

respawn
  The process will be restarted whenever it termi-
nates (e.g. getty).

因此,已經啟動的進程/sbin/agetty若被終止了,會重新運行。很明顯,為運行級1、2、3和5啟動了tty1至tty6的虛擬控制台。這些都是沒有X的運行級。例外的是tty6上運行的agetty也將在運行級4(有X的運行級)啟動。

agetty的manpage讓我們了解到agetty的實際行為:

AGETTY(8) AGETTY(8)
NAME
  agetty - alternative Linux getty
  SYNOPSIS
       agetty [-ihLmnw] [-f issue_file] [-l login_program] [-I
init] [-t timeout] [-H login_host] port baud_rate,...
[term]
agetty [-ihLmnw] [-f issue_file] [-l login_program] [-I
init] [-t timeout] [-H login_host] baud_rate,... port
[term]
  DESCRIPTION
       agetty opens a tty port, prompts for a login name and
       invokes the /bin/login command. It is normally invoked by
       init(8).

可見,agetty在一個tty的端口等待用戶登錄,然後將運行/bin/login。

LOGIN(1) LOGIN(1)
NAME
  login - begin session on the system
  SYNOPSIS
       login [-p] [username] [ENV=VAR ...]
login [-p] [-h host] [-f username]
login [-p] -r host
  DESCRIPTION
       login is used to establish a new session with the system.
       It is normally invoked automatically by responding to the
       login: prompt on the user's terminal. login may be spe-
       cial to the shell and may not be invoked as a sub-process.
       Typically, login is treated by the shell as exec login
       which causes the user to exit from the current shell.
       Attempting to execute login from any shell but the login
       shell will produce an error message.

login在系統上啟動了一個新的會話。讓我們回頭看看pstree的輸出:

bilbo@bilbo:~$ pstree
init-+-4*[agetty]
  |-atd
  |-bash
  |-bash---startx---xinit-+-X
  | `-xinitrc-+-bbmail
  | `-blackbox-+-mozilla-bin---mozilla-bin---4+
  | `-rxvt---bash---pstree

該死!不是應該有6個agetty嗎?呃,對,曾經確實是有6個。但很顯然,我從虛擬控制台登錄了兩次,有一次沒有運行其他的程序,另一次運行了startx,變成了X會話。

當我logout的時候agetty會重新運行,還記得respawn嗎?有趣的是,假如agetty啟動得更早,會不會多個用戶通過同一個虛擬控制台登錄呢?

*nix總是提供了與系統聯系的多種途徑,我們已經知道了其中的2種:

通過網絡,用telnet、ssh之類工具

通過直接連接到系統的鍵盤、顯示器和鼠標

但是,*nix還有其他途徑與系統聯系:

# Local serial lines:
#s1:12345:respawn:/sbin/agetty -L ttyS0 9600 vt100
#s2:12345:respawn:/sbin/agetty -L ttyS1 9600 vt100
# Dialup lines:
#d1:12345:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS0 vt100
#d2:12345:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS1 vt100

上面兩段為串行線路啟動agetty,用於串口連接的終端或者用modem撥號進入。

你可以看到,它們缺省情況是被注釋掉的。但一旦你需要使用古老的VT類終端或撥號進入系統,你就要用到這些代碼。

在最後,要由X來給我們提供一個圖形界面的運行級:

# Runlevel 4 used to be for an X window only system, until we discovered
# that it throws init into a loop that keeps your load avg at least 1 all
# the time. Thus, there is now one getty opened on tty6. Hopefully no one
# will notice. ;^)
# It might not be bad to have one text console anyway, in case something
# happens to X.
x1:4:wait:/etc/rc.d/rc.4

注釋首先解釋了為運行級4在tty6留下一個getty的原因。行為是wait,執行/etc/rc.d/rc.4。這個腳本將依次搜索kdm(kde的登錄管理器)、gdm(gnome的登錄管理器),最後是xdm(缺省的X登錄管理器)。它會運行它所找到的第一個。這些登錄管理器可以和agetty類比,它們會等著用戶登錄,當用戶退出後自己重新運行。(編程入門網)

bilbo@bilbo:~$ man kdm
No manual entry for kdm
bilbo@bilbo:~$

顯然,目前為止沒有kdm的manpage。

bilbo@bilbo:~$ man gdm
No manual entry for gdm
bilbo@bilbo:~$

目前為止,gnome的用戶也不關心gdm的manpage。(譯注:Slackware 9.1中已經有了)

XDM(1) XDM(1)
NAME
  xdm - X Display Manager with support for XDMCP, host
  chooser
  SYNOPSIS
  xdm [ -config configuration_file ] [ -nodaemon ] [ -debug
  debug_level ] [ -error error_log_file ] [ -resources
  resource_file ] [ -server server_entry ] [ -session ses-
  sion_program ]
DESCRIPTION
  Xdm manages a collection of X displays, which may be on
  the local host or remote servers. The design of xdm was
  guided by the needs of X terminals as well as The Open
  Group standard XDMCP, the X Display Manager Control Proto-
  col. Xdm provides services similar to those provided by
  init, getty and login on character terminals: prompting
  for login name and password, authenticating the user, and
  running a ``session.''

最後我們終於找到了,這是xdm的manpage的片段。由於我總是在運行級3,我沒法告訴你很多有關它的事。

我們已經看到,init - 所有進程之母 - 從內核那裡接管了系統,然後init將處理/etc/inittab文件,根據inittab的輸入,init將依次:

設置缺省的運行級

運行系統初始化腳本 /etc/rc.d/rc.S 並等待它結束

運行指定運行級的腳本並等待它結束

運行級1是/etc/rc.d/rc.K

運行級2、3、4、5是/etc/rc.d/rc.M

運行級0(關機)是/etc/rc.d/rc.0

運行級6(重新啟動)是/etc/rc.d/rc.6

決定在特殊情況,例如ctrl-alt-del或停電時應采取的行動

為運行級1、2、3和5啟動agetty(還有運行級4時啟動6號終端,但有其特殊原因)

為串口連接啟動終端,盡管這不是缺省的行為

為運行級4啟動圖形界面的登錄管理器

結論

事實上這些就是init做的全部事情。剩下的“只不過是腳本”了。但是,仔細讀它們也是很有趣的,否則你不會知道在哪裡加載模塊以及啟動網絡。

Copyright © Linux教程網 All Rights Reserved