找回密码
 立即注册
搜索
查看: 315|回复: 0

BusyBox inittab 文件介绍

[复制链接]

266

主题

0

回帖

1119

积分

管理员

积分
1119
发表于 2024-1-8 00:47:22 | 显示全部楼层 |阅读模式

除了基本的命令之外,BusyBox 还支持 init 功能,如同其它的 init 一样,BusyBox 的 init 也是完成系统的初始化工作,关机前的工作等等,我们知道在  Linux 的内核被载入之后,机器就把控制权转交给内核,内核启之后做了一些工作,然后找到根文件系统里面的 init 程序,并执行它。init 进程会依次进行以下工作:

  1. 为 init 设置信号处理过程;

  2. 初始化控制台;

  3. 剖析 /etc/inittab 文件;

  4. 执行系统初始化命令行,缺省情况下会使用 /etc/init.d/rcS;

  5. 执行所有导致 init 暂停的 inittab 命令(动作类型:wait);

  6. 执行所有仅执行一次的 inittab命令(动作类型:once);

一旦完成以上工作,init 进程便会循环执行以下进程:

  1. 执行所有终止时必须重新启动的 inittab 命令(动作类型:respawn)

  2. 执行所有终止时必须重新启动但启动前必须询问用户的 inittab 命令(动作类型:askfirst)

初始化控制台之后,BusyBox 会检查 /etc/inittab 文件是否存在,如果此文件不存在,BusyBox 会使用缺省的 inittab 配置,它主要为系统重引导,系统挂起以及 init 重启动设置缺省的动作,此外它还会为四个虚拟控制台(tty1 到 tty4)设置启动 shell 的动作。如果未建立这些设备文件,BusyBox 会报错。

Busybox 的 init 进程在初始化的时候会查看是否有 /etc/inittab 文件,如果有则解析它。

inittab 文件中每一行的格式如下所示:

id:runlevel_ignored:action:command
  1. id:对 BusyBox 而言,id 用来指定启动进程的控制终端。如果省略,则使用与 init 进程一样的控制终端。

  2. runlevel_ignored:对于 Busybox init 程序,这个字段没有意义,可以省略。

  3. action:表示 init 程序如何控制这个子进程:

action 说明
sysinit 为 init 提供初始化命令脚本的路径
wait 告诉 init 必须等到相应的进程完成之后才能继续执行
once 仅执行相应的进程一次,而且不会等待它执行完成
respawn 每当 init 进程监测到该进程终止时,重新启动该它
askfirst 与 respawn 类似,不过 init 进程先输出 “Please press Enter to actvie this console”,等用户输入回车键之后才启动子进程
shutdown 当系统关机(halt/reboot)时,执行相应的进程
restart 当 init 重新启动时(restart init when a QUIT is received),执行相应的进程,通常此处所执行的进程就是 init 本身
ctrlaltdel 当按下 Ctrl + Alt + Delete 组合键时,执行相应的进程
  1. process:要执行的程序,它可以是可执行程序,也可以是脚本

实例:

# Note: BusyBox init works just fine without an inittab. If no inittab is
# found, it has the following default behavior:
#         ::sysinit:/etc/init.d/rcS
#         ::askfirst:/bin/sh
#         ::ctrlaltdel:/sbin/reboot
#         ::shutdown:/sbin/swapoff -a
#         ::shutdown:/bin/umount -a -r
#         ::restart:/sbin/init
#         tty2::askfirst:/bin/sh
#         tty3::askfirst:/bin/sh
#         tty4::askfirst:/bin/sh
#
# Boot-time system configuration/initialization script.
# This is run first except when booting in single-user mode.
#
::sysinit:/etc/init.d/rcS

# /bin/sh invocations on selected ttys
#
# Note below that we prefix the shell commands with a "-" to indicate to the
# shell that it is supposed to be a login shell.  Normally this is handled by
# login, but since we are bypassing login in this case, BusyBox lets you do
# this yourself...
#
# Start an "askfirst" shell on the console (whatever that may be)
::askfirst:-/bin/sh
# Start an "askfirst" shell on /dev/tty2-4
tty2::askfirst:-/bin/sh
tty3::askfirst:-/bin/sh
tty4::askfirst:-/bin/sh

# /sbin/getty invocations for selected ttys
tty4::respawn:/sbin/getty 38400 tty5
tty5::respawn:/sbin/getty 38400 tty6

# Example of how to put a getty on a serial line (for a terminal)
#::respawn:/sbin/getty -L ttyS0 9600 vt100
#::respawn:/sbin/getty -L ttyS1 9600 vt100
#
# Example how to put a getty on a modem line.
#::respawn:/sbin/getty 57600 ttyS2

# Stuff to do when restarting the init process
::restart:/sbin/init

# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a

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

本版积分规则

Archiver|手机版|小黑屋|棱讯科技 ( 粤ICP备2024228160号-2|粤公网安备44030002003510号 )

GMT+8, 2024-7-27 17:03 , Processed in 0.016522 second(s), 4 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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