Linux boot process and running level
Linux boot process 1. Concepts
1. boot loader: leads the loader, which is commonly used (Grub, spfdisk)
2. Grub: it is a multi-operating system startup manager that leads different systems, such as windows and linux.
Ii. Boot Process
1. Load the hardware information of BIOS (basic input output system) and perform self-testing.
2. read and execute the boot loader, grub spfdisk, and other programs of MBR (primary boot Record sector) in the first boot device!
3. grub (boot loader) is a multi-operating system startup manager. After running it, select the system (boot loader -- grup function)
4. Load the kernel according to the boot loader settings (that is, the kernel of the system selected in step 1), decompress and execute the loaded kernel in the memory, and detect the hardware information loading driver.
5. After the hardware driver is successful, the kernel will call the first user-level program. init and init will get the runlevel) run level information is stored in the/etc/inittab file)
6. Run/etc/rc in init. d/rc. the sysinit file can be used to prepare information about the software execution environment (such as the network and Time Zone). The specific information can be vim/etc/rc. d/rc. view sysinit
7. run the run-level service in init to start the service corresponding to this run-level.
8. Run the/etc/rc. d/rc. local file (this is the user's custom boot Startup Program, and write the program that needs to be automatically started into this script)
9. init runs the terminal simulation program mingtty to start the login program and waits for the user to log on.
Iii. Functions of Bios (basic input output system)
1. Bios is a set of programs solidified on a Rom (read only memory) chip on the computer's motherboard, it stores the most important basic computer input and output programs, system settings, post-boot self-check programs, and system self-start programs. The programs in it are burned by the manufacturers, therefore, you can only read data and cannot modify it.
2. Cmos is a read/write RAM chip on the microcomputer motherboard. It is mainly used to save the hardware configuration of the current system and the operator's settings for certain parameters.
3. Load the cmos information through the bios program, and obtain the hardware configuration information of the host, such as the communication frequency of the cup and interface devices, through the preset values in the cmos, the I/O address of each interface device.
4. After obtaining the information, the Bios will perform a boot self-test, start hardware detection initialization, set the pnp device, and then define the device sequence for the boot, next we will start reading data from the boot device (MBR-related task) (MBR master boot record master boot zone)
5. Because most of the system software is stored on the hard disk, the Bios will create a device for boot so that we can read the core file of the operating system on the disk.
6. Because different operating systems have different file system formats, we must use a boot management program to handle core file loading issues. Therefore, this boot management program is called boot loader!
7. This boot loader is installed in the first sector (sector), that is, the MBR (master boot record occupies the boot record area)
8. boot loader varies with each operating system. In this case, how does the Bios read the boot loader in MBR?
9. In fact, the BIOS uses the INT13 interrupt function of the hardware to read the content in the MBR. That is to say, if the BIOS detects your disk (whether it is a sata or ide Interface) during hardware detection) there is a way to read the content of your MBR in the first sector of the disk through the channel INT 13, so that the boot loader can be executed!
4. Boot loader)
1. The main function of Boot loader is to understand the file format of the operating system and load the selected system core to the memory for execution.
2. Because the file formats of each operating system are different, each operating system has its own boot loader.
3. In this case, when multiple operating systems are installed on one machine, what should we do? Because there is only one MBR, and each operating system has its own boot loader, in fact, the Boot sector (boot sector) will be left in each filesystem or the main split slot to install your own Boot loader. Therefore, the problem of installing multiple systems will be solved.
4. Main Features of boot loader:
(1) provides a menu: You can select your own boot project, which is an important feature of Multi-boot.
(2) load the core file: directly point to the program segment that can be started and start the operating system.
(3) transfer another boot loader: transfers the boot management function to another boot loader.
** Because of its menu function, we can choose different cores for boot.
** Because of the control transfer function, we can load boot loader in other boot sector!
5. After the management of boot loader starts to read the core file, Linux will extract the core file to the main memory and use the core functions, start testing and driving various peripheral devices, such as storage devices, cpu, network cards, and sound cards. At this time, the linux core will re-detect hardware information with its own functions, rather than using the information detected by BIOS. That is to say, the Linux Core loaded at this time takes over the BIOS work!
6. the kernel has been loaded in the memory and uses the kernel function to detect hardware and try to hook it to the root directory to obtain additional drivers. However, the current kernel does not know the disk, it cannot be mounted to the root directory, so it cannot read/lib. modules/internal driver
7. If the kernel does not know the disk, how should it be mounted to the directory and how to load the driver should be solved by using the Virtual File System (also called the temporary file system initrd ).
8. A special feature of the virtual file system is that it can be loaded into the memory through the boot loader, and the file will be decompressed and simulated into a root directory in the memory, the simulation directory can provide an executable program to load the required modules during the boot process, these modules are usually the drivers for file systems and disk interfaces such as usb raid scsi, after these programs are loaded, the core will call/sbin/init again to start the subsequent normal boot process.
9. At this point, the kernel loads the required driver. Because the drive can be used to find the disk, the root directory file system is mounted and the virtual file system is released.
10. The core actively loads the first user-level Program/sbin/init
5. the first user-level program init, the configuration file/etc/inittab, and the running level
1. After the core is loaded and the hardware information is tested and the driver is loaded, your host hardware should be ready, at this time, the core will actively call the first user-level program, that is,/sbin/init (init is called all the ancestor processes and is also the first user-level process started)
2. The main function of/sbin/init is to prepare the software execution environment, including the host name, network settings, language settings, system file format, and startup of other services, all actions are planned through the init configuration file and/etc/inittab.
3. the system running level is configured in/etc/inittab. The bottom of this file is id: n: initdefault. This is the set system running level.
4. Why should we set the system running level? What is the difference? in linux, we plan by setting the run level, and the system starts with different services to make the linux environment different, there are 7 levels based on whether there is a network or xwindow
5. run level
(0) run level 0: Shutdown
(1) run level 1: single mode is the maintenance mode for a single user. Generally, the root password is forgotten. If there is a problem with the system, use this mode.
(2) run level 2: without NFS no NFS System
(3) run level 3: Full text mode with network functions
(4) run level 4: reserved by the System
(5) run level 5: xwinods and 3 are similar, except that the plain text is changed to the window mode.
(6) run level 6: restart reboot
6. If the file is executed once at startup,/etc/rc. d/rc. sysinit indicates that the system data settings are complete!
7. Start the system service and start the configuration file/etc/rc, d/rc n (your system level starts different services according to different levels)/etc/sysconfig
8. Load the core so that the entire system is ready to accept commands to work. d/rc. the initialization of sysinit system modules and related hardware information should be successful!
6. Switch the running level
1. In fact, different running levels are different for loading services. Here, run level 3 and run level 5 are columns: only their Sxxname and Kxxname in/etc/rc.3d and/etc/rc.5d are different.
2. First, compare the files starting with k and s in/etc/rc.3d and/etc/rc.5d.
3. Multiple K in the new run level are disabled.
4. In the new run level, multiple S are enabled, and there is no need to worry about them.
OK. The running level is converted!