In the previous study, we talked about reading the boot loader from the mbr of the first boot device after reading the BIOS information. Boot loader is used to load the kernel. Next, let's take a look at this boot loader.
Let's first look at the MBR composition diagram.
We can know that MBR is only 512 bytes in size, and bootloader only occupies 446 bytes, in addition, the 64-byte partition table information (a partition requires 16 bytes, Which is why only four primary partitions can be divided) and 2-byte magic number. The size of GRUB is definitely more than 512 bytes. How can it let go of the extra stuff?
Learn about the content in the/boot/grub directory.
Let's take a look at what is stored in the/boot/grub directory.
[Root @ yufei ~] # Ls-l/boot/grub/
Total 272
-Rw-r-. 1 root 63 Dec 15 device. map
-Rw-r-. 1 root 13216 Dec 15 e2fs_stage1_5
-Rw-r-. 1 root 12528 Dec 15 fat_stage00005
-Rw-r-. 1 root 11760 Dec 15 ffs_stage00005
-Rw ---. 1 root 788 Jan 2 21:08 grub. conf
-Rw ---. 1 root 788 Jan 2 20:58 grub. conf. bak
-Rw-r-. 1 root 11768 Dec 15 iso9660_stage00005
-Rw-r-. 1 root 13232 Dec 15 jfs_stage1_5
Lrwxrwxrwx. 1 root 11 Dec 15 menu. lst->./grub. conf
-Rw-r-. 1 root 11952 Dec 15 minix_stage1_5
-Rw-r-. 1 root 14312 Dec 15 reiserfs_stage1_5
-Rw-r-. 1 root 1341 May 7 2010 splash.xpm.gz
-Rw-r-. 1 root 512 Dec 15 stage1
-Rw-r-. 1 root 113056 Dec 15 stage2
-Rw-r-. 1 root 12020 Dec 15 ufs2_stage1_5
-Rw-r-. 1 root 11376 Dec 15 vstafs_stage1_5
-Rw-r-. 1 root 13944 Dec 15 xfs_stage1_5
We pay special attention to the size of the stage1 file, and find that it is exactly 512 bytes. Let's take a look at the attributes of this file.
[Root @ yufei grub] # file stage1
Stage1: x86 boot sector; GRand uniied Bootloader, stage1 version 0 × 3, GRUB version 0.94, code offset 0 × 48
This file is very interesting. It is the Boot Sector of X86, GRand uniied Bootloader (GRUB)
Through the above, we can draw a conclusion that (I personally think) This stage1 is MBR. Therefore, Stage1 is the main program that executes the boot loader, which is installed in our boot sector.
Let's take a look at this stage2.
[Root @ yufei grub] # hexdump-C stage2
For example
Although we don't understand the code, we can find something on the right.
This file will load the/boot/grub. conf file.
We can see many * stage00005 files in the/boot/grub directory. What are these files?
Haha, my understanding is something about transition, just like a bridge between stage1 and stage2. So they are all stage1_5 (just like 1-1.5-2 ). These files are some identification files for different file system formats.
Finally, the two files named device.mapand splash.xpm.gz are retrieved.
[Root @ yufei grub] # file device. map
Device. map: ASCII text
[Root @ yufei grub] # cat device. map
# This device map was generated by anaconda
(Hd0)/dev/sda
Did you see it? He recorded the location where grub was installed.
[Root @ yufei grub] # gunzip splash.xpm.gz
[Root @ yufei grub] # file splash. xpm
Splash. xpm: X pixmap image text
See it. This is an image. It is the background image under grub when the system is started.
[Root @ yufei grub] # ls-l menu. lst
Lrwxrwxrwx. 1 root 11 Dec 15 menu. lst->./grub. conf
This file is clear at a glance. A connection file and the specific content in this file will be discussed later.
The contents in the/boot/grub directory are all described.
The following is the relationship between GRUB and the boot sequence.
1. the BIOS delivers control to the Master Boot area of the hard disk, that is, MBR.
2. the bootloader (stage1) in MBR loads * stage00005 through the built-in Address.
3. the bootloader loads the stage2 in the partition through * stage1_5.
4. In this case, stage2 can load the grub. conf file in the file system so that you can see the option interface.
Learn about/boot/grub. conf
[Root @ yufei grub] # vim grub. conf
Remove the preceding comments and view the content directly.
Default = 0
Timeout = 5
Splashimage = (hd0, 0)/boot/grub/splash.xpm.gz
Hiddenmenu
Title Red Hat Enterprise Linux (2.6.32-71. el6.i686)
Root (hd0, 0)
Kernel/boot/vmlinuz-2.6.32-71.el6.i686 ro root = UUID = export rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG = en_US.UTF-8 KEYBOARDTYPE = pc KEYTABLE = us nomodeset crashkernel = auto rhgb quiet
Initrd/boot/initramfs-2.6.32-71.el6.i686.img
Default = 0 indicates the default project selected during startup. This item must be compared with the following title. 0 indicates a title, 1 indicates a second title, and so on.
Timeout = 5 If hiddenmenu is set, wait for 5 seconds. If no key is pressed, the default title item is executed.
Splashimage = (hd0, 0)/grub/splash.xpm.gz the background image displayed in the options.
Hiddenmenu does not display options.
Title Red Hat Enterprise Linux (2.6.32-71. el6.i686) name displayed in the options.
Root (hd0, 0) sets the disk location of the kernel
Initrd/boot/initramfs-2.6.32-71.el6.i686.img set initrd (virtualization disk) image file name
Initrd is called the initialization virtual disk. It is used to help load the kernel module, so that the Linux kernel can load the required modules without mounting the root directory during the boot process. If your filesystem is LVM, Raid, or the hard disk is a SCSI interface (including SATA and USB interfaces), the Linux kernel cannot recognize these devices and thus cannot start properly. Initrd can read the kernel module (driver) through the int13 chip. When the hard disk is driven, the kernel can mount the root directory. Read from other modules.
Root = UUID = export rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG = en_US.UTF-8 KEYBOARDTYPE = pc KEYTABLE = us nomodeset crashkernel = auto rhgb quiet
In RHEL6, this is a little different from the previous version.
Kernel/boot/vmlinuz-2.6.32-71.el6.i686 ro root = LABEL =/1 rhgb quiet
Now it is changed to the above format, and the hard disk partition is now replaced by UUID, which actually represents a meaning. Some startup parameters, such as LVM, RAID, keyboard, and language environment, are added later. Rhgb indicates the color, and quiet indicates static startup (some information is completely blocked ). You can view the UUID of a hard disk partition through dumpe2fs/dev/sda1 | more.
Hard Disk Partition representation in GRUB
GRUB requires that the device name be included in one. Fd indicates a floppy disk, while hd indicates a hard disk (not an IDE or SCSI hard disk ). Second, the device is numbered from 0, and the same is true for the partition. Separate the partition from the device with a comma. If no partition is specified, the entire device is used. Otherwise, only the specified partition is used.
Code of the hard disk search sequence in GRUB
First
(Hd0) (hd0, 0) (hd0, 1) (hd0, 4) (hd0, 5 )... ...
Second
(Hd1) (hd1, 0) (hd1, 1) (hd1, 4) (hd1, 5 )... ...
Third
(Hd2) (hd2, 0) (hd2, 1) (hd2, 4) (hd2, 5 )... ...
Fourth
(Hd3) (hd3, 0) (hd3, 1) (hd3, 4) (hd3, 5 )... ...
... ...
If there are any errors in this article, please contact me as soon as possible.
Keyword: One day, learn Linux, RHEL6, GRUB, MBR, boot loader
From: yufei blog