Embedded learning notes-root file system inittab

Source: Internet
Author: User

I would like to thank the teacher of the old house for his documents. Below are my documents for the teachers:

First, we will introduce some background information about inittab:

The INIT process is the parent process of all processes in the system. The INIT process generates sub-processes required to complete common operations.
Including: Setting Machine names, checking and installing disks and file systems, starting system logs, configuring network interfaces, and starting networks and emails
Service. In Solaris, the main task of the INIT process is to create a process according to the information provided by the inittab file,
Because all processes initiated by the system are created by init, The INIT process is also called the system initialization process.


The format of the inittab file is described as follows:

In the inittab file, each record starts from a new line. Each record item can contain a maximum of 512 characters. The format of each record is as follows:
It is generally as follows: ID: rstate: Action: process, which is explained below (you can refer to your own file system for comparative learning)
1. The ID field is a string of up to four characters, used to uniquely identify a table item.
2. The rstate (run state) field defines the running level when the record item is called. The rstate can be constructed by one or more running levels.
Yes, or it can be null. If it is null, it indicates the running level 0 ~ 6. When the init is requested to change the running level, the rstate fields are not included
Processes at the new running level will receive a sigterm warning signal and be killed. Only commands started by A, B, and C (A, B, and C are not really running level)
3. The action field tells init how to process the process specified by the process field. The values and corresponding actions of the action field are as follows:
1) respawn: if the process specified by the process field does not exist, start the process. init continues to scan the subsequent processes in the inittab file. When the process ends, init restarts it. If such a process already exists, nothing will be done.
2) Wait: start the process specified by the Process Field and wait until the processing is completed to process the next record in the inittab.
3) Once: start the process specified by the Process Field and process the next record item before the process ends. When such a process is terminated, it will not be restarted. When it enters the new running level, if such a process is still running, init will not restart it.
4) boot: init processes such records only when the system is started. It starts the corresponding process and processes the next record item without waiting for the processing to complete. When such a process is terminated, the system does not restart it.
5) bootwait: After the system is started, it processes such records when it enters multi-user mode for the first time from single-user mode. init starts such a process and waits until its processing ends, then process the next record item. When such a process is terminated,
The system does not restart it either.
6) powerfail: When init receives a power-off signal (sigpwr), IT processes the specified process.
7) powerwait: When init receives a power-off signal (sigpwr), IT processes the specified process and checks other record items until the processing ends.
8) off: if the specified process is running, send it a sigterm warning signal. init waits for 5 seconds before it sends a signal to sigkill to force it to end. If such a process does not exist, ignore this item.
9) OnDemand: the respawn function is used only for record items whose rstate field is A, B, and C.
10) sysinit: the specified process is executed before accessing the console. Such record items are only used for initialization of certain devices.
In order to enable init to ask the user about the running level on such a device, it is necessary to wait until the process finishes running before init continues.
11) initdefault: Specifies a default running level. This item is scanned only when init is called at the beginning. If the rstate field specifies multiple running levels, the maximum number is the default running level. If the rstate field is empty, init considers the field to be 0123456, and then enters Level 6, which leads to a loop, if the inittab file does not contain the initdefault record item, you are requested to specify an initial running level for it at system startup.


4. The process in the process field can be any waiting process, executable script or program.

In addition, you can add new record items in the file inittab at any time. Level Q/Q does not change the current running level, and re-check the inittab file, you can run the init Q or init Q command to immediately re-read and process the file inittab. These are the standard Linux System V standards described above, so it is not useful for embedded systems! Here, we will introduce embedded, that is, for busybox init:
Init of busybox

In addition to basic commands, busybox also supports the init function. Like other init functions, busybox init also completes system initialization and pre-shutdown, we know that after the Linux kernel is loaded, the machine transfers the control to the kernel. After the Linux kernel is started, it does some work and finds the INIT program in the root file system, and execute it. The INIT process of busybox will perform the following tasks in sequence:

(See <build an embedded Linux system> P201)

1. Set the signal processing process for init
2. initialize the Console
3. Analyze the/etc/inittab File
4. Execute the system initialization command line. By default,/etc/init. d/RCS will be used.
5. Execute all inittab commands that cause init to be paused (Action type: Wait)
6. Execute all inittab statements that are executed only once (Action type: Once)


Once the above work is completed, the INIT process cyclically executes the following processes:

1. Execute all inittab commands that must be restarted upon termination (Action type: Once)
2. Execute all the inittab commands (Action type: askfirst) That must be restarted at the time of termination)
After the console is initialized, busybox checks whether the/etc/inittab file exists. If the file does not exist, busybox
The default inittab configuration is used, which is mainly used for system reboot, system suspension, and default setting of init restart.
It also sets the shell startup action for the four virtual consoles (tty1 to tty4. If these device files are not created, busybox reports an error.
The format of each line in the inittab file is as follows: (the example folder under the root directory of busybox contains a detailed example of the inittab file)


ID: runlevel: Action: Process

Although this format is similar to the traditional sytem v init, ID has different meanings in the init of busybox. For busybox, ID is used to specify the control tty of the startup process. If the started process is not an interactive shell, such as the SH (Ash) of busybox, there should be a control TTY. If the control tty does not exist, the SH of busybox will report an error. Busybox will ignore the runlevel field completely, so leave it empty. You may ask why it is useless. I guess it is just for the sake
Keep sytem v init in the same format. The process field is used to specify the path of the program to be executed, including
Command line options. The action field is used to specify one of the eight actions that can be applied to the process in the following table.


Sysinit: Provides the initialization command line path for init.


Respawn: restarts whenever the corresponding process is terminated.


Askfirst: similar to respawn, but it is mainly used to reduce the number of terminal applications executed on the system. It will prompt init to display "Please press enter to active this console" Information on the console, and wait for the user to press enter before restarting

Wait: indicates that init can be executed only after the corresponding process is completed.


Once: Only execute the corresponding process once, and will not wait for it to complete


Ctratldel: When you press CTRL + ALT + Delete, the corresponding process is executed.

Shutdown: when the system is shut down, execute the corresponding process
Restart: When init restarts, execute the corresponding process. Generally, the process executed here is INIT itself.


The following is the inittab file of My USB Linux

: Sysinit:/etc/init. d/RCS
: Respawn:/sbin/Getty
115200 tty1
Tty2: askfirst:-/bin/sh
Tty3: askfirst:-/bin/sh
: Restart:/sbin/init
: Ctrlaltdel:/bin/umount-a-r
This inittab performs the following actions
1. Set/etc/init. d/RCs to the system initialization file.
2. Start a login session on the virtual terminal tty1 of 115200 BPS (note the usage of Getty)
3. Start the shell of askfirst action on the virtual terminal tty2 and tty3
4. If init restarts, set/sbin/init to the program it will execute.
5. Tell init to uninstall all file systems by running the umount command when the system is shut down.
To protect the file system.
1. The inittab of busybox is different from the inittab used by PC. The first ID is not a random name. The name must correspond to the file in the/dev/directory.
Corresponding error
Can't open/dev/0: no such file or directory
Process '-/bin/Sh' (PID 789) exited. Scheduling for restart.
Can't open/dev/0: no such file or directory
Process '-/bin/Sh' (PID 793) exited. Scheduling for restart.
2. the following error occurs:
Process '-/bin/Sh' (PID 789) exited. Scheduling for restart.
Process '-/bin/Sh' (PID 794) exited. Scheduling for restart.
Process '-/bin/Sh' (PID 796) exited. Scheduling for restart.
Process '-/bin/Sh' (PID 798) exited. Scheduling for restart.
The corresponding inittab file contains
Ttys0: askfirst:-/bin/sh
Although there is a ttys0 device in the/dev/directory, this device is obviously unavailable, so the above error will occur.
3. When the inittab simultaneously defines two statements for logging on to the same serial port terminal
: Askfirst:-/bin/sh
S3c2410_serial0: 23456: respawn:/sbin/Getty-l s3c2410_serial0 115200 VT100
The scenario is to be preemptible and cannot receive any serial port input.
4. Bad inittab entry
Most of the time is caused by invalid characters.
5. The runleve field in busybox does not have the runtime level concept.
6. Analyze the Startup Process
1. Set the signal processing process for init
2. initialize the Console
3. Analyze the/etc/inittab File
4. Execute the system initialization command line. By default,/etc/init. d/RCS will be used.
5. Execute all inittab commands that cause init to be paused (Action type: Wait)
6. Execute all inittab statements that are executed only once (Action type: Once)
Once the above work is completed, the INIT process cyclically executes the following processes:
1.
Execute all inittab commands that must be restarted upon termination (Action type: Once)
2.
Execute all the inittab commands (Action type: askfirst) That must be restarted at the time of termination)
After the console is initialized, busybox checks whether the/etc/inittab file exists. If the file does not exist, busybox
The default inittab configuration is used, which is mainly used for system reboot, system suspension, and default setting of init restart.
It also sets the shell startup action for the four virtual consoles (tty1 to tty4. If these device files are not created,
Busybox reports an error.
7. What is "-" on the Internet?
I am wondering:
: Respawn:-/bin/sh
What is this? Why is there sometimes ???
Also, I can see a routine from the Internet, as shown in the following excerpt:
: Respawn:-/bin/sh
Tty2: askfirst:-/bin/sh
I don't know the differences between the two. In this way, the console is started. Is the first or second sentence started? The console = ttys0 in the kernel startup parameters will automatically come to this console ???

During the test, the "-" statement will call the profile file in the/etc/directory after logging on to the terminal.
The script is not executed.
In fact, there are several convenient terminal login commands, but the standard is to use Getty to log on, but the above statement can also be used directly, and the compatibility is stronger, because it does not need to specify the corresponding serial port device.
: Askfirst:-/bin/sh
S3c2410_serial0: askfirst:-/bin/sh
: Askfirst:-/bin/sh
S3c2410_serial0: 23456: respawn:/sbin/Getty-l s3c2410_serial0 115200 VT100
All are available.
8./bin/sh: XXX not found
Arm-Linux-readelf-D xxx
Check which libraries your program depends on. This is generally caused by the lack of libc. so.6. The root file system is still a problem, and the common library files are not copied to the/lib directory.
Common libraries:
[Root @ centos lib] CP/usr/local/ARM/3.4.1/ARM-Linux/lib/LD *.
[Root @ centos lib] CP/usr/local/ARM/3.4.1/ARM-Linux/lib/libc-2.3.2.so.
[Root @ centos lib] CP/usr/local/ARM/3.4.1/ARM-Linux/lib/libc. so.6.
[Root @ centos lib] CP/usr/local/ARM/3.4.1/ARM-Linux/lib/libm *.
[Root @ centos lib] CP/usr/local/ARM/3.4.1/ARM-Linux/lib/libcrypt *.
9. Error insmod: chdir (2.6.26.6): no such file or directory
Someone on the Internet proposed this solution:
Note that commands for Loading modules such as insmod must be run from LIB/modules/2.6.26.6.
To load the module, you must first create this directory, and then put the module under this directory, otherwise the following
Two cases:
First, the LIB/modules/2.6.26.6 directory is not created,
Depends on the kernel version number,
Insmod: chdir (2.6.26.6): No
Such file or directory Error
The second is to simply put the module in the root directory or other folders without copying it to the specified lib/modules/2.6.26.6.
Directory.
Insmod: module 'gpio _ Driver 'Not Found error
However, this method is not very effective.
The root cause is the insmod problem. When compiling busybox, refer to the following options. Do not use
LINUX module utilities --->
[] Simplified modutils
// Do not select this option
[*] Support version 2.6.x linux kernels
// Select this option
Refer to the following:
10. The "-h" command cannot be executed.
No response was made when XXX-H was executed. Common library files are missing in the lib directory.
Refer to the following:
[Root @ VM-dev rootfs] # ls lib/
Ld-2.3.6.so
Libnss_files.so.2
Libc-2.3.6.so
Ld-linux.so.2
Libnss_hesiod-2.3.6.so
Libanl-2.3.6.so
Libnss_hesiod.so.2
Librt-2.3.6.so
Libnss_nis.so.2
Libgcc_s.so
Libthread_db.so.1
Libcrypt-2.3.6.so
Libpcprofile. So
Libgcc_s.so.1
Librt. so.1
Libcrypt. so.1
Libpthread-0.10.so
Libsegfault. So
Libnsl. so.1
Libnss_compat-2.3.6.so
Libutil-2.3.6.so
Libm-2.3.6.so
Libutil. so.1
Libnss_compat.so.2
Libanl. so.1
Libnss_nis-2.3.6.so
Libc. so.6
Libpthread. so.0
LibBrokenLocale-2.3.6.so
Libnss_nisplus-2.3.6.so
Libbrokenlocale. so.1
Libnss_nisplus.so.2
Libresolv. so.2
[Root @ VM-dev rootfs] #
Libtermcap. so.2
Libdl-2.3.6.so
Libresolv-2.3.6.so
Libmemusage. So
Libnss_dns-2.3.6.so
Modules
Libm. so.6
Libnss_dns.so.2
Libtermcap. so.2.0.8
Libdl. so.2
Libthread_db-1.0.so
Libnsl-2.3.6.so
Libnss_files-2.3.6.so

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.