Understand Grub in Linux

Source: Internet
Author: User
Grub configuration file: [root @ lyygrub] # ll total 199-rw-r -- r -- 1rootroot6010-2620: 05device. map # grub device file-rw-r -- 1rootroot758410-2620: 05e2fs_stage1_5 # ext2/ext3...

Grub configuration files:
[Root @ lyy grub] # ll
Total 199
-Rw-r -- 1 root 60 10-26 20:05 device. map # file of the grub device
-Rw-r -- 1 root 7584 10-26 20:05 e2fs_stage1_5 # ext2/ext3 file system definition file
-Rw-r -- 1 root 7456 10-26 20:05 fat_stage00005 # Definition File of FAT file system
-Rw-r -- 1 root 6720 10-26 ffs_stage00005 # Definition File of FFS file system
-Rw-r -- 2 root 195 11-20 grub. conf # grub configuration file in Red Hat
-Rw-r -- 1 root 6720 10-26 20:05 iso9660_stage00005 # Definition File of the optical drive File system
-Rw-r -- 1 root 8192 10-26 20:05 jfs_stage00005 # file system definition file
-Rw-r -- 2 root 195 11-20 12:21 menu. lst # boot menu configuration file
-Rw-r -- 1 root 6880 10-26 20:05 minix_stage1_5 # file system definition file
-Rw-r -- 1 root 9248 10-26 20:05 reiserfs_stage00005 # file system definition file
-Rw-r -- 1 root 512 10-26 20:05 stage1
-Rw-r -- 1 root 104988 10-26 20:05 stage2
-Rw-r -- 1 root 7072 10-26 20:05 ufs2_stage00005 # file system definition file
-Rw-r -- 1 root 6272 10-26 20:05 vstafs_stage00005 # file system definition file
-Rw-r -- 1 root 8904 10-26 20:05 xfs_stage00005
Code of the hard disk and partition in grub
The grub main program loads core files from a disk, so it must know the hard disk. Grub hard disk code setting and
The traditional linux disk code can be completely different, such:
(Hd0, 0)
The hard disk code is enclosed in parentheses;
Hard disk in hd format, followed by a group of numbers;
Use [search order] as the hard disk number, instead of sorting by hard disk line;
The first hard disk is 0, the second is 1, and so on;
The first partition code of each hard disk is 0, and so on.
The first logical partition code of the first hard disk is (hd0, 4 ).
/Boot/grub/menu. lst configuration file
[Root @ lyy grub] # cat menu. lst
Default = 0 # default boot, default first title Project
Timeout = 5 # stay for five seconds. what is the keyboard selection? Recognize
Splashimage = (hd0, 0)/grub/splash.xpm.gz # file where the background graph is located
Hiddenmenu # hide the complete boot menu by default
Title redhat enterprise server 5.4
Root (hd0, 0) # partition of core files
Kernel/vmlinuz-2.6.18-164.el5 ro root = LABEL =/rhgb quiet rhgb
Initrd/initrd-2.6.18-164.el5.img
Root (hd0, 0) partition of the core file, rather than the root directory.
After the kernel is followed by the Core name, it is the core parameter. Root = LABEL =/mount/directory rhgb for color display quiet mode
Initrd followed by virtual file system name
Root = LABEL =/can be written as root =/dev/hda2
1. test and install grub
Use grub-install to copy some necessary files to/boot/grub.
For example, if grub is installed in the MBR of the current system, my system is/dev/hda.
[Root @ lyy grub] # grub-install/dev/hda
If a grub error occurs and grub cannot be started, you can use a CD with grub boot, and then use the grub
You can use the core file on the hard disk to start the instance.
2. add a password to a specific menu
For example, add the MD5 password to the system's first boot menu and lock the online editing function.
1. create a password encrypted with MD
[Root @ lyy ~] # Grub-md5-crypt
Password:
Retype password:
$1 $ vX3Mu/$ msyisCLVKaZh1offoGYF2. # Password processed by MD5
2. add the generated password to/boot/grub/menu. lst.
[Root @ lyy grub] # vi menu. lst
Default = 0
Timeout = 5
Hiddenmenu
Title redhat enterprise server 5.4
Password -- md5 $1 $ eU4Mu/$ 0BvMemF2AVPO. BYbh3/e2/
Root (hd0, 0 )_
Kernel/vmlinuz-2.6.18-164.el5 ro root = LABEL =/rhgb quiet rhgb
Initrd/initrd-2.6.18-164.el5.img
Note that this password is added to the first line below the title
3. after the above simple steps, the password is completed, but grub's online editing function can still skip the password, so we
You need to lock the online editing function.
Default = 0
Timeout = 5
Password -- md5 $1 $ eU4Mu/$ 0BvMemF2AVPO. BYbh3/e2/# global control
Hiddenmenu
Title redhat enterprise server 5.4
Lock # added this function
Root (hd0, 0 )_
Kernel/vmlinuz-2.6.18-164.el5 ro root = LABEL =/rhgb quiet rhgb
Initrd/initrd-2.6.18-164.el5.img
III. Solve the init configuration file error
We all know that run level 0-6 reads/etc/inittab. if some files are incorrectly configured, they cannot be read.
Run level cannot read/etc/inittab to start the system. at this time, we can tell the core not to execute init to call bash.
For example, use the online editing function in the grub menu when the instance is started. modify the following:
Grub edit & gt; kernel/vmlinuz-2.6.18-92.el5 ro root = LABEL =/rhgb quiet init =/bin/bash
In this way, the first program of the system call is changed to/bin/bash, so/sbin/init will not be executed.
However, in addition to the root directory, other directories are not mounted and the root directory is read-only. we also need the following command:
To repeatedly mount the root directory
Mount-o remount, rw/# remount to become erasable
Mount-a # remount the file system according to/etc/fstab.

Author "Liyy study notes"

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.