LinuxSir.cn,穿越时空的Linuxsir!

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

updatedb+locate+man=linux bible 二分钟自制inittab

[复制链接]
发表于 2004-11-21 20:52:43 | 显示全部楼层 |阅读模式
如果你的inittab有问题了.恢复可以说比较麻烦, 如果在trouble shooting
中遇到, 那就真的很麻烦了. 以下提供一个最好的方法给那些不愿动太多脑的人,在三分钟内用最简单的方法不用记忆任何内容就可以自制一个inittab.
只要按照以下方法: 1 updatedb
                  2 locate inittab
           看到这里也许你会以为我要用inittab的man page, 那没什么新鲜的一点不错, 但我不是要你看, 而是执行man inittab > a   把inittab的说明文档输出到a文件中
然后.....呵呵. 用vi编辑你会看到文件有许多的乱码.(在linux中会是乱码)
如下:

INITTAB(5)            Linux System Administrator's Manual           INITTAB(5)



N NA AM ME E
       inittab  -  format of the inittab file used by the sysv-compatible init
       process

D DE ES SC CR RI IP PT TI IO ON N
       The i in ni it tt ta ab b file describes which processes are started  at  bootup  and
       during  normal  operation  (e.g. /etc/init.d/boot, /etc/init.d/rc, get-
       tys...).  I In ni it t(8) distinguishes multiple _ r_ u_ n_ l_ e_ v_ e_ l_ s, each of  which  can
       have  its  own  set of processes that are started.  Valid runlevels are
       0 0-6 6 plus A A, B B, and C C for o on nd de em ma an nd d entries.  An  entry  in  the  i in ni it tt ta ab b
       file has the following format:

              _ i_ d:_ r_ u_ n_ l_ e_ v_ e_ l_ s:_ a_ c_ t_ i_ o_ n:_ p_ r_ o_ c_ e_ s_ s

       Lines beginning with `#' are ignored.

       _ i_ d     is a unique sequence of 1-4 characters which identifies an entry
              in i in ni it tt ta ab b (for versions of sysvinit compiled with the _ o_ l_ d libc5
              (< 5.2.18) or a.out libraries the limit is 2 characters).

              Note:  traditionally,  for  getty and other login processes, the
              value of the _ i_ d field is kept the same as the suffix of the cor-
              responding  tty,  e.g. 1 1 for t tt ty y1 1. Some ancient login accounting
              programs might expect this, though I can't think of any.

       _ r_ u_ n_ l_ e_ v_ e_ l_ s
              lists the runlevels for which the  specified  action  should  be
              taken.

       _ a_ c_ t_ i_ o_ n describes which action should be taken.

       _ p_ r_ o_ c_ e_ s_ s
              specifies  the  process  to  be  executed.  If the process field
              starts with a `+' character, i in ni it t 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  _ r_ u_ n_ l_ e_ v_ e_ l_ s field may contain multiple characters for different run-
       levels.  For example, 1 12 23 3 specifies that the process should be  started
       in  runlevels 1, 2, and 3.  The _ r_ u_ n_ l_ e_ v_ e_ l_ s for o on nd de em ma an nd d entries may con-
       tain an A A, B B, or C C.  The _ r_ u_ n_ l_ e_ v_ e_ l_ s field of s sy ys si in ni it t, b bo oo ot t, and b bo oo ot tw wa ai it t
       entries are ignored.

       When the system runlevel is changed, any running processes that are not
       specified for the new runlevel are killed,  first  with  SIGTERM,  then
       with SIGKILL.

       Valid actions for the _ a_ c_ t_ i_ o_ n field are:

       r re es sp pa aw wn n
              The  process  will  be  restarted  whenever  it terminates (e.g.
              getty).

       w wa ai it t   The process will be started once when the specified runlevel  is
              entered and i in ni it t will wait for its termination.

       o on nc ce e   The process will be executed once when the specified runlevel is
              entered.

       b bo oo ot t   The process will be executed during system boot.  The  _ r_ u_ n_ l_ e_ v_ e_ l_ s
              field is ignored.

       b bo oo ot tw wa ai it t
              The  process  will  be  executed  during system boot, while i in ni it t
              waits for its termination (e.g. /etc/rc).  The  _ r_ u_ n_ l_ e_ v_ e_ l_ s  field
              is ignored.

       o of ff f    This does nothing.

       o on nd de em ma an nd d
              A  process  marked  with  an  o on nd de em ma an nd d runlevel will be executed
              whenever the specified o on nd de em ma an nd d runlevel is called.  However, no
              runlevel change will occur (o on nd de em ma an nd d runlevels are `a', `b', and
              `c').

       i in ni it td de ef fa au ul lt t
              An i in ni it td de ef fa au ul lt t entry specifies  the  runlevel  which  should  be
              entered  after system boot.  If none exists, i in ni it t will ask for a
              runlevel on the console. The _ p_ r_ o_ c_ e_ s_ s field is ignored.

       s sy ys si in ni it t
              The process will be executed during system boot. It will be exe-
              cuted before any b bo oo ot t or  b bo oo ot tw wa ai it t entries.  The _ r_ u_ n_ l_ e_ v_ e_ l_ s field
              is ignored.

       p po ow we er rw wa ai it t
              The process will be executed when the power goes down.  Init  is
              usually  informed  about this by a process talking to a UPS con-
              nected to the computer.  I In ni it t will wait for the process to  fin-
              ish before continuing.

       p po ow we er rf fa ai il l
              As  for  p po ow we er rw wa ai it t,  except that i in ni it t does not wait for the pro-
              cess's completion.

       p po ow we er ro ok kw wa ai it t
              This process will be executed as soon  as  i in ni it t  is  informormed
              that the power has been restored.

       p po ow we er rf fa ai il ln no ow w
              This process will be executed when i in ni it t 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).

       c ct tr rl la al lt td de el l
              The process will be executed when i in ni it t receives the SIGINT  sig-
              nal.   This means that someone on the system console has pressed
              the C CT TR RL L- -A AL LT T- -D DE EL L key combination. Typically one wants to execute
              some sort of s sh hu ut td do ow wn n either to get into single-user level or to
              reboot the machine.

       k kb br re eq qu ue es st t
              The process will be executed when i in ni it t receives  a  signal  from
              the  keyboard handler that a special key combination was pressed
              on the console keyboard.

              The documentation for this function is not  complete  yet;  more
              documentation can be found in the kbd-x.xx packages (most recent
              was kbd-0.94 at the time of this writing). Basically you want to
              map  some  keyboard  combination to the "KeyboardSignal" action.
              For example, to map Alt-Uparrow for this purpose use the follow-
              ing in your keymaps file:

              alt keycode 103 = KeyboardSignal


E EX XA AM MP PL LE ES S
       This is an example of a inittab which resembles the old Linux inittab:

   这里这里   # inittab for linux
              id:1:initdefault:
              rc::bootwait:/etc/rc
              1:1:respawn:/etc/getty 9600 tty1
              2:1:respawn:/etc/getty 9600 tty2
              3:1:respawn:/etc/getty 9600 tty3
              4:1:respawn:/etc/getty 9600 tty4

       This  inittab  file  executes  / /e et tc c/ /r rc c during boot and starts gettys on
       tty1-tty4.

       A more elaborate i in ni it tt ta ab b with different  runlevels  (see  the  comments
       inside):

              # Level to run in
              id:2:initdefault:

              # Boot-time system configuration/initialization script.
              si::sysinit:/etc/init.d/rcS

              # What to do in single-user mode.
              ~:S:wait:/sbin/sulogin

              # /etc/init.d executes the S and K scripts upon change
              # of runlevel.
              #
              # Runlevel 0 is halt.
              # Runlevel 1 is single-user.
              # Runlevels 2-5 are multi-user.
              # Runlevel 6 is reboot.

              l0:0:wait:/etc/init.d/rc 0
              l1:1:wait:/etc/init.d/rc 1
              l2:2:wait:/etc/init.d/rc 2
              l3:3:wait:/etc/init.d/rc 3
              l4:4:wait:/etc/init.d/rc 4
              l5:5:wait:/etc/init.d/rc 5
              l6:6:wait:/etc/init.d/rc 6

              # What to do at the "3 finger salute".
              ca::ctrlaltdel:/sbin/shutdown -t1 -h now

              # Runlevel 2,3: getty on virtual consoles
              # Runlevel   3: getty on terminal (ttyS0) and modem (ttyS1)
              1:23:respawn:/sbin/getty tty1 VC linux
              2:23:respawn:/sbin/getty tty2 VC linux
              3:23:respawn:/sbin/getty tty3 VC linux
              4:23:respawn:/sbin/getty tty4 VC linux
              S0:3:respawn:/sbin/getty -L 9600 ttyS0 vt320
              S1:3:respawn:/sbin/mgetty -x0 -D ttyS1



F FI IL LE ES S
       /etc/inittab

A AU UT TH HO OR R
       I In ni it t  was written by Miquel van Smoorenburg (miquels@cistron.nl).  This
       manual page was written by Sebastian  Lederer  (lederer@francium.infor-
       matik.uni-bonn.de)  and modified by Michael Haardt (u31b3hs@pool.infor-
       matik.rwth-aachen.de).

S SE EE E A AL LS SO O
       i in ni it t(8), t te el li in ni it t(8)



                                  Dec 4, 2001                       INITTAB(5)


但这些只是格式不符的一些说明信息, 并没有用处. 你可以用一串的dd删除那些乱码,当你删到:
# inittab for linux (在上边有标记"这里这里")
              id:1:initdefault:
              rc::bootwait:/etc/rc
              1:1:respawn:/etc/getty 9600 tty1
              2:1:respawn:/etc/getty 9600 tty2
              3:1:respawn:/etc/getty 9600 tty3
              4:1:respawn:/etc/getty 9600 tty4
这时你就要停了. 看起来是不是非常熟悉?
对比一下, 这就是你的inittab中开始起作用的第一行.
做如下步骤 : 改id:1:initdefault:  为id:3:initdefault:
从id:1:initdefault: 再往下删. 不要以为
              rc::bootwait:/etc/rc
              1:1:respawn:/etc/getty 9600 tty1
              2:1:respawn:/etc/getty 9600 tty2
              3:1:respawn:/etc/getty 9600 tty3
              4:1:respawn:/etc/getty 9600 tty4
是有用的. 删到.si::sysinit:/etc/init.d/rcS  将rcS改成rc.sysinit
再删到        l0:0:wait:/etc/init.d/rc 0
              l1:1:wait:/etc/init.d/rc 1
              l2:2:wait:/etc/init.d/rc 2
              l3:3:wait:/etc/init.d/rc 3
              l4:4:wait:/etc/init.d/rc 4
              l5:5:wait:/etc/init.d/rc 5
              l6:6:wait:/etc/init.d/rc 6

       要保留哦# What to do at the "3 finger salute".
       要保留哦  ca::ctrlaltdel:/sbin/shutdown -t1 -h now

执行 1,$s/init.d/rc.d/g     接着删到
              1:23:respawn:/sbin/getty tty1 VC linux
              2:23:respawn:/sbin/getty tty2 VC linux
              3:23:respawn:/sbin/getty tty3 VC linux
              4:23:respawn:/sbin/getty tty4 VC linux
              S0:3:respawn:/sbin/getty -L 9600 ttyS0 vt320
              S1:3:respawn:/sbin/mgetty -x0 -D ttyS1
执行 1,$s/getty/mingetty/g 然后将tty1后的都删除将23改成23456, 不明白看下边:   1:23456:respawn:/sbin/mingetty tty1 VC linux
              2:23456:respawn:/sbin/mingetty tty2
              3:23456:respawn:/sbin/mingetty tty3
              4:23456:respawn:/sbin/mingetty tty4
              5:23456:respawn:/sbin/mingetty tty5
              6:23456:respawn:/sbin/mingetty tty6
存盘改文件名为inittab重启试试? 你是不是可以将机器启动了? 其实inittab是非常重要的文件, 如果你能背下来是最好的. 做为管理员你也应该有这种水平,但对一些记忆并不好的人或在考试时紧张的人来说. 这无疑是你的救命草. 当然,你在rescue可能不能做updatedb 但你可以man或将inittab的5.gz的位置记下.就是 /usr/share/man/man5/inittab.5.gz稍微懂一些的人都会知道share目录是放说明文档的地方吧? 如果你不想耽误考试中很紧的时间的话, 这就是你最好的解决方法. 但最后要说明的是, 这个文件并没有说inittab中的三个重启动的命令, 但这并不影响inittab的使用. 以上是经过测试的. 一定能用.希望对你有帮助.
发表于 2004-11-21 21:39:40 | 显示全部楼层
呵呵,你瞎胡搞,钻牛角尖.
 楼主| 发表于 2004-11-21 21:44:08 | 显示全部楼层
我是瞎搞, 如果你要考试遇到这种情况.你看看你会不会搞?
发表于 2004-11-22 09:29:14 | 显示全部楼层
You can reinstall initscripts-*.rpm !
发表于 2004-11-22 16:06:35 | 显示全部楼层
不错,可以试试。
发表于 2004-11-24 22:36:41 | 显示全部楼层
最初由 shfeng1 发表
我是瞎搞, 如果你要考试遇到这种情况.你看看你会不会搞?

呵呵,我会搞。我已经是rhce了
发表于 2004-11-25 23:33:46 | 显示全部楼层
initscript rpm包重装不就得了 -,-
发表于 2004-11-28 23:47:31 | 显示全部楼层
不好意思我再来bs你一下,对于man文件的处理你完全不必这样手动处理。

man inittab | col -b > inittab.examples
发表于 2004-11-30 20:32:21 | 显示全部楼层
晕死,搞得这么复杂
发表于 2004-11-30 20:45:22 | 显示全部楼层
呵呵。,好用啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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