Introduction to the CentOS boot-up process

Source: Internet
Author: User
Tags network function

we all know that after pressing the computer power button, the screen will flash over a lot of information, and then display the login screen, and then enter the user name, password to enjoy the network world. So what's going on in this middle of the day, let's talk a little bit about CentOS's starter boot process.

Phase one: power-on self-test process

We all know that the computer all the data instructions are in memory to be processed by the CPU, we also know that the memory in the power after the loss of all the data on it, then the boot when the memory should be nothing, it can not dry, let alone start an operating system, actually Ah, Our memory is not just our common memory card, many hardware will map a memory to the CPU address space, such as BIOS, video card and so on, and we know that the BIOS is written on the motherboard chip, and is made of Flash ROM, although can also modify the data inside, But we are still accustomed to call it read-only memory, then the problem also comes, after the power, the CPU how to know in memory which address segment is the BIOS code snippet, this is because the CPU at the time of production settings, when the power instantaneous, the CPU will enter the real mode state, and then the memory address control in about 1MB appearance, Then the IP register and CS Register will point the address to a location in memory (only need to know in one location, because it's just a brief introduction), and this position is exactly where the BIOS code snippet started, and then it is obvious that the CPU began to execute the code, Then you will see the various BIOS self-test information we are familiar with, of course, the most important thing is to generate the interrupt vector table in memory (the location of the interrupt vector program is recorded in the deposit) and interrupt vector program, and we have set the BIOS bar, at least set the boot option inside it, is to set the system you want to start the hard drive as far as possible to the front position (because the BIOS only recognized the first), this is because when the BIOS detects that the drive contains an operating system, it will send a interrupt signal to the CPU, The CPU then locates the interrupt vector program in the memory interrupt vector table by name, then executes this part of the program, then the program will load the first sector of our hard disk (512 bytes also called MBR) into memory, We also know that the first 446K of the MBR of the hard disk is the boot program code, the middle 64K is the partition table of our hard disk, the last 2 bytes is the MBR valid flag (if 55AA is valid, the BIOS is through this to determine whether there is an operating system on the hard disk), Then the BIOS went to doze off, did the Shang, put together to the boot program this shop small two.

Second stage: bootloader Loading kernel procedure

We all know that there is no driver hardware can only self-entertainment, and the hard disk must be formatted into a file system in a format to store things under the operating system, then the boot program this shop small two want to load the operating system on the hard disk must have a driver to support this file system format, Unfortunately, only 446K of space is not possible, so there will be this driver in the subsequent sector of the MBR, and then the second stage to find his true love, in Linux is usually in the/boot/vmlinuz-version-hair model, The kernel is then decompressed and loaded into memory (the kernel is just a program).

Phase three: Kernel load to PID 1 process init process

The kernel is loaded into memory to start running, but the same problem comes again, the operating system on the hard disk must be a file system to hold the data, then it is possible to write all the file system drivers are written to the kernel, of course, but can not, because then not only the kernel will be particularly large, And a machine can only use a very small part of it, so it is not possible, but after writing it can also achieve the purpose, so it is possible, while Linux is a single core, but it fully absorbed the micro-core of the advanced concept, to support the dynamic loading module, the above meaning, Is that many functions can be written into a module, and then loaded into the kernel can be, of course, can be directly compiled into the kernel, and even some modules must be compiled into the kernel. And a lot of drivers are written into the module, just keep the basic functions on the line. (Please note, I am not holding windows here, although it is a micro-kernel, but also because of this so that it must write more code in order to achieve internal coordination, and thus become very bloated and prone to problems, so the word spicy chicken is most suitable for the above), but then that will not solve the boot operating system Ah, In fact, the kernel will use Randis technology in memory to virtualize a portion of the memory into hard disk use, through this virtualization of a small root file system, you can see if your/boot is not there is a initramfs-version-hair model of the file (version and hairstyle number and the same as the kernel in the CentOS 5 is initrd-version-hair model, if you look at the file below, you will find that it is a small file system, through this to load the file system driver, and then to load the real root file system, immediately after the operation of the operation, generate process No. 0, And then, because he's got nothing to do, he's going to have a son. 1th process Init, the son is much more powerful than dad (though still a bad brain, but at least the limbs are good)

Stage four: Process 1th, what did the init do?

On CentOS 5: Init himself has just opened the light, learn the father, but he is more ambitious than his father, because he will have a litter son, until his sons to form a complete operating system (Linux through the fork () copy, exec () run the process will be more powerful than his father), First of all, this will be very "axis", not to find/etc/inittab this file, which is the main definition of the default terminal, system initialization, shutdown and open the corresponding terminal program , and then get the terminal can be logged in . Format is

ID: Default Terminal level: Action:process

The default terminal levels are:

                0: Shutdown, shutdown
                1: Single user mode, root user, no authentication, maintenance mode,
                2, multiuser mode (multi user), will start the network function, but will not start NFS; maintenance mode;
                3, multiuser mode (mutli user), full function mode, text interface;
                4, Reserved level: Currently no special use purposes, but the habit of using the same 3-level function;
               5, multi-user mode (multi user), full function mode, graphical interface;
               6, restart, reboot

Action

Wait: Executes once while waiting to switch to the level at which the task is located;
Respawn: Once this task is terminated, it will be restarted automatically;
Initdefault: Sets the default RunLevel, at which time the process is omitted;
Sysinit: Set the system initialization mode, here is generally designated/etc/rc.d/rc.sysinit script;

Process

/ETC/RC.D/RC[0-6], turn off the k# #开头的程序 at the appropriate terminal level, turn on the s# at the appropriate terminal level #开头的程序, if you ll find the files below are all links to/INIT.D except the k# #和S # #的同名程序.

Then the order is, the first ID: The default terminal level: Initdefault:, to know the default terminal, then the Si::sysinit:/etc/rc,d/rc.sysinit, to initialize, and then the ID number: Default terminal level: wait:/etc/ RC.D/RC[0-6], to enable the shutdown of the corresponding terminal under the service script, and finally TTY[1-6]: default terminal level: Respawn:/usr/sbin/mingget tty[1-6], to obtain the login terminal.

The contents of the initialization implementation are:

(1) Set the host name;
(2) Set welcome information;
(3) Activate Udev and SELinux;
(4) Mount all file systems defined in the/etc/fstab file;
(5) Detecting the root file system and re-mounting the root file system in read-write mode;
(6) Set the system clock;
(7) Set kernel parameters according to/etc/sysctl.conf file;
(8) activating LVM and soft raid devices;
(9) Activate swap device;
(10) Loading the drivers for additional devices;
(11) Cleaning operation;

Finally executes the job inside the/etc/rc.d/rc.local, this file does not link to any script under the/ETC/INIT.D directory, he just wants to let the person who does not want to write the script to realize the boot service lazy

So how to write a script that can run or shut down. In fact, just look at the/ETC/INIT.D or/ETC/RC.D/INIT.D (front just link to the back) of the script will know, in the beginning of the script to add #chconfig: terminal (can be multiple): priority: Turn off the priority level, Then this script can be managed by the Chconfig command, of course you have to get this script to/ETC/INIT.D or/ETC/RC.D/INIT.D, you can link or directly built in this directory. The corresponding k# #开头和S # #开头的文件 is then automatically generated through the Chconfig--add script name added to the corresponding terminal level/etc/rc.d/rc[0-6] directory. You can then run the Restart View with service script name {Start|restart|status|stop} to stop the services script.

Chkconfig command

Chkconfig--list [script name]: View its turn-off status at each terminal level

Chkconfig--add script Name: Generate the specified script under the corresponding terminal k# #开头和S # #开头的的文件了, in fact, chkconfig program name on/off is the mechanism, but just so that no other terminal generation files, The open or close file is generated only in the terminal specified by the script.

Chkconfig--del script Name: The opposite of the above.

Chkconfig--level Specify terminal (can be multiple, default is 2345) script name on/off. This is called the boot Run and shutdown, in fact, in the corresponding terminal generated s# #文件和K # #文件罢了.

In addition, if the terminal level in the script-indicates that all terminal levels are turned off (generate k## only), the corresponding files are generated for the other numbers in the corresponding/etc/rc.d/rc[0-6] on those terminals.

k# #的这两个数字表示的是停止优先级, the smaller the number, the higher the priority to stop, which means dependent on other programs

s# #的这两个数字表示开启优先级, the smaller the number, the higher the priority to start, indicating that it is dependent on other programs

The upstart on CentOS 6 is not the 5 classic sys V, but it is still compatible with 5, so its/etc/inittab is still valid, only the default terminal is set, so only the ID: Specify the default level: Initdefault:

But it shows that the init script in/etc/init/rcs.conf, the script configuration file to turn the corresponding terminal level on and off is/etc/init/rc.conf, and then look at the two files to see if they point to the script in the/etc/rc.d/directory. So there's nothing to say, just know that 5 the configuration file above is/etc/inittab, and 6 of the configuration files are/etc/inittab and/etc/init/*.conf, but their scripts are/ETC/INIT.D (/etc/rc.d/ INIT.D)

The systemd used on CentOS 7, the change is very big, but still can be compatible with 5,6, especially 5, its configuration file in

/etc/systemd/system and/usr/lib/systemd/system. It has been said that although the change is great, it does not mean that it cannot be used like 5,6. Therefore, to be continued in this respect .....

Introduction to the CentOS boot-up process

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.