1. The computer reads the BIOS to load hardware information and complete the hardware self-check. Then, it reads the first device that can be started with BIOS settings.
2. read and execute the Boot Loader (grub, Lilo, spfdisk, and other boot programs) of the mbr of the first boot device)
A) Boot Loader provides three functions: menu: users can select different boot items, and can choose different core boot items. Load the core files: direct to the program segment that can be started to start the operating system; transfer to other loaders: transfer the boot management function to other loaders. The main point here is that the boot loader that the system can use must be able to understand the file system.
B) The Boot Loader is stored in the MBR. Although the boot loader varies with operating systems, the BIOS reads the MBR through the INT 13 interrupt of the hardware. That is to say, the BIOS can detect the hard disk, the MBR can be read through the INT 13 interrupt, so that the boot loader can be executed.
C) The Boot Loader size may exceed 466. The solution is to divide the boot loader into two sections for execution. In the first stage, only the minimum main program of the boot loader is installed, this main program must be installed in the startup zone, that is, MBR or the first sector, without installing the relevant configuration files. The second stage is to load all the setting files and Related Environment Parameter files of the boot loader. Generally, the setting files are in the/boot directory, such as grub. conf.
Note: MBR does not belong to any operating system. It cannot be read using the disk operation commands provided by the operating system, but can be modified and rewritten using commands. Located in the hard disk's 0 cylinder, 0 head, 1 sector, divided into three sections boot program area, Hard Disk Partition Table area, sector end sign area, MBR total size is 512 bytes, among them, the boot program area occupies 466 bytes. It is responsible for detecting the hard disk partition table, searching for bootable partitions, and loading the information of the boot sector to the memory. The Hard Disk Partition Table occupies 64 bytes, it contains four partition items, each of which is 16 bytes long, which is the reason that each hard drive primary partition and the number of extended partitions can be up to four. At the same time, each hard disk can only have one extended partition. This extended partition cannot be used directly and must be used in combination with a logical partition, each hard disk partition table contains important information such as the type, size, start and end position of each partition. The end flag of a sector is 2 bytes, fixed to 55aa. If the flag is incorrect, the system cannot be started.
3. Load the kernel and initrd according to the boot loader settings. The kernel detects the hardware device and loads the driver.
A) Start from the boot loader management to load the kernel. First, extract the kernel to the memory and use the kernel function to test and drive various devices, such as the CPU, Nic, and sound card, this is the detection performed by the kernel itself, and does not necessarily use the hardware information of the BIOS detection.
B) The core is the/boot/vmlinuz * file. The core can dynamically load core modules, such as various drivers.
C) The core module is placed in the/lib/modules directory. Because the system starts the first mounted partition as/, if the kernel cannot identify the hard disk, You need to load the hard disk driver to identify it, however, to read the driver, you must first mount the module partition. At this time, you need initrd, the file/boot/initrd *, which can be loaded into the memory by the boot loader, it is virtualized into a root directory/to load the most important core modules during the boot process, release the virtual system, mount the actual file system, and start the subsequent normal boot process. Without initrd, you can also boot smoothly, only on special disk interfaces (USB, SATA, SCSI), or the file system is special (LVM, raid) it is required only when/cannot be mounted at startup.
4. After the hardware driver is complete, the kernel will execute the initialization script program.
A) after the core is loaded, start to execute the system's first binary Script:/sbin/init. Its main function is to prepare the software execution environment, including the host name, network environment, language family, and various services. init reads the/etc/inittab file and completes the above actions according to the settings. The setting of/etc/inittab is similar to the shell script. The file content is also set from top to bottom line by line. The process of init is as follows:
1. first obtain the runlevel, that is, the level of the preset execution level
2. Use/etc/rc. d/rc. sysinit to initialize the system.
3. Because runlevel is 5, only L5: 5: Wait:/etc/rc. d/RC 5 is executed, and other rows are skipped.
4. Set the [CTRL] + [alt] + [del] combination key function.
5. Set the PF and PR mechanisms for the power-on system;
6. Start the six terminals (tty1 ~ Tty6)
7. Finally, start the graphic interface with/etc/X11/perofdm-nodaemon!
B) The inittab file defines the startup running level. Different services are enabled/disabled according to different levels.
1. First, the file defines seven run levels, which are:
0-halt (direct system shutdown)
1-single user mode (single user mode, used for maintenance when system problems occur)
2-multi-user, without NFS (similar to runlevel 3 below, but no NFS service)
3-full multi-user mode (full text mode with network functions)
4-unused (system reservation function)
5-X11 (similar to runlevel 3, but using X Window for loading)
6-Reboot (reboot)
2. The process for processing the content of the inittab File Based on the init method described above can read the default startup level and specify the script file to be executed next, the syntax of the file is to use the colon (:) to separate the settings into four fields. The meaning and description of each field are as follows: [set project]: [run level]: [init Action Behavior]: [command project]
Set project: a maximum of four characters, representing the main work project of init, just a simple description
Run level: the run level under which the project is implemented. If it is 35, runlevel 3 and 5 will be executed.
Init action items: the main actions that can be performed are initdefault (representing the preset run level value) and sysinit (representing the system initialization action items) ctrlaltdel (indicating whether the three buttons can be restarted) and wait (indicating that the command project set in the following field must be executed to continue other actions) and respawn (indicating that the commands of the following fields can be recycled without limit. For example, after you cancel the message in tty1, the system will open a new login screen to wait for the next login)
Command project: commands that can be executed, usually scripts
3. extracted important information:
ID: 5: initdefault: <== default runlevel setting, which is 5
Si: sysinit:/etc/rc. d/rc. sysinit <= system environment script
1: 2345: respawn:/sbin/mingetty tty1 <== total tty1 ~ Tty6 Terminals
X: 5: respawn:/etc/X11/preofdm-nodaemon <= X Window is determined by this line.
C) In the RC. sysinit script inittab, specify the RC. sysinit shell script to set the system environment. The main tasks of this script are as follows:
1. Obtain the network environment and host type (first read the network setting file/etc/sysconfig/network and obtain the host name, default gateway, and other network environments)
2. Test and load the memory device/proc and USB device/sys
3. Determine whether to start SELinux.
4. Interface Device Detection and plug-and-play (PNP) parameter testing
5. User-Defined module loading (you can add the User-Defined module to/etc/sysconfig/modules/*. modules, which will be automatically loaded to the System)
6. Load the settings of the core (the system will actively read the settings of the/etc/sysctl. conf file)
7. Set the system time
8. Set the font of the terminal Console
9. Set hard disk functions such as raid and LVM
10. Use fsck to detect the Disk File System
11. Convert the disk quota if necessary
12. Reload the System Disk in readable Mode
13. Start the quota Function
14. Start the system Random Device (random number generation function)
15. Clear temporary files during startup
16. Load startup information to the/var/log/dmesg file.
After the above process, the basic system settings are complete. Basically, the default setting files for a lot of work executed in this file are all in/etc/sysconfig.
D) RC. N file: RC. after sysinit is executed, start the services required by the system based on the set values in the inittab file and the default running levels. Only scripts corresponding to the running level are executed, each running level corresponds to/etc/rc. d/RC. all files in the N directory start with S or K. These files are all connection files and they are connected to/etc/rc. d/init. d directory shell script (/etc/rc. d/init. d and/etc/init. D is actually the same, because the two directories are connection files), where the S header file is the service file connection to be started at startup, files starting with K are the file connections of services that need to be closed when they are shut down or when the running level is changed. The numbers after S and K are the execution sequence.
For example, when the system changes the running level from 5 to 3, the system compares the files whose running levels start with K and S, and closes the corresponding services started in rc5.d without rc3.d, start services that need to be started in rc3.d and do not exist in rc5.d.
The runlevel command displays the current running level.
E) RC. Local: use this file to complete custom boot. According to the settings in the file inittab, After all system services are started, Linux will start the terminal or x Desktop system. When the runtime level is 2345,/sbin/mingetty will be executed, this script is the command to start the terminal and executes six, which is why there are six terminal settings in plain text. At the same time, the init of respawn indicates that when the command is terminated, init will automatically restart the project, which is why after exit, the reason why the system will re-display the user logon interface.
The most popular GRUB boot program:
A) files in the/boot/GRUB directory:
-RW-r -- device. Map <= grub Device File
-RW-r -- e2fs_stage1_5 <= ext2/ext3 file system definition file
-RW-r -- fat_stage00005 <= FAT file system definition file
-RW-r -- ffs_stage1_5 <= FFS file system definition file
-RW ------- grub. conf <= grub configuration file in Red Hat
-RW-r -- iso9660_stage00005 <= definition file of the optical drive File System
-RW-r -- jfs_stage1_5 <= JFS file system definition file
Lrwxrwxrwx menu. lst->./grub. conf <= menu. lst is the configuration file.
-RW-r -- minix_stage1_5 <= minix file system definition file
-RW-r -- reiserfs_stage1_5 <= reiserfs file system definition file
-RW-r -- splash.xpm.gz <= background image under grub at startup
-RW-r -- stage1 <= Description of the first phase of the pilot program
-RW-r -- stage2 <= Description of the second stage of the Bootstrap program
-RW-r -- ufs2_stage1_5 <= UFS file system definition file
-RW-r -- vstafs_stage1_5 <= vstafs file system definition file
-RW-r -- xfs_stage1_5 <= XFS file system definition file
Menu. lst is sometimes called grub. conf, but a symbolic link named menu. lst points to it under/boot/GRUB. It is the configuration file of the grub boot system.
File basic options:
Default 0: default startup Item of grub
Timeout 5: Specifies a timeout value in seconds. If you have not performed any operation within the time-out period of the grub wait, the default item is enabled.
Hidemenu: whether to display the multi-option menu at startup. If it is set, the option menu is not displayed by default at startup. Otherwise, the option menu is automatically displayed at grub startup.
Color white/Blue: Specifies the default color of the GRUB menu.
Password -- MD5 $1 $ etsg6 $ llxt8irafav5vyqn6tzuw1: specify a password and enable GRUB Password protection. This command must be placed in the first line under title. For security, the MD5 value is generally used, which can be generated using a grub-md5-crypt or using md5crypt in grub shell, or directly using letters or numbers. To modify the encrypted startup Item, press the P key and enter the password. Note that in order to place click e, enter the edit mode, delete the password field, and then press B to start the system, you can set the password as a whole, instead of placing it under a title, add a lock <= with the deadlock function under the corresponding title.
Example of an MD5 password Generation Command
# Grub-md5-crypt
Password: <= enter the password
Retype password: <= enter again
$1 $ kvli0/$ byrbngkt/. rekpqdfg287. <= This is the generated MD5 password!
A menu item for Linux Startup
Title Linux *: Specifies the name of a single item, that is, the name in the grub list
Root (hd0, 0): Specify the boot partition. Note that the number starts from 0. For example, the first partition of the first hard disk should be (hd0, 0 ). You can use fdisk-L to query the number of the Start partition, but the root permission is required.
Kernel/boot/vmlinuz-2.6.20-16-generic: System Kernel
Root = UUID = 3f784cd9-516f-4808-a601-b19356f6bdea Ro quiet splash locale = zh_cn VGA = 0x318:
Specify the absolute path and name of the started kernel, followed by the parameter. Generally, the Root parameter is your root file system and must be available. It can be represented by uuit In the example, you can also directly use/dev/sda2 or/dev/hda1. In fact, there are two lines of root and kernel to start Linux.
Initrd/boot/initrd. img-2.6.20-16-generic: Specifies the ramdisk image accessed before the system is started to access the real root file system
Savedefault: If this start item is selected, this item will be used as the default item at the next start. This item is valid when it is set to default saved.
Common Linux Kernel Parameters
Root: the location of the root file system.
RO: read/write. This parameter is required when the start partition is in JFS format so that the system can store logs at startup.
Quiet: quiet mode. The core detection information is not displayed.
Splash: displays the logo.
Locale: Specify locale
VGA: Specifies the display mode of the terminal. To adjust tty1 ~ For the resolution of the tty6 terminal, see the following table (this is a decimal value): color/Resolution bit
640x480 800x600 1024x768x1280
256 769 771 773 775 8 bit
32768 784 787 790 793 15 bit
65536 785 788 791 794 16 Bit
16.8 M 786 789 792 795 32 bit
B) operations on startup items
For multiple startup items, you can select the startup items and click e to enter the editing status. After that, you can click B to guide. In case of/boot/GRUB/menu. when the lst settings are incorrect, because of installation, or because of the core file, it cannot be started smoothly. Remember, In the GRUB menu, you can use grub shell to query (FIND) or directly specify the core file to start the instance.
C) rescue mode:
When the system cannot connect to the single-user mode or the grub command line cannot solve the boot problem, we need to use the Linux rescue mode for troubleshooting. The procedure is as follows:
1. Put the Linux installation CD into the optical drive. F2 enters the bios and sets it as the boot disc. F10 is saved and exited. When the Linux installation screen appears, go to "Boot: "prompt, enter" Linux Rescue ", and press enter to enter rescue mode. (F5 key view mode details)
2. The system detects the hardware, guides the Linux environment on the CD, prompts you to select the language used in rescue mode, and selects English. Chinese characters are garbled; use the default "us" for keyboard settings; network settings are not required.
3. The system will try to find the root partition. By default, in rescue mode, the root partition of the hard disk is mounted to the/mnt/sysimage directory of the CD Linux environment. The default option "continue" indicates that the mounting permission is read/write; "Read-only" is read-only. If detection fails, you can select "Skip" to skip. In this example, you need to have the read and write permissions to fix the system. The default option is "continue ". After entering the next step, the system prompts to run the "chroot/mnt/sysimage" command to mount the root directory to the root directory of our hard disk system.
4. Modify the boot configuration file Vim/boot/GRUB/grub. conf and enter the grub command to repair the boot program.
Grub> root (hd0, 0) is consistent with root under Title
Grub> setup (hd0) real fix
Grub> quit
Case 1: Dual-System Startup Repair
When we install a dual-system environment, first install Linux and then install windows; or If Windows has already been installed in a dual-system environment damaged, after the windows is re-installed, save the grub MBR (Master Boot Record, the Master Boot Record) will be overwritten by the Windows UDF ntldr, causing Linux to fail to boot.
1. If you want to recover the dual-system boot, first use the above method to enter the rescue mode, and execute the chroot command as follows:
Sh-3.1 # chroot/mnt/sysimage
2. Switch the root directory to the root directory of the hard drive system, and then run the grub-install command to reinstall GRUB:
Sh-3.1 # grub-install/dev/hda
"/Dev/hda" is the name of the hard disk. For example, if you use a SCSI hard disk or Linux to install it on the second IDE hard disk, adjust this setting accordingly.
3. Execute the exit command in sequence to exit the chroot mode and rescue mode (execute the exit command twice ):
Sh-3.1 # exit
Sh-3.1 # exit
After the system is restarted, the grub-guided dual-system boot will be restored.
Case 2: Repair of system configuration file loss
If/etc/inittab is accidentally deleted or modified incorrectly, Linux cannot start normally. In this case, only the rescue mode can be used to solve such problems.
1. Recovery Methods for backup files
Enter the rescue mode. After the chroot command is executed, if the file is backed up (we strongly recommend that you back up important data directories in the system, such as/etc and/BOOT ), copy the backup file back directly and exit and restart. If the configuration file is modified incorrectly, for example, the typical/boot/GRUB/grub. conf and/etc/passwd file are modified incorrectly, you can also directly fix the restoration. If the backup file/etc/inittab. Bak is available, run the following command in rescue mode:
Sh-3.1 # chroot/mnt/sysimage
Sh-3.1 # cp/etc/inittab. bak/etc/inittab
2. No recovery method for backup files
If some configuration files are lost or the software is deleted by mistake and there is no backup, you can reinstall the software package to recover it. First find the RPM package of/etc/inittab (even if the file is lost, because there is an RPM database, you can find the results ):
Sh-3.1 # chroot/mnt/sysimage
Sh-3.1 # rpm-qf/etc/inittab
Initscripts-8.45.3-1
Exit the chroot mode:
Sh-3.1 # exit
Mount the installation disc that stores the RPM package (in rescue mode, the disc is usually mounted in the/mnt/source directory ):
Sh-3.1 # Mount/dev/HDC/mnt/source
The RPM packages of the fedora system are stored in the ora/RPMS directory on the CD. The storage locations in other Linux systems are similar, because the root directory of the hard drive system to be repaired is in/mnt/sysimage, you need to use the -- root option to specify its location. Overwrite the RPM package where the/etc/inittab file is installed:
Sh-3.1 # rpm-IVH -- replacepkgs -- root/mnt/sysimage/mnt/source/Fedora/RPMS/initscripts-8.45.3-1.i386.rpm
The RPM Command Option "-- replacepkgs" indicates that the file has been restored after the installation is completed. If you want to extract only the/etc/inittab file in the RPM package for restoration, you can run the following command after entering rescue mode:
Sh-3.1 # rpm2cpio/mnt/source/Fedora/RPMS/initscripts-8.45.3-1.i386.rpm
| Cpio-IDV./etc/inittab
Sh-3.1 # cp ETC/inittab/mnt/sysimage/etc
Note: When executing this command, you cannot directly restore the file to the/etc directory. You can only extract the file to the current directory, and the path of the recovered file name must be a complete absolute path. After the file is extracted, copy it to the corresponding location in the/mnt/sysimage directory where the root partition is located.
D) inittab configuration file error (/etc/inittab)
This file is set incorrectly and cannot be started! Based on the boot process, we know runlevel 0 ~ 6. the/etc/inittab file is read. Therefore, you need to read/etc/inittab in single-user mode for boot. In this case, you cannot enter the single-person maintenance mode. Therefore, you need to tell the core not to execute init, use Bash, and skip init. After the operation is started into grub, similarly, in the case of grub edit, do the following:
Grub edit & gt; kernel/vmlinuz-2.6.18-92.el5 Ro root = label =/rhgb quiet init =/bin/bash
Because the first program (init) of the core call is specified to be/bin/bash,/sbin/init will not be executed. According to the boot process, we know that although Bash can be obtained by using root, (1) all directories except the root directory are not mounted. (2) the root directory is mounted to the read-only status. Therefore, we still need to perform some actions! As follows:
Only two commands are issued. "Mount-O remount, RW/" is used to remount the root directory to writable, for "Mount-a", refer to the/etc/fstab content to re-mount the file system! Now you can start the system again for rescue! After the rescue is completed, you must use "reboot" to restart the system.
E) If the grub. conf file is corrupted and the system cannot be started normally, the following error occurs when grub is started:
Note: You can use the tab key to complete the following grub environment!
Grub>
3. set the root device of grub to the partition where the Linux kernel is located. Because my/boot partition is installed in the first partition of the first hard disk, it is set to (hd0, 0 ), note that the IDC hard disk and SCSI hard disk are not distinguished here!
Grub> root (hd0, 0)
4. set the kernel parameters and load the kernel file because I have installed an independent/boot partition. If the/boot partition is placed under the/partition, the kernel file must be/boot/vmlinuz-verstion!
Grub> kernel/vmlinuz-2.6.18-53.el5PAE Ro root =/dev/volgroup00/logvol00 rhgb quiet
5. Load the kernel Image File
Grub> initrd/initrd-2.6.18-53.el5PAE.img
6. Boot System
Grub> boot
7. After entering the system, repair or create a new/boot/GRUB/grub. conf file to ensure that the system can be started normally next time;
8. If you have a CD, there is another way to fix the grub. conf file in Linux rescue mode.
A) boot the CD to the Linux rescue mode
Boot: Linux rescue
B) root directory Switch
Sh-3.1 # chroot/mnt/sysimage
C) Now you can fix or recreate the grub. conf file.
Sh-3.1 # vi/boot/GRUB/grub. conf