init process analysis

uboot passes boot parameters:

root=/dev/mtdblock3  init=/linuxrc console=ttySAC0

 

The kernel starts the first program:

1. The function mount_root mounts the partition root=/dev/mtdblock3

2. Open the device /dev/console

3. Start the first program run_init_process("/linuxrc") //linuxrc is the same as /sbin/init

    ----init_main //init process entry function

    --------parse_inittab //Parse the configuration file /etc/inittab and put it in the init_action_list list

    ------------run_actions //Execute related programs

 

inittab format:

<id>:<runlevels>:<action>:<process>

id => /dev/id, used as terminal: stdin, stdout, stderr: printf, scanf, err

runlevels: ignore

action : execution time

process : application or script

 

(1)./etc/inittab

::sysinit:/etc/init.d/rcS //Execute at startup

console::askfirst:-/bin/sh //Ask the user before starting

::ctrlaltdel:/sbin/reboot //Execute when ctrl+alt+del

::shutdown:/bin/umount -a –r //Execute when the system is shut down

(2). /etc/init.d/rcS

mount –a                     // To mount the file system, the configuration file /etc/fstab is required

mkdir /dev/pts

mount -t devpts devpts /dev/pts

echo /sbin/mdev > /proc/sys/kernel/hotplug

mdev –s

ifconfig eth0 192.168.1.100

telnetd

inetd

(3)./etc/fstab

# device    mount-point    type  options        dump fsck order

proc          /proc        proc  defaults        0    0

tmpfs         /tmp         tmpfs defaults        0    0

sysfs         /sys         sysfs defaults        0    0

tmpfs         /dev         tmpfs defaults        0    0

Note:

a.mount –a mounts the file system configured in /etc/fstab

b.proc virtual file system

The c.mdev mechanism automatically creates devices under /dev, which requires the configuration of the green part

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324818923&siteId=291194637