Configure GRUB in centos 6.7

Source: Internet
Author: User
Tags network function

Configure GRUB in centos 6.7

Brief linux boot process:

POST --> bootloader --> kernel --> usr_space_Application

######################################## ######################################

POST phase:

After the computer is powered on, the First Command executed by the processor locates the BIOS chip (ROM) to load the program in the ROM to the memory, and then jumps to the memory address segment of the program in the ROM, load the program to the processor for execution and perform power-on self-check. (Usually there are two ROM on the server motherboard to prevent the BIOS firmware upgrade from failing, resulting in failure to boot)

Features inherent in BIOS

BIOS features

-UEFI (uniied Extensible Firmware Interface) # Unified Extensible Firmware Interface (which can be considered as a new BIOS, specifically Baidu)

-SMBIOS 2.5 (DMI) # It is equivalent to the database's DMI. You can obtain the serial number, computer vendor, serial port information, and other system accessories.

-ServerHardware Design Guide # Some help tips when setting BIOS (for example, F10 save and exit ...)

-WfM 2.0 # connection management. Specifications developed by Intel to improve manageability of desktop computers, portable computers, and servers; WfM standards include DMI, PXE, and remote Wakeup

-ACPI 2.0 support # has the energy consumption management function (such as timed ON/OFF, remote boot ...)

-USB keyboard/mouse

-Bootpossible from: # optional startup items

-CD-ROM/DVD (SATA)

-Hard disk (SATA, SAS, USB)

-LAN

-Consoleredirection support # Remote Control support

-OEM logo # manufacturer information

-CPU and memory disable # enable or disable a certain CPU memory slot, etc.

-------

When the BIOS program is started, the BIOS program is regarded as an operating system. After the system runs, the system detects the hardware, if the hardware is damaged, it will trigger an alarm (the corresponding indicator will change to orange or red). If the damage reaches the threshold of power-on, it will be stuck on a certain interface; otherwise, the damaged hardware will be shielded directly (a multi-processor breaks down a processor and can still be turned on, with the same memory); this entire process is POST ).

The last step of POST is to execute the INT 0x19 command. This command reads 0th bytes from the first sector of the 0th cylinder 512 track of the boot device and loads the address 0x7c00. The 512 bytes Main Boot Program (bootloader) the second part is the Partitiontable area (Partition Table), that is, DPT, which occupies 64 bytes. The number of partitions in the hard disk and the size of each partition are recorded in this section. The third part is magicnumber, which occupies 2 bytes and is fixed to 0xAA55 or 0x55AA. If this sector ends with 0xAA55 or 0x55AA ), then the BIOS will think that this is a system device and then hand over the power to the 512-byte small system.

Bytes --------------------------------------------------------------------------------------------

Boot Loader stage (Startup Program)

Programs in the BootLoder (GRUB) can also be considered as a small system. The function of this small system is to find the kernel, load the kernel to the memory, run it, and finally assign permissions to the kernel.

Bytes --------------------------------------------------------------------------------------------

Kernel stage:

Kernel is capable of self-extracting and running after being loaded to the memory. It will fully scan all hardware, load the corresponding hardware driver, and mount the root file system.

Bytes --------------------------------------------------------------------------------------------

User_space_Application stage:

After the kernel is started, the kernel starts the first user space program/sbin/init (7 Series: systemd) in the user space. This program sets the corresponding running level and time zone, keyboard, environment variable... the logon page is printed.

######################################## ######################################

Grub Introduction

The bios is already fixed on the motherboard chip. We usually do not interfere too much with BIOS settings, because the hardware has been set out at the factory, and grub is the key point to start the kernel, familiar with GRUB configuration is also a required knowledge of LINUX administrators.

File systems supported by GRUB:

Support multiple filesystem types

Supportmultiple filesystem types transparently, plus a useful explicit blocklistnotation. The currently supported filesystem types are bsd ffs, DOS FAT16 andFAT32, Minix fs, Linux ext2fs, kernel, JFS, XFS, and VSTa.

Grub can boot multiple systems (Backward compatibility for booting FreeBSD, NetBSD, OpenBSD, andLinux. proprietary kernels (such as DOS, Windows NT, and OS/2) are supportedvia a chain-loading function.

)

Bytes --------------------------------------------------------------------------------------------

Three steps for starting GRUB: Stage1Stage1.5Stage2

GRUB contains the following startup modules: two required scenario files (Stage1 and Stage2 ). Non-essential Stage1.5, first of all, have a general understanding of them.

Stage1

The first-stage code is stored in MBR. This Code contains a part pointing to GRUB, stage1_5, or Stage2 in the next stage of the list. Starting Stage1.5 does not depend on the file system where Stage2 is located.

12345678910111213 [root@www~] # Ddif =/dev/sdacount = 1of =/tmp/MBR # copy the MBR content to tmp 1+0records in 1+0recordsout 512bytes(512B)copied,0.000298384s,1.7MB /s [root@www~] # File/tmp/MBR # View file Types /tmp/MBR :x86bootsector;GRandUnifiedBootloader,stage1version0x3, bootdrive0x80,1stsectorstage20x849fe,GRUBversion0.94; partition1:ID=0x83,active,starthead32,startsector2048,1024000sectors; partition2:ID=0x8e,starthead221,startsector1026048,40916992sectors,codeoffset0x48 [root@www~] # [root@www~] # File/boot/grub/stage1 # the content of this file is the same as the 446-byte content in mbr. /boot/grub/stage1 :x86bootsector;GRandUnifiedBootloader,stage1version0x3, GRUBversion0.94,codeoffset0x48

Stage1.5

All the work of Stage1 is to load Stage 2 or Stage 1.5 from a local disk. Due to the limitation on the size of stage1 (446 bytes), the Code cannot be designed to be too complex and huge. It can only identify basic linux File Systems (file systems with fdisk-l ID 83 ), if it is another file system, the compromise solution is to load Stage1.5. Otherwise, Stage2 is directly loaded without loading Stage1.5. I believe you understand when to load Stage1.5 !!

[Root @ www ~] # Cd/tmp/

[Root @ www tmp] # cd/boot/grub/

[Root @ wwwgrub] # ls * stage1_5

E2fs_stage00005 ffs_stage00005 jfs_stage00005 reiserfs_stage00005 vstafs_stage00005

Fat_stage00005 iso9660_stage00005 minix_stage00005 ufs2_stage00005 xfs_stage00005

Stage2

The second-stage Code reads/boot/grub. conf to determine how to load the kernel and select which kernel to start (grub can guide different kernels) and display the grub menu. Stage2 code is stored in the file/boot/grub/stage2

######################################## ######################################

Grub repair

Grub damage can be solved in the following ways:

1. Use the original CD when installing the system, rescue mode

2. Use a mobile device with grub boot program installed

3. unmount the hard disk and mount it to a PC that can be properly started for repair.

If none of the above methods are met, the hard disk will be lost...

Use the third method to fix the problem:

--------------------------------------------------------

Manual destruction of grub partitions

[Root @ www tmp] # dd if =/dev/zero of =/dev/sda bs = 400 count = 1 # do not exceed 446 bytes, otherwise the partition will be damaged

1 + 0 records in

1 + 0 records out

400 bytes (400 B) copied, 0.000285534 s, 1.4 MB/s

[Root @ www tmp] # sync

[Root @ www tmp] # sync

[Root @ www tmp] # sync

[Root @ www tmp] # reboot

The operating system is not found after restart.

Insert a cd

Select rescue mode

Select language and keyboard types

Whether to enable the network function. Select NO.

Continue

You can see that the source disk is temporarily mounted to the/mnt/sysimage directory.

Select start shell

Switch root directory

Reinstall grub to the MBR sector. Note that it is the hard disk device of the boot system and cannot be installed to other hard disks and restarted simultaneously.

Grub repaired !!

######################################## ######################################## ############

Use GRUB boot System

GRUB is damaged, but the source disc is lost. You can also use a mobile device in your hands as a linux operating system to boot the mobile device (equivalent to winPE)

Modify the boot item to start from the mobile device (this step can be skipped, bios will scan from the first boot item until the boot partition is found)

Go to the grub command line interface:

---------------------------------------------

Set GRUB Password

Set a password to prevent others from maliciously modifying the root password in single-user mode, resulting in unnecessary losses

Place the password in grub. different Places in conf play different roles. One is to enter the password before you can use the command line mode of the grub menu for editing, one is to enter the password before starting the system (equivalent to setting the hard disk password)

Generate password:

[Root @ localhost ~] # Grub-md5-crypt

Password:

Retype password:

$1 $. Fn1S $ Q1dbZ39KfVf7Ot5UIn4vT. # copy the encrypted password

Modify configuration file

[Root @ localhost ~] # Vi/boot/grub. conf

Password -- md5 $1 $. Fn1S $ Q1dbZ39KfVf7Ot5UIn4vT. # password -- add the password generated by md5 to the corresponding location in the configuration file

Save, exit, restart, and take effect

#####

Clear Password

[Root @ localhost ~] # Vi/boot/grub. conf

Save it and restart it next time.

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.