LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2313|回复: 7

[翻译] Slackware 系统的 INIT

[复制链接]
发表于 2006-4-10 20:01:08 | 显示全部楼层 |阅读模式
看了这篇文档,发现很适合初学者,于是就花了一个下午翻译了下来。有很多不妥的地方,请大家指教了(很久没有在大本营发贴了,这贴算是向大家赔礼啦)

[php]

                                                                Slackware 系统的 INIT

运行模式级别

   这里将详细介绍一下运行级别(runlevels)。现在是一个非常好的机会去解释一下什么是
   运行级别。一个运行级别决定着 *ix 系统的运行服务级别。每个不同的运行级别决定着
   哪些服务需要运行哪些则不需要。大致上有五个运行级别:

   一个但用户模式、运行最少的系统服务。这个级别的运行模式通常是作为系统维护之用。

   一个多用户系统模式、运行所有所能提供的服务。这些服务可能是一个 HTTP 服务器、邮
   件服务器、SQL 服务器或者别的。

   一个多用户系统模式,和上面的一样,所不同的是它提供了一个图形界面的登陆模式。

   系统正常运行必需是一个多用户的运行模式。你可以定义额外的模式,比如你可以定义一个
   在单用户模式下载入网络支持以便远程登陆之用。

   另外,还有两个特殊的运行模式:

   一个用做关闭系统。

   一个用做重新启动系统。



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 衍生,没有一个例外。

   从 MAN 页:

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 进程从一个名叫 /etc/inittab 的文件开始。

         init 控制着自动运行的程序(精灵进程)。

   通过 pstree 显示的输出,你可以看到这些精灵进程。它们全部是 init 进程的子进程。
   例如有 agetty(4x)、sendmail(2x)等等。

   但是这里有一个问题,为什么 init 是“所有进程之母”?

   从 MAN (第43页)得:

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.

   可以看出,内核启动所做的最后一件事情就是启动 init。Init 接手以后,通过 /etc/inittab
   文件确定运行方式。

   Init 的 man 页提供了许多的信息。但是也许现在最好是先看看 /etc/inittab 文件。
   这个文件看起来像 pretty 的导入文件。

/etc/inittab

   从 man:

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 风格”,这个是 Slackware 吗?

   是的,这是 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 风格”。

   呵呵,仅仅是趣话而已,让我们看一下 /etc/inittabs 的格式:

   重新阅读 Man 页:

               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.

   文件每行有四个字段,并用“:”隔开。

         id - 定义这行的命令

         运行模式 - 指定运行模式,这是一个零或者一或者其他的一个数字

         行为 - 定义所执行的命令,你可以从 inittab 的 man 页找到详细信息。我
         过会详细介绍它。

         进程 - 定义以后 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, <miquels@drinkel.nl.mugnet.org>
# Modified by:  Patrick J. Volkerding, <volkerdi@slackware.com>
#

# 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 行,如果你删去注释得话,仅仅剩下 16 行!但是你可以从
   注释上获得额外的信息。

   让我们一步一步的分析 /etc/inittab。


从注释开始

# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified by:  Patrick J. Volkerding, <volkerdi@slackware.com>
   
   最后一个版本是由 Miquel van Smoorenburg 创建,并且由 Patrick J. Volkerding
   移植到 Slackware 下。注释不要过于的冗长,这不是工作的关键。任何东西都是基于
   GPL 下工作的。
   
Slackware 的运行级

# 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 拥有七个运行级别。运行级别 2 和 5 并没有使用,待会你可以
   定义它们像级别 3 一样的运行。

默认的运行级别

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

   终于到了说一下真正起作用的一行了。这是一个普通的 inittab 行;用“:”分成 4 个字段。
   行为定义(action)是“initdefault”,具体信息可以用 MAN 看到:

   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,一个多用户的
   文本界面(Console)登陆模式。

   如果 init 收到进入其他命令的信号(比如命令 `telinit 1`),它就会马上进入这个级别,
   比如重新启动。

系统初始化

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

   “sysinit”的名字所表示的行为已经非常的明显了,不过我们还是要看一下 Man 是
   怎么说的:

  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
   实际上是一个脚本。你可以在 /etc/rc.d 目录下查看 Slackware 所有的 init 启动脚本。
   我们可以了解到脚本文件 /etc/rc.d/rc.S 是初始化系统用的,我们等会详细介绍下它。

运行级脚本

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

   The action here is wait:

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

   The script (that is what it is) will be called when entering runlevels 1
   and S (S for single). The action "wait" makes that init will hold all
   other actions until the processing of /etc/rc.d/rc.K finishes. In
   /etc/rc.d/rc.K the services are started needed for a singe user runlevel.
   Later on you will see those are not a whole lot.

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

   Again the action is wait. This says the script /etc/rc.d/rc.M is called
   for the runlevels 2,3,4 and 5. So in essence for all the "normal"
   runlevels except runlevel 1. In /etc/rc.d/rc.M all the services for a
   multi-user runlevel are started. Quite a script as we will see in a while.

   The lines we have seen so far are used to determine what hapens after a
   system boots. In all cases init will wait till the started process (the
   script) terminates. The next couple of lines are actions that init should
   take in special circumstances and do not really belong to any specific
   runlevel.

特殊功能

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

   并不是只有 M$ 用户知道“三指掸”的威力。但是 Linux 允许你定义你是否开启这个功能。
   INIT 有一个详细的关于此方面信息的介绍:

   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/shutdon -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 参数意味着重新启动,这个信号发送给 INIT 并使其转入运行级别 6。这动作延迟
   5 秒。你可以重新定义“三指禅”完成其他不同的命令,例如仅仅是给用户一个重新启
   动的警告。(如果你拥有一个类 NT 系统 和 Linux 系统集成服务器群,那么禁止
   ctrl-alt-del 也许是一个明智之举)

   所以理所当然第二个字段是空的。INIT 从外部获取信号执行命令。

# Runlevel 0 halts the system.
l0:0:wait:/etc/rc.d/rc.0
      
   又是一个 wait 的行动定义,所以 init 会等待脚本执行完成。当系统进入运行级别 0
   时,init 会执行 /etc/rc.d/rc.0叫(注意,是 0 ;))。这个脚本的作用是安全停止所有
   进程。并不是所有的程序都会乖乖的退出。程序的最后会调用 poweroff 关闭系统,或者
   给用户一个系统停止信号。

# Runlevel 6 reboots the system.
l6:6:wait:/etc/rc.d/rc.6
      
   这行和级别 0 非常的相似。实际上 /etc/rc.d/rc.6 是 /etc/rc.d/rc.0 的一个软连接。
   两个文件的内容是一样的。脚本的实际区别仅仅是在最后一步上的操作不同而已。运行级别
   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
      

   这两行程序相互配合共同完成了一件事情。所定义动作如下:

        powerokwait
               This process will be executed as soon as init is
               informormed that the power has been restored.

        powerfailnow
               This  process  will  be  executed when init is told
               that the battery of  the  external  UPS  is  almost
               empty  and  the power is failing (provided that the
               external UPS and the monitoring process are able to
               detect this condition).

   两行所关注的都是系统电源失效的问题(或者是说 UPS 的供电问题)。当系统电源失效时
   执行 `/sbin/genpowerfail start` ,这个脚本使系统稍后停止。系统重新开始供电时,执行
   `/sbin/genpowerfail stop` 程序,它使系统取消停止并恢复到正常状态。也许你注意到了,
   脚本开始是系统并不等待它完成。如果系统等待其停止,那么将直接导致系统停止。实际上
   `/sbin/genpowerfail` 脚本调用了 'shutdown' 程序,如果你有一个 UPS 你得仔细阅读一下
   /sbin/genpowerfail。

一个登陆的方式

   We've now reached the point where the system is just about operational.
   The sysinit scrip has executed. The default runlevel script(s) have been
   executed, /etc/rc.d/rc.K for the single user runlevel 1 and /etc/rc.d/rc.M
   for the multi user runlevels 2,3,4 and 5. All intended daemons are
   running. And in a multi users runlevel one would be able to logon with
   telnet or ssh, assuming these daemons have been started in /etc/rc.d/rc.M.
   If your system is a server without display and keyboard you could actually
   leave it like this.

   What isn't possible at the moment is to logon at the console. And from
   time to time being able to log in comes in quite handy. Console logons are
   the next task of 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 的参考文档可以看到:

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

   So the started process, /sbin/agetty, will be restarted when it
   terminates. And apperently are started for virtual consoles tty1 through
   tt6 for the runlevels 1,2,3 and 5. These are the runlevels without X.
   Except for the agetty on tty6 which is allso started for runlevel 4. The
   runlevel with X.

   The agetty man page gives us an idea what agetty actually does:

  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).

   So agetty waits on a tty port untill somebody tries to login, at which
   moment is will execute /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.

   And with login a new session is started on the system.

   Lets look back at the output of pstree:

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

   Shoot! Shouldn't there be 6 agetty's?

   Well.... yes, and at one time there actually were 6. But apperantly I have
   logged in twice via a virtual console. Once without any other program
   started, and once with an startx running.... an X session it seems.

   Agetty wil start again whenever I logout, with that respawn... remember.
   It would be kinda funny if agetty would start sooner, multiple users that
   could log in on the same virtual console?

其他的登陆方式

   *Nix has allways given different ways to connect to a system. We have
   allready seen 2 of them:

     * Via the network - with telnet, ssh or such.

     * Via the keyboard, monitor and mouse connected to the system directly.

   But *nix has yet other ways to connect to the system

# 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

   The above 2 blocks start agetty's for serial lines. Those are used for
   serail terminals or dialin connections via modems.

   As you can see they are marked out by default. But this is the code you
   will have to deal with if lay you hands on one those good old vtxxx
   terminals or want to dial in to your box.

然后是 X

   And at the verry end, there is X to give us a graphical runlevel

# 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

   The comment first of all gives an explanation for the one getty left over
   on tty6 running in runlevel 6

   It is a "wait" action which executes /etc/rc.d/rc.4. This script will look
   in sequence for kdm (the kde login manager), gdm (the gnome login manager)
   and last xdm (a default login manager). It will execute the first it
   finds. These login managers can be compared to agetty in that they will
   wait for a user to login an start themselves again when the user logs out.

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

   So far for the kdm manpage, appently they did not get to it at KDE.

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

   And so far for the gdm manpage, and the Gnome people do not care either.

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.''
      

   And, finally we have got a hit, here is an abstract from the XDM manpage.
   Since I am allways in runlevel 3 I can't really tell you a lot about it.

   En hier die van xdm. Ik kan je er verder weinig van vertellen. Ik zit
   altijd in runlevel 3, en gebruik dus geen grafische inlog managers.

我们所得到的

   我们已经了解到,“init”从内核获得对机器的控制权,并且是所有进程的母亲。
   “Iint”会读取 “/etc/inittab”,然后会做以下的事情:

         设定默认的运行级别

         运行系统初始化程序 /etc/rc.d/rc.S,并等待它完成

         运行所定义的运行级别,并等待它完成

          /etc/rc.d/rc.K 为运行级别 1

          /etc/rc.d/rc.M 是为多用户级别 2、3、4 和 5 准备的

          /etc/rc.d/rc.0 为运行级别 0(系统停止)

          /etc/rc.d/rc.6 为运行级别 6(系统重启)

         定义一些特殊的功能选项;比如“三指禅”和断电。

         为级别 1、2、3、和 5 运行 agetty 以便用户能本地登陆(但是级别 4 是在第六控制台
         登陆的,这是出于一个特殊的情况)。

         开始 agetty 的串口连接,这不是默认选项

         为运行级别 4 运行一个图形化登陆管理器

   这就是 init 的实际上的功能。它们实际上都是一些“脚本而已”。所以你应该阅读它,
   否则你就不会了解模块是怎么载入的、网络是怎么开始的。
[/php]
 楼主| 发表于 2006-4-10 20:08:12 | 显示全部楼层
原英文版本:

[php]

                                                                        Slack's INIT


1. Runlevels.

   There will be a lot of talk about runlevels. So perhaps this is a good
   time to give a bit of explanation about runlevels. A runlevel is a *nix
   method to determine the service level of a certain machine. Per runlevel
   one would be able to define which services will be active and which not.
   In principle there can be many runlevels. In practice this is limited to
   5:

     * A single user runlevel in which an absolute minimum of services is
       running. This runlevel is often used for system maintenance.

     * A multi user runlevel in which all the services run which are to be
       offered. These services can be a HTTP server , e-mail server, SQL
       server or what ever else. Just what the sysop (you!) wants.

     * A multi user runlevel, same as before, only this time with a graphical
       login manager.

   One of these multi user runlevels will be the normal operation state of
   the machine. It is up to you to define extra runlevels. For instance a
   single user runlevel with network support for remote maintenance.

   Beside these runlevels there are 2 special runlevels:

     * A runlevel to halt the system.

     * A runlevel to reboot the system.

3.2. Init, the mother of all processes.

   If I ask for a forest view of all the processes on my box, I would get
   something like this:

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:~$

   What pstree shows is a sort of "tree structure" view of all the processes
   on my box. It looks a bit like a directory structure. What catches the eye
   (mine at least) is that the "root" in this view is "init". From init all
   other processes spawn. And that is not by chance.

   From the 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.

   There are a few important remarks in here:

     * Init is the parent of all processes.

     * Init starts processes from a file /etc/inittab.

     * Init is in control of autonomous processes (daemons).

   In the pstree view above you can see those autonomous processes. They are
   all direct children of init. Among them are agetty (4x), sendmail (2x),
   lpd and syslogd to name a few.

   But why is it that init is the "mother of all processes"?

   From the manpage (regel 43)

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.

   So the last thing the kernel does when it boots is to start init. Init on
   its turn will work its way through /etc/inittab.

   Init's manpage gives a lot more info. But perhaps for us it is a good time
   to take a look at /etc/inittab. This seems to be a pretty important file.

3.3. /etc/inittab

   From the 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

   Whoha, shock!. It says: "Used by the sysv-compatible init process". And
   this is Slackware?

   Yes this is Slackware, and Slackware uses Sys V init. Just for kicks, lets
   have a look at the Slackware package description:

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:~$

   So let nobody ever tell you that Slackware does not use Sys V init. It
   just uses it in a "BSD style".

   Enough fun..... lets have a look at /etc/inittabs format:

   Again from the 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.

   The file is consists of lines, each made out of 4 fields, separated by a
   ":"

     * id - an identifier for the line

     * runlevels - a list with zero 1 or more runlevels for which this action
       should take place

     * action - the action that should take place, you will find them
       summarized in inittab's manpage. I'll quote them when appropriate

     * process - the process which will be started by init

   Complex? It is not that bad.... here is my /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, <miquels@drinkel.nl.mugnet.org>
# Modified by:  Patrick J. Volkerding, <volkerdi@slackware.com>
#

# 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:~$

   Only 74 lines of text (just about an A4 (ok folio)), if you would take
   away the comments there would be only 16 lines left! But you will learn
   that the comments are worth reading.

   Lets start by taking /etc/inittab apart....

3.4. Comments to start with

# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified by:  Patrick J. Volkerding, <volkerdi@slackware.com>

   The last version of the file has been made by Miquel van Smoorenburg
   (sounds dutch) and it is modified for Slackware by Patrick J. Volkerding
   (Slackware's maintainer(yes Slackware is a one mans job)). The comment
   does not do much, but it does belong there. Lets call it GPL at work.

3.5. The Slackware runlevels

# 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

   Again a piece of comment, which of course does not do anything. But it
   makes what is to follow a lot clearer. What you see is a description of
   the 7 runlevels as in use by Slackware. Run levels 2 and 5 are not in use,
   you will see later on that they use the same scripts as runlevels 3.

3.6. The default runlevel

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

   Finally something is actually done. It is a normal inittab line; 4 fields,
   separated by a ":". The action here is "initdefault", according to the
   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.

   Here the default runlevel is configured. But of course that is what it
   said in the leading comment. So the default runlevel for Slackware is
   runlevel 3; a multi-user runlevel with console/text login.

   This is the runlevel init will enter if its not signaled (by a command
   like `telinit 1`) to enter an other runlevel, i.e. when the system boots.

3.7. Systeem initialisation

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

   The action here is "sysinit" and it's meaning is quite obvious, but lets
   have a look at the manpage anyway:

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

   Allthough the runlevel "S" is stated, it is actually ignored. The program
   that will run is /etc/rc.d/rc.S, which is a script. You will see that all
   of Slackware's init scripts are in /etc/rc.d. In /etc/rc.d/rc.S the system
   will be initialised as we will see when we discuss the script later on.

3.8. The runlevel scripts

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

   The action here is wait:

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

   The script (that is what it is) will be called when entering runlevels 1
   and S (S for single). The action "wait" makes that init will hold all
   other actions until the processing of /etc/rc.d/rc.K finishes. In
   /etc/rc.d/rc.K the services are started needed for a singe user runlevel.
   Later on you will see those are not a whole lot.

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

   Again the action is wait. This says the script /etc/rc.d/rc.M is called
   for the runlevels 2,3,4 and 5. So in essence for all the "normal"
   runlevels except runlevel 1. In /etc/rc.d/rc.M all the services for a
   multi-user runlevel are started. Quite a script as we will see in a while.

   The lines we have seen so far are used to determine what hapens after a
   system boots. In all cases init will wait till the started process (the
   script) terminates. The next couple of lines are actions that init should
   take in special circumstances and do not really belong to any specific
   runlevel.

3.9. Special circumstances

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

   Not just MS knows about the "3 finger salute". But in Linux you can decide
   for youself what happen when it is given. To be complete here is init's
   manpage entry about this action:

        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.

   On a Slackware system the command `/sbin/shutdown -t5 -r now` is executed.

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.

   The -r means that a reboot will follow, this is done by signaling init to
   enter runlevel 6. The delay is 5 seconds from now. If you are a uptime
   junkie you could make the "3 finger salute" do something completely
   different, and in effect force a user to give the shutdown command
   explicitly. (Disabling ctrl-alt-del is not such a bad idea if you have a
   server farm mix with NT like systems and Linux.)

   Off course there is no need for the second field for the runlevel. Init
   reacts on a signal from the outside world.

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

   Again the action is wait, so init will once again wait for the script to
   finish. On entering runlevel 0 init will execute /etc/rc.d/rc.0 (that's a
   zero ;)). What this script does is bring all started processes down in a
   safe way. Not every program likes when you would simply pull the plug. As
   a last action it will call poweroff which will shutsdown the system or
   signal the user that he can pull the plug.

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

   This entry is verry simular to the previous entry. That simular in fact
   that /etc/rc.d/rc.0 is a symbolic link to /etc/rc.d/rc.6. The two scripts
   are identical. The way the script is called determines what the last step
   will be. In the case of runlevel 6 (this case) the last command will be
   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
      

   These next two entries can be adressed in one go. They have a lot to do
   with each other. The actions are:

        powerokwait
               This process will be executed as soon as init is
               informormed that the power has been restored.

        powerfailnow
               This  process  will  be  executed when init is told
               that the battery of  the  external  UPS  is  almost
               empty  and  the power is failing (provided that the
               external UPS and the monitoring process are able to
               detect this condition).

   Both lines have something to do with the action that will be taken as a
   result of a power faillure (or actually the draining of the UPS battries).
   `/sbin/genpowerfail start' begins by bringing the system down.
   `/sbin/genpowerfail stop` tries to interrupt the system going down in case
   the power is restored. Perhaps you notice that the start action does not
   wait for the script to finish. If it would have waited, one would not be
   able to ineterrupt the shutdown. `/sbin/genpowerfail` is a script which
   uses 'shutdown', if you have an UPS you should read the script
   /sbin/genpowerfail.

3.10. A way to logon

   We've now reached the point where the system is just about operational.
   The sysinit scrip has executed. The default runlevel script(s) have been
   executed, /etc/rc.d/rc.K for the single user runlevel 1 and /etc/rc.d/rc.M
   for the multi user runlevels 2,3,4 and 5. All intended daemons are
   running. And in a multi users runlevel one would be able to logon with
   telnet or ssh, assuming these daemons have been started in /etc/rc.d/rc.M.
   If your system is a server without display and keyboard you could actually
   leave it like this.

   What isn't possible at the moment is to logon at the console. And from
   time to time being able to log in comes in quite handy. Console logons are
   the next task of 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
      

   And right away we have a new action, the inittab manpage:

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

   So the started process, /sbin/agetty, will be restarted when it
   terminates. And apperently are started for virtual consoles tty1 through
   tt6 for the runlevels 1,2,3 and 5. These are the runlevels without X.
   Except for the agetty on tty6 which is allso started for runlevel 4. The
   runlevel with X.

   The agetty man page gives us an idea what agetty actually does:

  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).

   So agetty waits on a tty port untill somebody tries to login, at which
   moment is will execute /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.

   And with login a new session is started on the system.

   Lets look back at the output of pstree:

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

   Shoot! Shouldn't there be 6 agetty's?

   Well.... yes, and at one time there actually were 6. But apperantly I have
   logged in twice via a virtual console. Once without any other program
   started, and once with an startx running.... an X session it seems.

   Agetty wil start again whenever I logout, with that respawn... remember.
   It would be kinda funny if agetty would start sooner, multiple users that
   could log in on the same virtual console?

3.11. Another way to logon.

   *Nix has allways given different ways to connect to a system. We have
   allready seen 2 of them:

     * Via the network - with telnet, ssh or such.

     * Via the keyboard, monitor and mouse connected to the system directly.

   But *nix has yet other ways to connect to the system

# 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

   The above 2 blocks start agetty's for serial lines. Those are used for
   serail terminals or dialin connections via modems.

   As you can see they are marked out by default. But this is the code you
   will have to deal with if lay you hands on one those good old vtxxx
   terminals or want to dial in to your box.

3.12. And then there is X.

   And at the verry end, there is X to give us a graphical runlevel

# 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

   The comment first of all gives an explanation for the one getty left over
   on tty6 running in runlevel 6

   It is a "wait" action which executes /etc/rc.d/rc.4. This script will look
   in sequence for kdm (the kde login manager), gdm (the gnome login manager)
   and last xdm (a default login manager). It will execute the first it
   finds. These login managers can be compared to agetty in that they will
   wait for a user to login an start themselves again when the user logs out.

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

   So far for the kdm manpage, appently they did not get to it at KDE.

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

   And so far for the gdm manpage, and the Gnome people do not care either.

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.''
      

   And, finally we have got a hit, here is an abstract from the XDM manpage.
   Since I am allways in runlevel 3 I can't really tell you a lot about it.

   En hier die van xdm. Ik kan je er verder weinig van vertellen. Ik zit
   altijd in runlevel 3, en gebruik dus geen grafische inlog managers.

3.13. Where did that get us.

   We have seen that "init" - as the mother of all processes - got controll
   over the machine from the kernal. "Init" will than process the file
   "/etc/inittab". With the input from "inittab" "init" will in sequence:

     * Set the default runlevel.

     * Run the sytem initialisation script /etc/rc.d/rc.S, and wait for its
       completion.

     * Run the script for the decided runlevel, and wait for its completion.

          * /etc/rc.d/rc.K for the single user runlevel 1

          * /etc/rc.d/rc.M for the multi user runlevels 2,3,4 en 5

          * /etc/rc.d/rc.0 for runlevel 0 (system halt)

          * /etc/rc.d/rc.6 for runlevel 6 (system reboot)

     * Determine which action should be taken in special circumstances like;
       ctrl-alt-del and power faillure.

     * Start agetty's for the consoles in runlevels 1, 2, 3 en 5 so users can
       logon locally. (And 1 for runlevel 4 on console 6, but that has a
       special reason)

     * Start agetty's for serial connection, not the default behaviour
       though..

     * Start a graphical logon manager for runlevel 4.

   This in fact is all there is to it for init. What rests are "just
   scripts". But they can be fun to look over; otherwise you still would not
   know where your modules get loaded and the network started.



[/php]
回复 支持 反对

使用道具 举报

发表于 2006-4-10 20:52:39 | 显示全部楼层
感谢楼主的分享!今天上午正好在看LINUX的串口通信,也很细致的提到了/etc/inittab,看完此帖后,印象更深了。
我把ca::ctrlaltdel:/sbin/shutdown -t5 -r now改成了
ca::ctrlaltdel:/usr/bin/echo "what are you doing?"了,呵呵。
回复 支持 反对

使用道具 举报

发表于 2006-4-10 23:37:33 | 显示全部楼层
收下,谢谢,顶顶
回复 支持 反对

使用道具 举报

发表于 2006-4-11 11:10:17 | 显示全部楼层
仔细看了看,这篇东西我曾经译过

http://www.linuxsir.cn/bbs/showthread.php?t=83503
回复 支持 反对

使用道具 举报

发表于 2006-4-11 11:20:54 | 显示全部楼层
感谢楼主的分享!今天上午正好在看LINUX的串口通信,也很细致的提到了/etc/inittab,看完此帖后,印象更深了。
我把ca::ctrlaltdel:/sbin/shutdown -t5 -r now改成了
ca::ctrlaltdel:/usr/bin/echo "what are you doing?"了,呵呵。


如果我能物理接触你机器,我就来个alt+sysrq+b,哼。

注:不是灌水。
回复 支持 反对

使用道具 举报

发表于 2006-4-11 13:45:04 | 显示全部楼层
没错,SlackWare就是一个披着BSD皮的SysV
真正的BSD系统根本没有runlevel的概念
回复 支持 反对

使用道具 举报

发表于 2006-4-11 15:05:02 | 显示全部楼层
google了一下:

Tom Gall
Staff Software Engineer, IBM linux 技术中心
2000 年 4 月
如果正在使用开发内核或设备驱动程序,或运行着那些能导致机器发生内核严重错误的代码,那么这个技巧会对您有用。

这个技巧在 linux 上使用,适用于 x86、PowerPC 或 SPARC 处理器,并且你至少需要拥有 2.2.x 或以上的内核。

如果您的机器遭遇严重错误,或突然变成了一堆炽热的零件,您可以通过组合键来同步文件系统,并将文件系统重新装载为只读。接着重启,您就能避免可能长时间的文件系统检查。

不同平台的组合键略有不同:
x86 ALT-SYSRQ-[命令键]
SPARC ALT-STOP-[命令键]
PowerPC ALT-Print Screen-[命令键]


命令键如下所示:
s 试图同步所有已装载的文件系统
u 试图将所有已装载的文件系统重新装载为只读
b 试图立即重新启动系统
(这相当于按下机箱的复位开关
或电源按钮; 进程将没有
关闭的机会。)
p 将当前的寄存器和标记打印到控制台
t 将当前任务及相关信息的列表打印到控制台
e 发送 SIGTERM 到所有进程中,init 除外
i 发送 SIGKILL 到所有进程中,init 除外
l 发送 SIGKILL 到所有进程中

欲了解更多信息,请查看 /usr/src/linux/Documentation/sysrq.txt,可获取其他组合键。

我机器默认好象没有开sysrq,网上搜索了下说要编译内核才加入支持,默认没有编译进去。我直接用的是test26.s的内核。
不过也长见识了!
同时也发现右alt+sysrq可以直接切换到GUI。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表