Transfer-linux Start-up process (Inittab, Rc.sysinit, RCX.D, rc.local)

Source: Internet
Author: User
Tags crypt number sign terminates

http://blog.chinaunix.net/space.php?uid=10167808&do=blog&id=26042 1) BIOS self-test
2) Start Grub/lilo
3) Loading the kernel
4) Executing the INIT process
5) initialization via/etc/inittab file
6) Login to Linux

1) BIOS self-test
A) POST (Power on Self test), hardware detection
The computer is self-checking by the BIOS after power-on, the so-called post (Power on Self Test), which detects the hardware
Read "Boot block" from hard disk, floppy disk, or CDROM based on boot sequence set in BIOS
In a PC, Linux starts at address 0xffff0 in the BIOS
The first step in the BIOS is a power-on self-test (POST), which detects the hardware
The second step is to enumerate and initialize the local device.
The BIOS consists of two parts: The post code and the runtime service
When the post is finished, it is cleaned out of memory, but the BIOS runtime service remains in memory and the target operating system can use these services
To boot an operating system, the BIOS runtime searches for the active and bootable device in the order of the CMOS settings: Floppy disk, CD-ROM, partition on hard disk, a device on the network, USB (usually Linux is booting from hard disk
Master boot Record MBR contains the master boot loader. The MBR is a 512-byte sector that is located in the first sector on disk (0 0 Cylinder 1 sectors), and when the MBR is loaded into RAM, the BIOS gives control over to the MBR

b) extracting information from the MBR
To see the contents of the MBR, use the following command
Reads the first 512 bytes of content #从/dev/sda and writes it to a Mbr.bin file
[[email protected] pam.d]# dd IF=/DEV/SDA of=mbr.bin bs=512 count=1

#以十六进制和ASCII码格式打印这个二进制文件的内容
[Email protected] pam.d]# Od-xa Mbr.bin
0000000 48eb 0090 d08e 00BC fb7c d88e b9fc 0080
K H dle nul so P 2) Start Grub/lilo
Both grub and Lilo are boot loaders, which boot the operating system. When the machine boots its operating system, the BIOS reads the first 512 bytes (that is, the Mbr:master boot record) on the boot media

3) Loading the kernel
When the kernel image is loaded into memory, the kernel phase is added.
The kernel image is not an executable kernel, but a compressed kernel image. Usually it is a zimage (compressed image, less than 512KB) or bzimage (larger compressed image, greater than 512KB), which is compressed in advance using zlib
In front of this kernel image is a routine that implements a small amount of hardware setup, extracts the kernel contained in the kernel image, and then puts it into high-end memory, if there is an initial RAM disk image, moves it into memory and indicates later use, then this routine invokes the kernel and starts booting the kernel boot process
In the Grub command, we can use the INITRD image to boot a specific kernel, as follows:
Grub> kernel/bzimage-2.6.14.2
[Linux-bzimage, setup=0x1400, size=0x29672e]

Grub>initrd/initrd-2.6.14.2.img
[Linux-initrd @ 0x5f13000, 0xcc199 bytes]

grub> Boot
Uncompressing Linux ... Ok, booting the kernel.

If you do not know the name of the kernel to boot, just use/and then press the TAB key to display the kernel and INITRD image list

Encrypting the Grub command line
A) Use the command/sbin/grub-md5-crypt to generate the password used by grub
[Email protected] pam.d]#/sbin/grub-md5-crypt
Password:
Retype Password:
$1$3ybpf$zfvry6j8vxnr9ok4fxrkr1
b) Modify/etc/grub.conf join password--md5 $1$3YBPF$ZFVRY6J8VXNR9OK4FXRKR1 must be placed before title
When you restart the system when you want to press the e command to edit the Grub menu, you must first press the P key to enter the password.

4) Executing the INIT process
The init process is the starting point for all processes, and the kernel, after completing the kernel boot, loads the INIT program in this thread (process) space with a process number of 1
The init process is the initiator and controller of all processes
The INIT process has two functions:
Play the role of ending the parent process: All orphan processes will be taken over by the INIT process
Run the appropriate program at a specific runlevel to manage the various run levels, defined by the/etc/inittab file.

5) initialization via/etc/inittab file
The init process is performed according to/etc/inittab to execute the corresponding script for system initialization, such as setting the keyboard, font, loading module, setting up the network, etc. for Redhat, in the following order
A) Execute/etc/rc.d/rc.sysinit (the first script executed by Init)
This step can be done by:
Setting the $path variable
Configure the Network
Start swapping for virtual memory
Set the host name of the system
Check the root file system for necessary repairs
Check the root file system quota
To open quotas for users and groups for the root file system
Re-loading the root filesystem in read/write mode
Clears the mounted File system table/ETC/MATB
Enter the root file system into mTAB
Using the system to prepare for loading modules
Find related files for a module
Check the file system for necessary repairs
Load all other file systems
Clear several/etc files, such as/etc/mtab,/etc/fastboot, and/etc/nologin
Delete the UUCP lock file
To delete obsolete subsystem files
To delete outdated PID files
Setting the system clock
Open Swap
Initializing the serial port
Loading modules

b) Implementation of/etc/rc.d/rcx.d[ks]
First terminates the service (used to shut down a service) starting with K, and then starts the service that begins with S (to start a service)
For each runlevel, there is a subordinate directory in the/ETC/RC.D subdirectory.
These run-level subordinate subdirectories are named on the method Rcx.d, where x is the number representing the run level
In each run level subdirectory, a symbolic link to the command script in the/ETC/RC.D/INIT.D subdirectory is established
The name of the link after K and S has a number, indicating the order of execution, the number of small first performed such as K01tog-pegasus, S00microcode_ctl
The system passes the stop parameter to a script that starts with K, and the script system that starts with s passes the start parameter

c) Implementation of/etc/rc.d/rc.local
Redhat run mode 2,3,5 the/etc/rc.d/rc.local as the last file in the Init script, so users can add in this file their own commands that need to be executed before landing after other initialization work


6) Execute/bin/login
The login program will prompt the user to enter the account number and password, and then code and confirm the correctness of the password, if the two are consistent, users to initialize the environment, and give control to the shell, that is, and so on.

----------------This, the Linux boot process is all over----------------------
Linux Init detailed
"Uuno on Numero yksi" (Slogan for a series of Finnish movies.)
This chapter describes InitProcess, which is the first user-level process that the kernel initiates. InitThere are many important tasks, such as starting Getty(for user logons), implementing RunLevel, and handling orphaned processes. This chapter explains how to configure the InitAnd how to use different levels of operation.
 
The first step
Init
For the operation of the Linux system, InitProgram is one of the most basic procedures. But you can still do most of the law. A good Linux distribution usually comes with a InitConfiguration, this configuration is suitable for the work of most systems, and in some systems it is not necessary to InitDo anything. Typically, you only need to be concerned when you encounter a modem such as a serial terminal that hangs up, dials in (not dial out), or you want to change the default runlevel. Init
After the kernel has booted itself (it has been loaded into memory, has started running, has initialized all device drivers and data structures, and so on), by starting the user-level program InitTo complete the kernel portion of the boot process. So InitAlways the first process (its process number is always 1).
The kernel searches in several locations Init, these positions were used previously to place InitBut InitThe most appropriate location (on a Linux system) is/sbin/init. If the kernel does not find Init, it tries to run the/bin/sh, and if it fails, the system starts to fail.
When InitStarts running, it ends the boot process by performing some administrative tasks, such as checking the file system, cleaning/tmp, starting various services, and launching for each terminal and Virtual Console Getty, where users will be logged into the system (see chapter eighth).
After the system is fully up, InitRestart for each terminal that the user has exited Getty(This will allow the next user to log in). InitAlso collects isolated processes: When a process initiates a child process and terminates before the child process, the child process becomes immediately InitSub-process. This is important for a variety of technical reasons, and it's good to know that because it's easy to understand the process list and the process tree diagram. [1] InitHave few variants. Most Linux distributions use Sysinit(by Miguel van Smoorenburg), which is based on the System V InitDesign. The BSD version of Unix has a different Init。 The main difference is the operating level: System V has and BSD does not (at least traditionally). This difference is not the main. Here we discuss only Sysvinit
 
Configure Init to start the Getty:/etc/inittab file

When InitAfter startup, InitRead the/etc/inittab configuration file. When the system is running, if a hup signal is emitted, InitWill reread it; [2] This feature makes the InitConfiguration file changes do not need to restart the system to work.
The/etc/inittab file is a bit complicated. We will configure the GettyThe simple case of the line. The rows in the Etc/inittab are made up of four colon-qualified fields:
Id:runlevels:action:process
The individual domains are described below. In addition,/etc/inittab can contain blank lines and lines that begin with a number sign (' # '), which are ignored.

ID

This determines the line in the file. For GettyLine, specifies the terminal on which it runs (the character after the device file name/dev/tty). For other rows, it is meaningless (except for the length limit), but it must be unique.

Runlevels

The run level that the row should consider. The run level is given as a single number with no delimiter. (The run level is discussed in the next section.) )

Action

For the action that the line should take, that is, respawn runs the command in the next domain again, when it exists, or only once.

Process

The command to run.
In order to run on the first virtual terminal (/DEV/TTY1) Getty, in all normal multi-user runlevel (2-5), the following line should be written:
1:2345:respawn:/sbin/getty 9600 tty1
The first field indicates that this is the row that corresponds to/dev/tty1. The second field indicates that it applies to runlevel 2,3,4 and 5. The third domain is that after the command exits, it should be executed again (so that the user can log on, exit, and log on again). The last domain is run on the first virtual terminal Getty's command. [3]
If you need to add a terminal to the system or dial in a modem line, you should add more rows to the/etc/inittab, one for each terminal or one dial-in line. For more information, see Init, Inittab and GettyThe manual page.
If a command fails while running, and Init is configured to run it again, it uses many system resources: Init runs it, it fails, Init runs it again, fails again, and so on, endlessly. To avoid this, Init will track how many times a command has been re-run, and if the frequency of the re-operation is too high, it will be delayed for five minutes before it runs.
A Run level ( Run level) is the state of Init and the system as a whole, which defines what system services can be provided. The runlevel is defined by numbers, as shown in table 7-1. There is no consistent opinion on how to use user-defined RunLevel (2 to 5). Some system administrators use RunLevel to define which subsystem works, that is, whether X is operational, whether the network works, and so on. Others always let all subsystems work or run separately and stop them without changing their runlevel, because the runlevel is too rough to control their systems. You have to decide for yourself, but it might be easiest to follow your Linux distribution.
Table 7-1. Number of Run levels
0
Termination system
1
Single-user mode (for special Administration)
2-5
Normal operation (user defined)
6
Restart
The run level is configured in/etc/inittab by the lines shown in the following line:
L2:2:WAIT:/ETC/INIT.D/RC 2
The first field is any given symbol, and the second field indicates that it is run Level 2. The third field describes when the run level is entered, InitThe commands in the fourth field should be run once, and InitShould wait for it to end. At run Level 2 o'clock, the/ETC/INIT.D/RC command runs or stops the service when needed.
The commands in the fourth domain do all the hard work of setting a run level. It starts a service that is not yet running, and stops services that should not run in the new RunLevel. Exactly what the command is and how the RunLevel is configured depends on the individual Linux distributions.
When InitWhen it starts running, it looks for a row in/etc/inittab that specifies the default run level:
Id:2:initdefault:
By giving the kernel a single or emergency command-line argument, you can InitRun starts at a non-default run level. For example, kernel command line parameters can be given by Lilo. This allows you to select single-user mode (Run Level 1).
When the system is running, Telinitcommand to change the run level. When the runlevel changes, init runs the corresponding command in/etc/inittab.
 
Special configurations in the/etc/inittab

/etc/inittab has some special features that allow InitRespond to a particular environment. These distinctive features are marked in the third field by the keyword. Some examples are as follows:

Powerwait

When system power fails, allow InitShut down the system. This assumes the use of UPS and software to monitor ups and notify Init of power failure.

Ctrlaltdel

When the user presses the Ctrl-alt-del key combination on the console, it allows InitReboot (boot) boot system. Note that the system administrator can configure what the response to the Ctrl-alt-del key combination is, for example, ignore it if the system is in a public environment (or start NetHack。 )

Sysinit

The command to execute when the system boots. For example, this command is usually cleaned/tmp.
Not all of them are listed above. For all the keywords and how to use them, see Inittab manual page.
 
Boot (boot) into single-user mode

A very important runlevel is single-user mode ( Single user mode(Run Level 1), in this mode only the system administrator is using the machine and only a few system services are running, such as logon service. Single-user mode is required for some administrative tasks, [4] if running on/usr partition fsck, because this requires that the partition not be loaded, which is not possible unless almost all of the system services are terminated.
Pass TelinitRequest Run Level 1, a running system can be converted to single-user mode. At boot time, you can enter single-user mode by giving the command line on the kernel (emergency): The kernel also gives the command line InitInitWill understand the word and will not use the default runlevel. (The kernel command-line Input method relies on how the system is booted.) )
Booting into single-user mode is sometimes required before loading the file system, so that it can be run manually fsckcommand, otherwise it is likely to damage the/USR partition (any operation on a problematic file system will further damage it, so fsckTo run as soon as possible).
If the automatic check of fsck fails at startup, start the profile Initwill automatically enter single-user mode. This is an attempt to prevent the system from using a file system that is too corrupt to be able to automatically fix it. This kind of destruction is fairly rare, usually with a hard drive or a kernel version, but it's better to be prepared than not.
As a security measure, a properly configured system should require a password before the shell running the single-user mode. Otherwise, it is easy to enter the system as root as long as the appropriate line parameter is entered for Lilo. (Of course, this is not the case if the/etc/passwd is destroyed due to a file system problem.) If that's the case, you'd better have a bootable floppy on hand. )

Transfer-linux Start-up process (Inittab, Rc.sysinit, RCX.D, rc.local)

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.