Linux File System Startup Analysis

Source: Internet
Author: User
Tags sigint signal

File:
1. Run/linuxrc first after the kernel is started.
/Linuxrc content:
#! /Bin/sh
Echo "Mount/etc as ramfs"
/Bin/Mount-n-t ramfs/etc
/Bin/CP-A/mnt/yaffs/etc/*/etc // when shutdown, we will save the/etc content to/mnt/yaffs/etc.
Echo "re-create the/etc/mtab entries"
# Re-create the/etc/mtab entries
/Bin/Mount-F-T cramfs-O remount, RO/dev/mtdblock/2/
/Bin/Mount-F-T ramfs/etc
Exec/sbin/init
First, you need to understand this linuxrc,
1./bin/Mount-n-t ramfs/etc
Load a ramfs as the/etc directory. In this way,/etc is a writable directory.
Check this script to find that your root file system is a cramfs, a read-only file system, and/etc is used as the storage location of the system running configuration file, some running states may be written here. The first thing in linuxrc is to mount a ramfs to the/etc read-only directory so that the/etc/directory can be writable, the purpose of specifying the-n parameter is to tell mount not to write/etc/mtab. This file is stored in all the file systems mounted by the current system.
Because the/etc/directory is still read-only, do not write this file for this mount, otherwise it will fail. Where is the ramfs you asked? There should be a ramfs in your/etc/fstab file. Mount will find this option. If not, mount will fail. It cannot be executed later.
2./bin/CP-A/mnt/yaffs/etc/*/etc
After/etc becomes a writable directory, copy all configuration files in/mnt/yaffs/etc to/etc/. This indicates that your ramfs may be an empty ramfs, there is no configuration file, or the configuration file is old. It also indicates that your system is a read-only system, and the configurations written in each system operation will not be retained.
Re-write the previously mounted information to the/etc/mtab. The command is as follows.
3./bin/Mount-F-T cramfs-O remount, RO/dev/mtdblock/2/
The commands/bin/Mount-F-T ramfs/ETC only write the mount information to the/etc/mtab and do not actually mount these Block devices, it indicates that your root file system is still the previous one/dev/bon/2.
4. exec/sbin/init
Execute the init execution program in the root file system to make it process 1. Shell is officially run.
######################################## ######################################## ###
/Etc/mtab: mtab is in the same format as/etc/fstab. It is used to record information about mounted partitions.
Note: If the file/linuxrc is not available,/sbin/init is run first by default.
######################################## ######################################## ###
2. We can see from the/linuxrc file that it finally runs/sbin/init, and init will run according to/etc/inittab.
Inittab file entry format:
ID: runlevels: Action: Process
ID: the unique identifier of the entry in the inittab file, which must be 1-4 characters long. (If the sysvinit program is compiled with a library version earlier than 5.2.18 or a. Out, it must be 2 characters long ).
Note: For Getty or other registration processes, the ID must be the TTY Suffix of the response terminal line, for example, 1 responds to tty1. Otherwise, the registration process cannot work normally.
Runlevels:
#0-halt (do not set initdefault to this)
#1-Single User Mode
#2-multiuser, without NFS (the same as 3, if you do not have networking)
#3-full multiuser Mode
#4-unused
#5-X11
#6-Reboot (do not set initdefault to this)
Action describes the action to take.
Process to be executed. if the process field starts with a '+', init does not charge for this process in the utmp and wtmp files. this is because Getty needs to host utmp/wtmp accounting by itself, and it is also a legacy vulnerability.
The runlevels field can contain multiple characters that indicate different running levels. For example, 123 indicates that the process must be started when the running level is 1, 2, and 3. the runlevels domain used for the OnDemand entry can contain A, B, or C. the runlevels fields used for sysinit, boot, and bootwait entries are ignored.
When the running level is changed, the processes that are not given in the new operation level are killed. Use the sigterm signal first, and then the sigkill.
The action field can use the following actions: respawn:

Restart the process as long as it is terminated (such as Getty ).

· Wait

Start this process as long as you enter the specified running level, and init waits for the end of the process.

· Once

This process is started once at the specified running level.

 

· Boot

This process is executed during system boot. The runlevels domain is ignored.

· Bootwait

Execute this process during system boot. and init waits for the process to end (such as/etc/rc). The runlevels domain is ignored.

· Off

Do nothing.

· OnDemand

Only processes marked as OnDemand will be executed at the OnDemand running level. in any case, the running level is not actually changed (OnDemand running level is 'A', 'B', and 'C ').

· Initdefault

The initdefault entry indicates the running level that the system enters after booting. If such an entry does not exist, init will query the running level on the console. The process domain to be accessed is ignored.

· Sysinit

This process is executed during system boot. This process will be executed before the boot or bootwait entry. The runlevels domain is ignored.

· Powerwait

This process is executed when the power supply is insufficient. The INIT process is usually notified when a process connects the ups to the computer. init will wait until the process ends before continuing other work.

· Powerfail

Similar to powerwait, but init does not wait for the process to complete.

· Powerokwait

Execute this process immediately after init receives the power recovery notification.

· Powerfailnow

This process is executed when init is notified that the UPS power supply is quickly exhausted while the external power supply fails (invalid). (assuming that the ups and monitoring process can detect such a situation ).

· Ctrlaltdel

Execute this process when init receives the SIGINT signal. This means that someone has pressed the CTRL-ALT-DEL key combination on the console, typically, might want to execute something like shutdown and then enter single user mode or reboot the machine.

· Kbrequest

This process is executed when init receives a special combination of key signals generated from the console keyboard.
Inittab instance:
#/Etc/inittab
: Sysinit:/etc/init. d/RCS
Tty0: respawn:/sbin/Getty 38400 tty0
Tty2: askfirst:/bin/sh
: Ctrlaltdel:/sbin/reboot
: Shutdown:/bin/CP/etc/mnt/yaffs/etc-ra // because our root file system is read-only, you need to save/etc content
: Shutdown:/bin/umount ar
: Shutdown:/bin/Mount/o remount. ro // Mount-O remount means reload.
3. From the inittab, we can see the current system startup/etc/init. d/RCS!

Next we will introduce the RFM file.
// Content of the RCS
#! /Bin/sh
/Bin/Mount-
/Sbin/ifconfig 192.168.0.1
/Bin/echo "I am xiaoshou! "
First, we can see the Mount-a command. This command performs mounting Based on/etc/fstab.
Next let's take a look at the/etc/fstab file.
#/Etc/fstab
None/proc defaults 0 0
None/dev/PTS devpts mode = 0622 0 0
Tmpfs/dev/SHM tmpfs defaults 0 0
The file format is as follows:
# Functions of the fstab file
File/etc/fstab stores the file system information in the system. If the file is correctly set, you can use "Mount
/Directoryname "command to load a file system. Each file system corresponds to an independent line. Fields in each line are separated by spaces or tabs. Fsck,
Commands such as Mount and umount use this program.
# Fstab file format
The following is an example line of the/etc/fatab file:
Fs_spec | fs_file | fs_type | fs_options | fs_dump | fs_pass
/Dev/hda1 |/| ext2 | defaults | 1 | 1
Fs_spec-
This field defines the device or remote file system where the file system to be loaded is located. For general local Block devices, the IDE device is generally described as/dev/hdaxn, and X is the IDE device channel.
(A, B, or
C), N indicates the Partition Number, and SCSI device 1 is described as/dev/sdaxn. For NFS, the format is generally:
'Knuth. AEB. NL :/'. For procfs, use 'proc' for definition.
Fs_file-this field describes the directory point to be loaded by the file system. For a swap device, this field is none. For a directory name containing spaces, 40 is used to indicate spaces.
Fs_type-defines the file system on the device. The common file types are ext2 (common file types for Linux devices) and vfat (FAT32 format for Windows systems), NTFS, iso9600, etc.
Fs_options-specifying the file system to load the device is a specific parameter option that needs to be used, multiple parameters are separated by commas. Most systems can use "defaults" to meet their needs. Other common options include:
Option description
RO loads the file system in read-only mode
Sync does not buffer write operations on the device, which can prevent file system damage during abnormal shutdown, but reduces the computer speed.
User allows normal users to load the File System
Quota forces disk quota limit on this file system
Noauto no longer uses the Mount-a command (for example, when the system is started) to load the File System
Fs_dump-this option is used by the "dump" command to check how often a file system should be dumped. If no dump is required, set this field to 0.
Fs_pass-this field is used by The fsck command to determine the sequence of the file system to be scanned at startup. The value of the "/" pair of the root file system should be 1, other file systems should be 2. If the file system does not need to scan at startup, set this field to 0.
4. After mounting all partitions, we can add our own commands in the/etc/init. d/RCS file.
For example:/sbin/ifconfig eth0 192.168.0.1
/Sbin/ifconfig lo 127.0.0.1
Continued: I will introduce the formats of file systems such as ramfs tmpfs ramdisk cramfs jffs yaffs in my subsequent articles.

Article Source: http://www.diybl.com/course/6_system/linux/Linuxjs/200871/129571.html

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.