"Go" embedded Linux file system startup script and Analysis

Source: Internet
Author: User
Tags stdin

Original URL: http://www.linuxidc.com/Linux/2011-03/33728.htm

After the kernel initialization is complete, the boot process of the embedded Linux file system consists of the following steps:

1. Execute the/sbin/init file

2. Execute the/etc/inittab file

3. Execute the/etc/init.d/rcs file

4. Execute Mount File System script

5. Executing kernel module scripts

6. Execute the Network initialization script

7. Execute scripts such as application startup, such as Qtopia startup

System Start Flowchart:

1. Kernel boot init

The last step of the kernel boot is to start the init process, which is the first (and only one) user process initiated by the kernel (process ID 1), which determines which programs to start according to the configuration file, such as some scripts, start the shell, run user-specified programs, and so on, then Init How did the process start---it was started by the kernel calling the/sbin/init file, and someone wanted to know how the kernel found the init file that needed to be executed. The following is a look at the kernel code in INIT/MAIN.C, as follows:

static int noinline init_post (void)

{

Free_initmem (); /* Release Initialize Memory */

Unlock_kernel ();

Mark_rodate_ro ();

system_state=system_running;

Numa_default_policy ();

/* Turn on the control device hanle=0=>stdin*/

if (sys_open (const char __user*) "/dev/console", o_rdwr,0) <0)

PRINTK (kern_warning "waring:unable to open an initial console.\n");

/* Copy the console device to handle 1,2=>stout,stderr*/

(void) sys_dup (0);

(void) sys_dup (0);

/* Try to execute the program specified by Ramdisk_execute_command */

if (Ramdisk_execute_command) {

Run_init_process (Ramdisk_execute_command);

PRINTK (kern_warning "Failed to execute%s\n", Ramdisk_execute_command);

}

/* Try to execute the program specified by Execute_command */

if (Execute_command) {

Run_init_process (Execute_command);

PRINTK (kern_warning "Failed to execute%s\n", Execute_command);

}

/* Try execution of four external programs in turn */

Run_init_process ("/sbin/init");

Run_init_process ("/etc/init");

Run_init_process ("/bin/init");

Run_init_process ("/bin/sh");

Panic ("No init found. Try passing init=option to kernel. ");

The kernel starts the INIT process as follows:

First open the console device/dev/console, and copy the two handle, so stdout,stdin,stderr all point to/dev/console, which opens the standard device input, output, standard error device, and then executes several external programs. Any one of these programs is successfully loaded into the user state, and the kernel boot is declared to be complete.

2. Execute the/etc/inittab file

When Init starts successfully, all you need to do is parse the/etc/inittab file and execute it. The contents are as follows:

#/etc/inittab

:: Sysinit:/etc/init.d/rcs

# start the shell with/DEV/TTYSAC0 as the console

Ttysac0::askfirst:-/bin/sh

# Press the program executed after Ctrl+alt+del, but cannot enter the Ctrl+alt+del key combination in the serial console

:: Ctrlaltdel:/sbin/reboot

# The program that is executed before restarting the shutdown

:: Shutdown:/bin/umount-a-R

3. Execute the/etc/init.d/rcs file

This is a script file where you can add commands that you want to run automatically. The contents are as follows:

#! /bin/sh

Path=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:

Runlevel=s

Prevlevel=n

Umask 022

Export PATH runlevel Prevlevel

# Network Configuration Script

. /etc/init.d/network.sh

# load Zlg_fs

Insmod/bin/zlg_fs.ko

Insmod/bin/zlg_ffs.ko

MKNOD/DEV/ZLG_FSA B 125 0

MKNOD/DEV/ZLG_FSA1 B 125 1

MKNOD/DEV/ZLG_FSA2 B 125 2

Mount-t VFAT/DEV/ZLG_FSA/USR

Mount-a

4. Execute/etc/fstab (Mount file system script)

When Mount–a is executed in file/etc/init.d/rcs, the corresponding file system is mounted according to the file/etc/fstab content.

#device mount-point Type options dump fsck order

NONE/PROC proc Defaults 0 0

None/dev/pts devpts mode=0622 0 0

TMPFS/DEV/SHM TMPFS Defaults 0 0

(1) Device: Devices to be hooked up, such as/dev/hda2

Mount-point: Mount Contact

Type: File system types, such as Pro,jffs2,nfs

Options: hook-up parameters, separated by commas

Dump and fsck order: used to determine the behavior of the control Dump,fsck program.

5. Then execute some kernel modules and network Russian configuration scripts, and finally execute scripts such as application startup, such as Qtopia startup.

"Go" embedded Linux file system startup script and Analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.