Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Initialization and starting process of Linux     - Linux Network Security: nmap port scanning software (Linux)

- Analyzing Linux server architecture is 32-bit / 64-bit (Server)

- Deploy Apache Spark cluster environment in Ubuntu (Server)

- Nginx concerning the location and rewrite applications proxy_pass (Server)

- ORA-28000 the account is locked fault simulation (Database)

- CentOS card fails to start at boot progress bar certmonger solve (Linux)

- Linux platform to prevent hackers to share practical skills (Linux)

- KVM virtualization nested configuration (Server)

- RedHat Linux 7 build yum source server (Server)

- How do you turn on and off IPv6 address on Fedora (Linux)

- Redhat Close SELinux correct step (Linux)

- Linux C source code (sockettype: socket descriptor determination function) (Programming)

- Ubuntu 14.04 install PostgreSQL 9.2 (Database)

- CentOS How to mount the hard drive (Linux)

- Configuring s3c-linux- appears Unable to find the QT3 installation (Linux)

- Samba file sharing server set up (Server)

- Android judgment toward camera pictures (Programming)

- Production environment Linux bonding method standby mode slave card switch (Server)

- Large computer network security policy Experience (Linux)

- Linux Network Programming - signal blocking and shielding (block, unblock) (Programming)

  Initialization and starting process of Linux
  Add Date : 2018-11-21      
  We just need to run the program click on the icon of the application can be, but before that, we must start our system. Before everything, we must have certain procedures to guide the core of our system, the procedure is the kernel boot program, such as LILO, GRUB, U-Boot, RedBoot. These boot program also needs to be loaded and run other programs, so go on, where the vast life is the end ah? Surely we can think of ---- hardware! Such a long process is complex, rugged! Everything is difficult at the beginning of the so-called positive, but not afraid, we traveled together to go!

cpu initialize itself: This is the first boot, if on a multiprocessor system, each cpu must initialize itself. After initialization cpu, cpu from a fixed location (should be 0Xfffffff0) fetch this instruction is a jump instruction, the destination is the first portion of BIOS code, but cpu does not care whether the BIOS is present, it is just to perform at this address command it!

BIOS: BIOS is read-only memory (ROM), is cured on the motherboard. Its work has two main, that is the figure that is the Power On Self Test POST (post on self test) and load the kernel boot program.

Then they completed what is the specific work?

1) Power On Self Test: Complete hardware detection system, including the memory test, the system bus inspection work.

2) load the kernel boot procedure: After POST is completed, it is necessary to load the kernel boot procedure, and that it is stored in where? Disk inside! Haha, BIOS reads 0 head 0 track, a 512-byte sector, this sector is called the MBR (Master Boot Record), MBR saved in the beginning of the kernel boot program, BIOS will be loaded into memory carried out. What is 512-byte MBR some of it? Here it is necessary to talk about MBR! MBR partition table to 80 starting in 55AA to end, a total of 64 bytes. Specific knowledge MBR own Baidu!

MBR: 1) 446 bytes of boot code

2) 64-byte partition table, how many partition it. . ? I really do not know! The partition table is divided into four, three and a bootable partition can not boot partition.

3) 2-byte 0XAA55, for checking the validity of MBR.

It should be noted that the program is loaded after the kernel boot, POST part of the code will be cleared from memory, leaving only part of the memory reserved for the target operating system in use.

Kernel boot program: kernel boot program in two parts: the primary, secondary bootstrap. Master boot program main job is to collect search to find active partition, the partition boot record of the activities of the second boot program is loaded into memory and executed. And this time the boot program is responsible for loading the kernel and passes control to the kernel. The above mentioned kernel boot program has LILO, GRUB, U-Boot, RedBoot. Wherein the first two for the pc, while the latter two are embedded.

Kernel: the kernel in compressed form, is not an executable kernel! So the kernel stage first thing to do is a self-extracting kernel image. Compressed kernel image vmlinuz talk after compiling the kernel formed here. After compiled vmlinux, will generally be compressed to vmlinuz, making zImage-- less than 512KB of small kernels, or become larger than 512KB bzImage-- large kernel.

Done so much work finally linux kernel to boot out. ! ! Let's initialize this long-awaited linux kernel!

Kernel initialization: the kernel calls a series of initialization function to initialize all of the core components from start_kernel () ---.....---> rest_init () ----..----> kernel_init () ----....--> init_post () ------ to ---> end of the first user init process.

start_kernel (): Most of the kernel initialization complete its work. Now the relevant code to the kernel source code! www.kernel.org

rest_init (): start_kernel () call rest_init () initializes the back.

kernel_init (): This function is mainly to initialize the device driver, and calls init_post () to start the init process user space.

init_post (): the end of the first user-space init initialization turned out! Its PID is always 1.

init: kernel in the past have used it to find several places for init, its correct position (for Linux systems) is / sbin / init. If the kernel can not find init, it will try to run / bin / sh, if you fail, the system will fail to start. Find / sbin / init after init according to / etc / inittab (online information say so, and I can not find Ubuntu3.8 the kernel, but can be found in Fedora! Release is different, right? (Seeking advice ) here attach picture) file to do some other work, such as:! getty process accepts the user's login, set up networks. Speak in detail here.

The system all the processes forming a treelike structure, and roots of this tree is formed in kernel mode, the system automatically configured to process number 0, which is the ancestor of all processes. Roughly vmlinux entrance startup_32 (head.S) in the original process for the pid number 0 is provided execution environment, and then the process was originally started start_kernel () to complete the initialization of the Linux kernel. Including page table initialization, initialize the interrupt vector table, the system initialization time. Then call fork (), to create the first kernel init process:

kernel_thread (kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); // Parameter CLONE_FS | CLONE_SIGHAND represent 0 and 1 thread threads are shared file system (CLONE_FS), open the file (CLONE_FILES) and signal processing procedures (CLONE_SIGHAND).

This process is known as pid init process 1 (kernel mode), it will continue to complete the remaining work to create several initialization for virtual cache and main memory management kernel threads over and, as kswapd bdflush and the like, then execve (/ sbin / init) (init process to generate user mode pid = 1, because there is no call to fork (), so pid or 1!), all processes in the system to become the ancestors of the other. Looking back the process pid = 0, and after creating the init process (kernel mode), pid = process 0 calls cpu_idle () evolved into the main cpu idle process. The kernel mode pid = init process 1 will also be generated from each of the cpu idel process. init before evolving into / sbin / init, performs some initialization work, one of which is smp_prepare_cpus (), initialize the SMP processor, in this process will be from the time each call processor

task = copy_process (CLONE_VM, 0, idle_regs (& regs), 0, NULL, NULL, 0); init_idle (task, cpu);

That is copied from init in a process, and initialize it to idle process (pid still 0). From the idle process on the processor will be a Activate work, and then do cpu_idle ().

Execute / sbin / init, so too over from the kernel to user mode, the configuration file / etc / inittab required to complete the work started, and create a number of non-numbered terminal registration process getty 1,2,3 ... numbers, its role is to set its process group identification number, monitor system terminal configuration to the interface circuit, when the signal came when, getty executes execve () generate the registration process login, registered users can log on, and if the login is successful, login shell process will evolve, if unsuccessful login close the open end of the line, the user 1 process creates a new getty. Here the init process is basically complete.

init process finished, here to talk about a rough init also done something. First to understand the run level.

Run Level: linux boot can start a different program on different occasions, which is called run level. Start different programs depending on the run level. For example, when used as a server to open Apache, while the desktop is not required.

linux preset seven kinds of run level (0--6). There are eight kinds of ubuntu (0--6, S), where it is mainly in ubuntu. 0: Turn off the system, 1: the system into single-user mode, S: single-user recovery mode, text login screen, running only a small number of system services. 2: multi-user mode (the default level), the graphical login screen, the system runs all scheduled services. 3 - 5: multi-user mode, the graphical login screen, run all scheduled services (for system customization, the run levels 2-5 are the functional equivalent), 6: reboot the system.

For each run level, the / etc / has a corresponding sub CONTENTS --- / etc / rcN.d used to specify the program to be loaded.

Carefully to see if you can find other documents are "the beginning of a two-digit + S + program name" form except README outside. This represents what? S stands for Start start. If yes, then K represents close kill, if you switch from another run level over the case will have to close the program. After the numbers as a sequential process, the smaller the sooner executed, and if the same figure, in alphabetical order starting.

The figure can be seen here files are linked files, and why? The above mentioned various operational levels have their own store a record entry for each of the boot process, if there are multiple levels to start running the same program, the script of this program will be copied to each entry in a record, doing so so, if you want to modify the startup scripts will modify each recording head, so unscientific ah! ! ! ! So these files are linked files point to /etc/init.d. When you start it is to run these scripts.

Subsystem initialization:

Kernel Options: linux kernel configuration options allow the user to pass to the kernel, the kernel calls parse_args initialization process () function to parse these options, and then call the appropriate function for processing. For parse_args () function, which is able to resolve the form of "variable name = value" strings will be called to parse the module parameters when the module is loaded.

Initializes subsystems: the completion of the parsing kernel options, you enter the function call to initialize. () Function call do_basic_setup in kernel_init () function call again do_initcalls () function to complete. Please refer to the specific implementation of each function source code!

Login: Log in three ways.

1) Command Line Login

init create getty, and other users to enter a user name and password, call the login procedure check password is entered, if correct reads / etc / passwd file, read the user's specified shell and start it.

2) ssh login

System call sshd program to replace getty and login, after starting the shell.

3) Graphical login

init process calls the Display Manager, Gnome graphical interface corresponds to gdm, then enter the user name and password, if the password is correct then starting the user session.

Here the system to start up! Having said that, now we play something fun! ! ! ! ! ! Simple familiar with linux boot! ! ! ! ! ! ! ! ! ! ! First prepare a ubuntu 13.04 or 12.04 had the best system, can be a virtual machine (preferably operate on a virtual machine! Because I was this little experiment and reinstall it again real system! At that time do not know ah! Miserable. ........).

1: enter the system, in the main folder (easy) to create a new file and name it c language init.c, enter ----> The easiest c language program helloworld, this is not the greatest c language program!

main () {

printf ( "! helloworld \ n");


Needless to say, after it is compiled. Open a terminal (ctrl + alt + t) this instruction is executed: gcc --static -o init init.c this init file is ready! Guess what I want to do yet. . ? Haha we continue! !

2: The above mentioned / sbin / init file backup this instruction is executed: sudo cp / sbin / init /sbin/init.bak backup file into init.bak

The original init file deletion, executing instructions: sudo rm / sbin / init

Well, the next step will be copied to our helloworld init / sbin / recording heads! Instruction: sudo mv init / sbin / you should pay attention to this directive before the end of the current path and the path of init is not the same as, or can not be successful! !

3: This will do a good job! ! ! We decisive restart! So we started to see our helloworld! Ugh. . Where it stops! ! That's for sure, describes the role of init above, you change, you can not start it is normal. . By thinking here of the state of the kernel. ? In fact, here the basic kernel has been initialized done! Leaving initialization process generates a subsystem. In init_post () function finds the far end of the path init, if you can not find the crash. And it will attempt to establish an interactive shell (/ bin / sh) instead not find init, so that users can fix this error, re-start.

4: Let's restore our system! Just step 2 will not let you for nothing! Restart the system, and at the outset, according to the left Shift (my previous system is not used, do not know what has been done before on grub.cfg bad !!), the system automatically detects this signal, it will appear below FIG interface. (Recommended to look at the characteristics of grub2!):

Press e, to edit, press down the lower right corner of the keyboard keys in linux far end of the line (quiet) was added in front of ----> init = / sbin / init.bak, press ctrl + x to start the system.

If everything is not wrong, then you definitely can successfully restart the system! If you see the login screen, then congratulations, you have to go in life's long road trip up!

Well, here to talk about the knowledge article has been finished. Let us work together to think about I have no problems in this one encounter, the great God, please enlighten!

Question: My first experiment was done on a virtual machine, I had thought that init is related with the kernel archive, so use 3.8.0-19 kernel into the system init deleted, so be sure to start the kernel 3.8.0-19 not the kernel. I 3.8.0-27 kernel into the system, the same can not go. . Or the emergence of great helloworld! This view init with vmlinux and other documents in the boot in the irrelevant! Where it will be saved after init off! ? There is also a most important! I re-installed the system again (virtual machine), it is not 3.8.0-27 kernel, I will file my kernel 3.8.0-27 of the real machine (/ boot Lane vmlinuz files, etc.) into a virtual machine the / boot / folder, restart the system, find that the resolution has changed, the cursor is not flexible (the relationship may be the resolution!), the screen size is twice the original feeling. Why is this?

ps: This article very long! If you have questions, feel free to ask, exchange exchanges, learn! If you know the cause of the above problems, then please leave a few words to the god of the younger co-learn!
- Using DOS command to change UNIX administrator password (Linux)
- Perl said method B if A judge (Programming)
- Make command tutorial (Linux)
- CentOS 7 Add yum source (Linux)
- Linux Security Raiders SSH tools SCP uses examples to explain in detail (Linux)
- Revive Adserver ad server installation on Ubuntu 15.04 / CentOS7 (Server)
- Questions about Linux compiler u-boot (Programming)
- Make Windows boot disk to install USB in Ubuntu Linux (Linux)
- Install Python 3.3.4 under CentOS 6.4 (Linux)
- Linux platform Oracle MySQL connection (Database)
- Linux mention the right notes (Linux)
- Configure shared library PCRE (Linux)
- Replace element and non-replaced elements of learning (Programming)
- Mac OS X 10.9 build Nginx + MySQL + php-fpm environment (Server)
- Ubuntu 14.04 / 14.10 how to install FFmpeg 2.5.1 (Linux)
- Oracle 11R2 Grid Infrastructure execute root.sh script rootcrs.pl execution failed treatment (Database)
- Ubuntu security settings and tools (Linux)
- OpenSSL Introduction and compilation steps on Windows, Linux, Mac systems (Linux)
- The Java ThreadLocal (Programming)
- Install and manage Java under mac (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.