Linux: Startup Analysis III -- inittab analysis

 Linux startup process: 

1. inittab file (/etc/inittab)

1. All the entries in inittab file are stored with format below:

id:run-levels:action:process

id --> identifier, usually two alphabets or two degits.

run-levels --> digit from 0-6. multiple run-level can be assigned.

action --> represents the running status

process --> represents the script/command that need to be executed.

process is our main focus, and we can even ignore the id.

action:
1> initdefault: the system default run level
2> sysinit: 
3> wait: the command marked wait means the commands after this line can be executed only after the execution of this command.
4> once: start a new process and execute the command, the commands after it don't have to wait the execution of it.
5> ctrlaltdel: the command will be executed when we press ctrl+alt+del
6> powerfail: when there is error with battery/power, the command specified will be executed, and don't have to wait for end of the execution.
7> powerokwait: when the battery/power back to normal, the command specified will be executed.
8> respawn: whenever the command executed, the command should be executed again. It a command execution loop.

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

Sometimes we may install sendmail, and it will execute when we start up. And its default action is wait, that means other commands have to wait the execution of it. That would take a lot of time.

# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# In linux, tty means local terminal
# We can press ctrl+alt+F1~F6 to shift between different theres terminals.
# If we press ctrl+alt+F7/F8 then we will shift to x-window terminal
si::sysinit:/etc/rc.d/rc.sysinit
# id -> si
# run-levels -> empty means this init script/command should be executed no matter what the current run-level is

l0:0:wait:/etc/rc.d/rc 0
# id -> l0
# run-levels -> 0 means only execute "/etc/rc.d/rc 0" when current run level is 0

pr:12345:powerokwait:/sbin/shutdown

2. First effective line in inittab file:

id:5:initdefault

1. The default run-level is 5 which means multi-user and x-window running level.

2. We can modify this line to change the default running level when system startup.


 3. There is no process script assigned in this line, why?

 

 3. Second effective line in inittab file:

si::sysinit:/etc/rc.d/rc.sysinit

1. run-level is empty, means whatever current run-level is, this "etc/rc.d/rc.sysinit" will always be executed.

2. "etc/rc.d/rc.sysinit" is a shell script. If we want an operation executed when the system startups, we can add the command at the end of this file.

 

 4. Third segment in inittab file

l0:0:wait:/etc/rc.d/rc 0
l0:1:wait:/etc/rc.d/rc 1
l0:2:wait:/etc/rc.d/rc 2
l0:3:wait:/etc/rc.d/rc 3
l0:4:wait:/etc/rc.d/rc 4
l0:5:wait:/etc/rc.d/rc 5
l0:6:wait:/etc/rc.d/rc 6

1. As the "etc/rc.d/rc.sysinit" is the commom script for any run-levels, how can we make the difference between different run-levels?

    That is how can we make sure run-level 5 will show an x-window and run-level 3 will not?

    This is the function of segment above.

2. "etc/rc.d/rc" is a executable shell script file

ls -l /etc/rc.d/rc
-rwxr-xr-x 1 root root 2255 Jul 4 2009 /etc/rc.d/rc

 3. "etc/rc.d/rc 0" as we pass 0 to the script, the actual running script is stored in "etc/rc.d/rc0.d" directory

etc/rc.d/rc0.d
etc/rc.d/rc1.d
etc/rc.d/rc2.d
etc/rc.d/rc3.d
etc/rc.d/rc4.d
etc/rc.d/rc5.d
etc/rc.d/rc6.d

ls /etc/rc.d
init.d --> direcotory
rc0.d --> direcotory
rc1.d --> direcotory
... --> direcotory
rc.sysinit --> file
rc --> file
rc.local --> file

 4. What stores in "etc/rc.d/rc3.d"?

ls /etc/rc.d/rc3.d
K01dnsmasq
K02avahi-dnsconfd
K02NetworkManager
K05conman
K85mdmpd
S12restorecond
S55sshd

1)  S = start, means in this run level, we need to start this server.

2)  K = kill, means in this run level, we need to kill this server.

 Why should we have K ? As long as we have S, wouldn't that be enough?

 For the benefit of shifting between different run-levels.

 The number after S/K means the priority of starting/killing.

 The smaller the number is, the higher priority the service is.

 The last part is the name of the service script. 

 
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值