This section learns the concept of grub, the sequence of boot calls, how to customize grub files, and how to debug some common system startup errors and so on.
Before learning the first 446 bytes of the MBR partition is the system boot program grub, the middle 64 bytes is the partition table, and the last 2 bytes represent the end. So how does grub work?
Simply put, the opportunity goes through the following steps:
BIOS self-test, check the hardware;
No file system exists on the activation mbr,mbr and can be viewed as part of the hardware, so it can be read directly
Grub is loaded into memory, generates a micro-system, and the micro-system has a compact file system built in
Through this micro-system, he will go to boot partitions, such as the default is generally sda1 up to find kernel files such as Vmlinuz, and then call the grub configuration file.
Grub mainly puts his configuration file in 3 places.
/boot/grub2/grub.cfg
/etc/grub.d/
/etc/default/grub
as shown below. Their relationship is grub.cfg inside through # # # #BEGIN ##### This format in order to invoke/ETC/GRUB.D inside the script to implement different functions. There are many scripts in the GRUB.D directory that start with numbers, which are executed in order from small to large. Take 00__header as an example, he will call the/etc/default/grub configuration file to achieve the most basic boot interface configuration.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4nraDDcfTAAE3n0vNdnY863.jpg "style=" float: none; "title=" 1.PNG "alt=" Wkiol1s4nraddcftaae3n0vndny863.jpg "/>
For example, in the/etc/grub2/grub.cfg file called/etc/grub.d/10_linux to configure a different kernel, there are 2 menuentry (menu entry), so we will see two default options when booting, one is the normal mode, One is rescue mode.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4nryj-JWlAAJIGoabzk4864.jpg "style=" float: none; "title=" 2.PNG "alt=" Wkiol1s4nryj-jwlaajigoabzk4864.jpg "/>
This is the/etc/default/grub file. Compared to other scripts, it's very simple and intuitive. The following example is how to modify
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4nfLjtlIDAAFFm5HPQoE249.jpg "style=" float: none; "title=" 3.PNG "alt=" Wkiom1s4nfljtlidaaffm5hpqoe249.jpg "/>
It is important to note that you must not directly modify the/etc/grub2/grub.cfg file. This is because if the kernel is upgraded later, all configurations will be invalidated. If you need to customize this file, we can modify the corresponding script or/etc/default/grub file, and then regenerate the Grub.cfg file via Grub2-mkconfig.
Here's a look at how to modify some simple settings.
Example 1: Modify the startup wait time
Default is 5 seconds
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B4/wKiom1S4nfXj0P_3AADgTDX0sOw052.jpg "style=" float: none; "title=" 4.PNG "alt=" Wkiom1s4nfxj0p_3aadgtdx0sow052.jpg "/>
I changed it to-1, then the boot must be manually confirmed.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4nsqSfZHJAAGHppxp3DI242.jpg "style=" float: none; "title=" 5.PNG "alt=" Wkiol1s4nsqsfzhjaaghppxp3di242.jpg "/>
Re-compile after modification
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B4/wKiom1S4nf-CwxDmAAE_MyuZEqw662.jpg "style=" float: none; "title=" 6.PNG "alt=" Wkiom1s4nf-cwxdmaae_myuzeqw662.jpg "/>
The boot will not automatically wait for the time, you must manually confirm
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4ns-hi_a-AADM4TZL5_c050.jpg "style=" float: none; "title=" 7.PNG "alt=" Wkiol1s4ns-hi_a-aadm4tzl5_c050.jpg "/>
Example 2 to modify the display name of the network card, which was mentioned in front of the networking configuration, here do not repeat.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4ngbQHj7sAAFF6vN0xXU188.jpg "style=" float: none; "title=" 8.PNG "alt=" Wkiom1s4ngbqhj7saaff6vn0xxu188.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B1/wKioL1S4nt-AhuI8AAGFeZGIA60439.jpg "style=" float: none; "title=" 9.PNG "alt=" Wkiol1s4nt-ahui8aagfezgia60439.jpg "/>
Example 3: Encrypting grub
When the interface is started, if you enter E, the editing window will open and we can enter rescue, emergency or shell mode as needed. How to restrict access.
At the end of the 00_header file, add the following:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B4/wKiom1S4nhaDVQMyAABI_y3Wbyo960.jpg "style=" float: none; "title=" 11.PNG "alt=" Wkiom1s4nhadvqmyaabi_y3wbyo960.jpg "/>
Re-compiling
After restarting, enter E and the user and password are required to enter the edit window.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4nuXg9VwoAABp9_ta0fY227.jpg "style=" float: none; "title=" 12.PNG "alt=" Wkiol1s4nuxg9vwoaabp9_ta0fy227.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4nu2iQCMWAAGyEedXW5o652.jpg "style=" float: none; "title=" 13.PNG "alt=" Wkiol1s4nu2iqcmwaagyeedxw5o652.jpg "/>
In this editing window, we can enter the 3 modes of rescue,emergency and shell boot as needed. These 3 modes are useful for system startup troubleshooting, such as a service that is stuck and unable to load. We can debug these 3 modes.
Rescue mode: Add S at the end of commandline configuration, like single user mode before RHEL6
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4niPwP6leAAHGihvhCbQ398.jpg "style=" float: none; "title=" 14.PNG "alt=" Wkiom1s4nipwp6leaahgihvhcbq398.jpg "/>
Normal mode needs to load a lot of services, but this rescue mode load is much less, enter the administrator password can be entered. Check out the configuration and logs for more information.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B1/wKioL1S4nvPR_RWsAAG0O7cUO3M030.jpg "style=" float: none; "title=" 15.PNG "alt=" Wkiol1s4nvpr_rwsaag0o7cuo3m030.jpg "/>
The emergency mode is similar to the rescue mode, but the service is less loaded, so change s to emergency.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4nvbRaLlyAAGQiemfbns832.jpg "style=" float: none; "title=" 16.PNG "alt=" Wkiol1s4nvbrallyaagqiemfbns832.jpg "/>
You need to enter the administrator password
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B4/wKiom1S4niqg2UQAAAF2SQCAEFM688.jpg "style=" float: none; "title=" 17.PNG "alt=" Wkiom1s4niqg2uqaaaf2sqcaefm688.jpg "/>
So what if I forget the root password?!
Delete Rhgb quiet in the last line of linux16 and add init=/bin/sh, which will replace the default daemon process with the shell
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4nvyjS6SQAADo6udeftk120.jpg "style=" float: none; "title=" 18.PNG "alt=" Wkiol1s4nvyjs6sqaado6udeftk120.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B4/wKiom1S4njOzTFQoAAGbjRqCmWA109.jpg "style=" float: none; "title=" 19.PNG "alt=" Wkiom1s4njoztfqoaagbjrqcmwa109.jpg "/>
Change the password after you come in, it seems not good.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4nwLj0NzaAAC4kIJJ8XM045.jpg "style=" float: none; "title=" 20.PNG "alt=" Wkiol1s4nwlj0nzaaac4kijj8xm045.jpg "/>
The reason is simple, the root load permission is RO, read-only
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B1/wKioL1S4nwWDw2J-AATFRr1mhsU682.jpg "style=" float: none; "title=" 21.PNG "alt=" Wkiol1s4nwwdw2j-aatfrr1mhsu682.jpg "/>
Permissions to reload into RW
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4nwrRIGyVAARBJ4bmyHI174.jpg "style=" float: none; "title=" 22.PNG "alt=" Wkiol1s4nwrrigyvaarbj4bmyhi174.jpg "/>
We can change the password at this time.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B4/wKiom1S4nj7x6elkAACWXChLF7E072.jpg "style=" float: none; "title=" 23.PNG "alt=" Wkiom1s4nj7x6elkaacwxchlf7e072.jpg "/>
Don't forget selinux, creating this file will automatically re-label when it's opened
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4nwzjWO4SAAAnyuH_jl8810.jpg "style=" float: none; "title=" 24.PNG "alt=" Wkiol1s4nwzjwo4saaanyuh_jl8810.jpg "/>
Reboot to see
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4nkDDiLJLAADop_uVW-E787.jpg "style=" float: none; "title=" 25.PNG "alt=" Wkiom1s4nkddiljlaadop_uvw-e787.jpg "/>
Boot Troubleshooting tips:
Example 1. What to do if the grub file is broken, like below I've written the first 446 bytes in 0.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B1/wKioL1S4nxGSgnEcAAB5ZyMFeVM820.jpg "style=" float: none; "title=" 26.PNG "alt=" Wkiol1s4nxgsgnecaab5zymfevm820.jpg "/>
Boot will automatically try to load the bootloader from the local, CD-ROM and network, this is loaded from my CD, because the local boot program is no longer
Choose Troubleshooting (Check the wrong)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B4/wKiom1S4nkXQT9ePAAC7N2cHeIA845.jpg "style=" float: none; "title=" 27.PNG "alt=" Wkiom1s4nkxqt9epaac7n2cheia845.jpg "/>
Select rescue
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4nxXjFhwzAAErhWzpSY8145.jpg "style=" float: none; "title=" 28.PNG "alt=" Wkiol1s4nxxjfhwzaaerhwzpsy8145.jpg "/>
Choose Continue, pay attention to have patience wait a bit more, sometimes will card 10 seconds to react
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B4/wKiom1S4nkmjh_s5AAGB_dXftRI296.jpg "style=" float: none; "title=" 29.PNG "alt=" Wkiom1s4nkmjh_s5aagb_dxftri296.jpg "/>
Check the prompt, the system is mounted to/mnt/sysimge inside, confirm OK
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B1/wKioL1S4nxiwXPheAAECTHVL8Tw407.jpg "style=" float: none; "title=" 30.PNG "alt=" Wkiol1s4nxiwxpheaaecthvl8tw407.jpg "/>
Follow the prompts to switch the root-to-native system
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4nk3T9tJIAADSenutwJQ242.jpg "style=" float: none; "title=" 31.PNG "alt=" Wkiom1s4nk3t9tjiaadsenutwjq242.jpg "/>
Fdisk-l See what the boot partition is, with an asterisk
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4nk_SeQwxAAC3d2tPnvA534.jpg "style=" float: none; "title=" 32.PNG "alt=" Wkiom1s4nk_seqwxaac3d2tpnva534.jpg "/>
Reload the GRUB2 to the boot partition.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B4/wKiom1S4p36QhgWTAABSx1J90g0697.jpg "style=" float: none; "title=" 33.PNG "alt=" Wkiom1s4p36qhgwtaabsx1j90g0697.jpg "/>
Restart okay
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B1/wKioL1S4qE6SPQzKAACtNrs_Q7U263.jpg "style=" float: none; "title=" 34.PNG "alt=" Wkiol1s4qe6spqzkaactnrs_q7u263.jpg "/>
Example 2: What to do if the grub bootloader is not a problem, but we delete the kernel file or the Grub.cfg configuration file
Take a look at what documents are currently available, all deleted.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4p4vAQRFPAAGuRfUCRvc533.jpg "style=" float: none; "title=" 35.PNG "alt=" Wkiom1s4p4vaqrfpaagurfucrvc533.jpg "/>
After restarting, go directly to the Grub rescue mode, which indicates that the boot program has a problem with the wood, but the boot file cannot be found.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B1/wKioL1S4qFyhTojQAABgmnHU7HM647.jpg "style=" float: none; "title=" 36.PNG "alt=" Wkiol1s4qfyhtojqaabgmnhu7hm647.jpg "/>
As before, the disc starts
Switch the root directory, mount the disc to/iso, and look at the/boot directory, empty, kernel files and configuration files are gone.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B2/wKioL1S4qejD0N2mAAAy0QurDe4920.jpg "style=" float: none; "title=" 37.PNG "alt=" Wkiol1s4qejd0n2maaay0qurde4920.jpg "/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B4/wKiom1S4qRug9WoAAAAcgBlhSbo845.jpg "style=" float: none; "title=" 38.PNG "alt=" Wkiom1s4qrug9woaaaacgblhsbo845.jpg "/>
If you don't, then install it from scratch, install the kernel with RPM or yum, use Yum to uninstall the current, then install, and RPM to force--force overwrite the installation.
Install with Yum
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/B2/wKioL1S4qeuwfSSoAAHlTAmL78g621.jpg "style=" float: none; "title=" 39.PNG "alt=" Wkiol1s4qeuwfssoaahltaml78g621.jpg "/>
or RPM (Here I repeat 2 times, because of the graphical interface, I thought there was something wrong)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/58/B4/wKiom1S4p57zbtfgAAJ172fzjEM395.jpg "style=" float: none; "title=" 44.PNG "alt=" Wkiom1s4p57zbtfgaaj172fzjem395.jpg "/>
After installing the kernel, reinstall GRUB2, enter GRUB2-INSTALL/DEV/SDA, and recompile grub2.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/B2/wKioL1S4qG6htjJzAAE2UlqW5-o020.jpg "style=" float: none; "title=" 45.PNG "alt=" Wkiol1s4qg6htjjzaae2ulqw5-o020.jpg "/>
Restart
After the restart, I also met 2 questions, the first problem is the start of the display I/O errors, longitude Niang Google confirmed that the floppy drive can be switched off;
The second problem is the boot directly into the command line mode, even if the runlevel display is 5, manual input StartX the same error. The workaround is to reinstall the graphical interface
Yum Grouplist
Yum Groupinstall ' Server with GUI '
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1604763
RHCE Learning Notes grub and boot troubleshooting