Linux basics-Boot Process

Source: Internet
Author: User

1 Linux boot process

--------------------------------------------------------------------------------
1.1 load BIOS hardware information and perform self-testing, and obtain the first device that can be started based on the settings

--------------------------------------------------------------------------------
BIOS (Basic Input Output System): The System loads the BIOS, loads the CMOS information through the BIOS, and obtains various hardware configurations of the Host Based on the preset values in the CMOS; the BIOS performs a Power-on Self Test (POST) based on the obtained information and determines the device sequence that can be started.


1.2 read and execute the boot Loader (such as grub and spfdisk) of MBR in the first boot device)

--------------------------------------------------------------------------------
Because the filesystem formats of different operating systems are different, you need to boot the management program to process the core file loading (load), the so-called boot loader. The boot loader program is installed in the first sector (sector) of the first Boot device, that is, MBR (Master boot Record, Main Boot Record area, 446 bytes ). BIOS reads MBR through INT13 interruption. By default, each operating system installs a boot loader to its own file system, which is the premise of multiple systems.


1.3 load the Kernel according to the boot loader settings. The Kernel starts to detect the hardware and load the driver.

--------------------------------------------------------------------------------
Boot loader reads the Kernel file according to the settings and decompress it To the memory. The Kernel starts to detect the hardware and load the driver. The core is generally in the/boot/vmlinuz-core version. The linux core can dynamically load the core module (the drivers of disk devices are all in the form of modules ), these core modules are placed in the/lib/modules/directory.

Initial RAM Disk:/boot/initrd, which is loaded into the memory through the boot loader to simulate a root directory. The virtual file system can provide an executable program, this program is used to load the core modules most needed during the boot process.
Boot loader loads kernel and initrd, decompress initrd into the root directory in the memory, and then the kernel can load the appropriate driver to release the virtual file system, and mount the actual root directory file system to start the subsequent normal boot process.


1.4 after the hardware driver is successful, the Kernel will start the init program, and the init will get the run-level information.

--------------------------------------------------------------------------------
The core starts the first program/sbin/init and prepares the software execution environment, including the host name, network settings, language processing, file system format, and startup of other services of the system, the configuration file is/etc/inittab. Inittab also obtains the run-level (startup execution level ).


1.5 run the/etc/rc. d/rc. sysinit file in init to prepare the job environment (such as network and Time Zone) for software execution)

--------------------------------------------------------------------------------
Init process system initialization process (/etc/rc. d/rc. sysinit), including deciding whether to start SELinux, reading the network configuration file/etc/sysconfig/network, and loading/etc/sysconfig/modules/* of user-defined modules /*. use fsck to check the disk file system: filesystem check, clear temporary files during the boot process, and load boot-related information to the/var/log/dmesg file.


1.6 init run-level startup of each Service (script Mode)

--------------------------------------------------------------------------------
Start System services and related STARTUP configuration files (/etc/rc. d/rc N &/etc/sysconfig) based on run-level ). For example, if run-level is 5, the script in the/etc/rc5.d/directory is executed when the GUI is started. Each script actually points to/etc/init. d/The corresponding STARTUP script in the directory. The last execution is/etc/rc. d/rc. local.


1.7 run the/etc/rc. d/rc. local file in init.

--------------------------------------------------------------------------------
Run the User-Defined boot Startup Program/etc/rc. d/rc. local.


1.8 init execute the terminal simulation program mingetty to start the login program, and finally wait for the user to log on


2. Files and key points during startup

--------------------------------------------------------------------------------
2.1. About the configuration file loaded by the module:/etc/modprobe. d/*. conf :( CentOS6.5, the/etc/modprobe. conf file is no longer used .)


2.2./etc/sysconfig/*: the configuration files read during the boot process, including authconfig (standard user identity authentication mechanism) and network-scripts/* (NIC setting.


2.3. About core and core modules (driver modules ):
Core:/boot/vmlinuz or/boot/vmlinuz-version;
RAM Disk required for core decompression:/boot/initrd (/boot/initrd-version );
Core Module:/lib/modules/version/kernel or/lib/modules/$ (uname-r)/kernel;
Core original code:/usr/src/linux (not installed by default)
Core version:/proc/version
System core functions:/proc/sys/kernel
Two methods are used to add the driver module of the new hardware: recompile the core and add the source code of the corresponding driver; Compile the driver program of the hardware into a module and load the module at startup.
Kernel module relevance:/lib/modules/$ (uname-r)/kernel module relevance is recorded in/lib/modules/$ (uname-r)/modules. in the dep file, run the depmod command to create the file.
Kernel module-related commands: lsmod -- displays the modules that already exist in the core, and the module relevance is also displayed
Modinfo -- display details of a module
Modpobe -- automatically analyzes the module relevance (modprobe. dep), loads the module, and removes the module from the-r module.
Insmod-manually load the module with the complete file name
Rmmod -- remove the module,-f force remove,-w Wait for use before removing
Ps: When the insmod and rmmod operation modules are dependent, the operation cannot be completed.


2.4. initrd: The initrd file contains the modules required for starting/lib/modules/$ (uname-r)/kernel, at startup, the file is read out and decompressed through the INT13 hardware function of the host. initrd simulates the file as the root directory in the memory, because the Initial RAM Disk) this module mainly includes disks and file systems. The core can identify the actual disk and mount the actual root directory. Use the mkinitrd command to recreate the initrd file: mkinitrd [-v] [-- with = Module name] core version of The initrd file name


2.5. About the boot management artifact grub:
Through the configuration file/boot/grub/menu. lst is used to modify and add boot items. After adding a boot item, you need to use grub to install the main program to the system (such as setup (hd0), such as MBR (hd0) to quit boot sector (hd0, 0) and so on
Encrypt: grub-md5-crypt for a startup Item, get the encrypted password, add the first line under the title corresponding to the menu. lst file, eg: title CentOS
Password -- md5 $1 $ kvlI0/$ byrbNgkt/. REKPQdfg287.
Insecure: You can enter the menu in editing mode (e), delete the password field, and press B to start the boot process. Therefore, you need to encrypt the menu. lst file: place the password in front of all titles, and add lock to the title to be locked. The start item can only be unlocked by p.

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.