Linux Basics-GRUB functionality in system startup

Source: Internet
Author: User

This paper mainly explains the grub principle and the process of grub during system startup.


Grub is the boot loader system bootstrapper used in most Linux distributions, the primary function of which is to find the system kernel kernel file and load the kernel file by grub after the computer chooses the specified device from boot sequence.


Grub Execution Process

The grub process is mainly divided into three stages, as shown in:


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/AA/wKioL1XrHKrSiXReAAIF7A29u8c551.jpg "title=" Grub execution Process 01.jpg "alt=" Wkiol1xrhkrsixreaaif7a29u8c551.jpg "/>


Stage1: Starts the GRUB program, which is located in the top 446Byte of the MBR;

stage1.5: Identifies the file system type of the partition on which the kernel resides, in the boot sector of the partition where the kernel file resides;

Stage2: According to the boot menu in the Grub configuration file grub.conf, read the kernel vmlinuz file and read parameters and Initramfs files specified in the menu, located in the boot directory where the kernel Vmlinuz file resides.

Where the kernel file naming method is: vmlinuz-$ (uname-r);

The Initrd file is named: initrd-$ (UNAME-R). IMG (RHEL5) or initramfs-$ (UNAME-R). IMG (RHEL6)


Field description for GRUB configuration file grub.conf

DEFAULT=0 Specifies the default boot title menu timeout=5 Specifies the wait time password--md5 $1$fra2p$uzgeloriloh8sbmqhz5zp/Specifies the password to manage the Grub profile from the command line Splash Image= (hd0,0)/grub/splash.xpm.gz Specify grub background picture path Hiddenmenu specify hidden menu option title CentOS 6 (2.6.32-504.el6.x86_64) Title field specified dish Single name root (hd0,0) root field specifies the partition of the kernel file Vmlinuz as the "grub root" kernel/vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/ The Vg0-rootkernel field specifies the absolute path of the kernel file Vmlinuz in the Grub root directory and specifies the device file path initrd/initramfs-2.6.32-504.el6.x86_64 to load the real root file system as read-only. The IMG initrd field specifies the Initramfs file in the "Grub root" absolute path password--md5 $1$fra2p$uzgeloriloh8sbmqhz5zp/Specifies the password when the system is enabled

Note:

1 for grub, all types of hard drives are HD, in the Format (hd#,n): #表示第几个磁盘, the last N is the partition of the corresponding disk, and you can view/boot/grub/device.map to see the corresponding disk number identified by grub

2 Depending on whether the boot directory is partitioned separately, the root directory of grub will change, and the absolute path of the kernel and INITRD files to the Grub root reference point will also change :

Boot directory separate partition/dev/sda1,/root directory for/dev/sda2 ==> "Grub root" for/dev/sda1 ==> kernel file with "Grub root" reference point absolute path to/vmlinz-$ (UNAME-R) , initrd files the same;

The boot directory does not have a separate partition, but is a subdirectory of the/root directory and/root directory is/dev/sda1 ==> "Grub Root" is/dev/sda1 ==> kernel file with "Grub root" reference point absolute Path is/boot/ vmlinz-$ (uname-r), initrd file the same.


Grub main role

1 User forgot login password

Method: After the system boot into the Grub menu screen, press E to enter the menu editing mode, select the second line kernel menu item and press the E key to edit it, after adding 1 or s or S, ESC exits, then press the B key will start the kernel in single user mode, directly can modify the user password.

Once the password has been modified, the init command can be used to switch to the original level.


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/AE/wKiom1XrJsOSLFwNAAGaJzVIvkc405.jpg "title=" Grub02.jpg "alt=" Wkiom1xrjsoslfwnaagajzvivkc405.jpg "/>


2. grub.conf configuration file is missing or corrupted

Method: The system will enter the GRUB command line mode by default grub>


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/AA/wKioL1XrK7mwJLUXAAHEzqEBAVQ903.jpg "title=" Grub04.jpg "alt=" Wkiol1xrk7mwjluxaahezqebavq903.jpg "/>


With the Find (hd#,0)/+tab key, you can find the disk partition where the Vmlinuz file is located by using the Find and Tab command

grub> Root (hd#,0) specifies VMLINUZ disk partition grub> Kernel/vmlinuz-2.6.18-208.e15 ro root=/dev/mapper/vg0-root by Root Kern EL Specifies the kernel file and mounts the root file system as read-only grub> initrd/initrd-2.6.18-208.e15.img Initramfs boot boot by INITRD designation

Add GRUB configuration file after normal boot boot


3. Grub program Corruption

Method: Grub failed to boot the system kernel through grub, the system prompts for boot

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/AE/wKiom1XrKinQMMlzAACeW8OO7l4944.jpg "style=" float: none; "title=" grub06.jpg "alt=" Wkiom1xrkinqmmlzaacew8oo7l4944.jpg "/>


Insert the system image disc in the optical drive and set the boot order to start the disc.

Option to repair the system via rescue mode after booting from CD

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/AA/wKioL1XrLE-AAXxXAAESyfkBBf4958.jpg "style=" float: none; "title=" grub07.jpg "alt=" Wkiol1xrle-aaxxxaaesyfkbbf4958.jpg "/>


Select the disc in the Rescue mode category

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/AE/wKiom1XrKimC4ZWgAADO2oq0AAU293.jpg "style=" float: none; "title=" grub08.jpg "alt=" Wkiom1xrkimc4zwgaado2oq0aau293.jpg "/>


After selecting rescue mode, the system will prompt to try to restore the original system and mount the original system in the/mnt/sysimage directory.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/AE/wKiom1XrK4ygHB0UAAJS1YO2xaM093.jpg "style=" float: none; "title=" grub10.jpg "alt=" Wkiom1xrk4yghb0uaajs1yo2xam093.jpg "/>


After finding the original system, you will be prompted to perform a root switch chroot/mnt/sysimage to switch the root to the original system root directory.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/AA/wKioL1XrLbPAVnoOAAEMRFkBO4I813.jpg "style=" float: none; "title=" grub11.jpg "alt=" Wkiol1xrlbpavnooaaemrfkbo4i813.jpg "/>


To enter rescue mode in a shell environment, switch the root to the original system root and use the Grub-install command to install the GRUB program on the MBR of the original system's corresponding disk. 650) this.width=650; "src=" http:/ S3.51cto.com/wyfs02/m01/72/aa/wkiol1xrlfdckwgraadtwo8lghg670.jpg "style=" Float:none; "title=" Grub09.jpg "alt=" Wkiol1xrlfdckwgraadtwo8lghg670.jpg "/>


After the installation is complete, after exiting the original root system, restart the system in the rescue mode environment to restore the original system.

If the configuration file is not corrupted at this time, do not need to modify the configuration file; If the configuration file is corrupted, it will enter the GRUB command line interface after booting, and then manually specify the contents of the Grub.conf configuration file to start normally

# to start the disc on the boot device after rebooting the system


I have limited level, if there is improper understanding of the place, please give correct, thank you very much!

This article is from the "Pavel" blog, make sure to keep this source http://pavel86.blog.51cto.com/8349178/1691685

Linux Basics-GRUB functionality in system startup

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.