Multi-OS Boot Manager Grub learning in Linux systems

Source: Internet
Author: User
Tags crypt md5 md5 encryption uuid password protection

Note: The following learning is done on the Linux system under the CPU of the X86 architecture.

I. Introduction to the Linux system startup process

Post post-load bios--> read mbr--> start boot loader/grub program-load kernel-user layer init according to the Inittab file to set the run level- The INIT process executes rc.sysinit--> boot the kernel module and executes a different runlevel of the script--and executes the/etc/rc.d/rc.local--> execution/bin/login program, into the login state

The above is the Linux system boot detailed steps, specific each block in the boot step of the content here do not do too much introduction.


Ii. introduction of MBR

The MBR is the abbreviation of the English Master boot record, and the Chinese meaning is the main guide record. The first sector of the hard disk's 0 tracks is called the MBR, and its size is 512 bytes, and this area can be divided into two parts. The first part is the Pre-Boot area (pre-boot area), accounting for 446 bytes; The second section is the partition table area (partition table), which accounts for 66 bytes. At the same time, a boot loader called boot Loader is written to the MBR in 512 bytes, and there are two separate LILO (LInux Loader) and grub (GRand Unified Bootloader), which are now commonly used for grub, and the following is a simple Learn how to use grub alone.


Iii. Introduction of Grub

1. What is Grub

GRUB is the boot loader (boot loader)-it is responsible for loading the kernel and booting the Linux system. GRUB can also boot other operating systems, such as FreeBSD, NetBSD, OpenBSD, GNU HURD and DOS, and Windows systems. Although booting the operating system looks like an ordinary and trivial task, it is actually important. If the boot loader does not perform well or is not resilient, it is possible to lock the system and not boot the computer. Also, a good boot loader gives you the flexibility to install multiple operating systems on your computer without having to deal with unnecessary hassles.


2. Functionality of GRUB

1) Select the kernel or system to start;

2) can go into the Grub interactive interface for related operations (when the system starts by pressing the E key to enter);

3) password protection based on access to the grub operation, there are two types of password protection: the first to enable the password protection of the kernel image, to make this kind of protection must be generated password text into the response title, the second is actually into the grub of the editing mode of protection, to make such protection must be The generated password text is placed in the global segment.


3. Introduction to Grub Core file

[Email protected] grub]# ls/boot/grub/

Device.map grub.conf minix_stage1_5 Stage2

E2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5

Fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5

Ffs_stage1_5 menu.lst Stage1 xfs_stage1_5


Stage1: Usually it is embedded into the MBR. Or an area of the Guide Sector of a partition. Because the boot sector of the PC is 512 bytes, stage1 is also 512 bytes. The Stage1 function is to load Stage 2 or stage 1.5 from a local disk. Because of the large and small limitations, stage1 encodes the location of the Stage2 or stage 1.5, that is, Stage1 is unable to recognize the file system format.


Stage 1.5: Their purpose is to build a bridge between Stage1 and Stage2, that is, Stage 1 loading stage 1.5, stage 1.5 loading stage2. The difference between Stage1 and stage 1.5 is that STAGE1 does not recognize the file system, and stage 1.5 can. Because the Stage2 is too large to be embedded in a fixed area, the Stage1.5 can be installed in the location after the MBR.


Stage2: This is the core boot program for GRUB. It almost does everything except launch itself, usually it is stored under a file system, but not necessarily under the filesystem.


4 . Introduction to Grub configuration file grub.conf

[email protected] grub]# cat grub.confdefault=0timeout=5splashimage= (hd0,0)/grub/splash.xpm.gzhiddenmenutitle CentOS 6 (2.6.32-504.el6.x86_64) root (hd0,0) kernel/vmlinuz-2.6.32-504.el6.x86_64 ro root=uuid= Ba513d9f-378e-4024-af2e-ca76e97129ea nomodeset rd_no_luks keyboardtype=pc keytable=us Rd_NO_MD crashkernel=auto LANG= Zh_cn. UTF-8 RD_NO_LVM rd_no_dm rhgb quiet initrd/initramfs-2.6.32-504.el6.x86_64.img


A) Default: Defines the operating system that is booted from the defaults. 0 represents the first operating system, 1 means 2nd, and so on.

b) Timeout: Defines in how many seconds the operating system specified by default is automatically booted if the user does not press a key on the keyboard.

c) splashimage define the Grub interface background picture (/boot/grub/splash.xpm.gz picture file).

d) Hiddenmenu: Used to hide the menu at startup, unless you press ESC before timeout to see the menu.

E) Title: Defines the name of the boot project.

f) Root: Sets the root device of grub, which is the partition where the kernel resides.

Device (disk) representation: In Grub, all start with HD and follow a number to mark each disk device, starting with 0

Part representation: Represents the partition, numbering starts at 0.

g) Kernel: Defines the file to be used, which can be appended to the boot parameters passed to the kernel.

Specifying kernel files and parameters passed to the kernel

Parameters: Ro root= device file, quiet silent mode output, use RO read-only method, avoid changing kernel files.

h) INITRD: Specifies the RAM disk or RAM FS file that provides additional driver functionality for the kernel.

Files: typically archive for cpio and use gzip compression, usually with. img As the file suffix name

You can also encrypt grub with the following:

i) Password: Used to define the password to enter the GRUB command mode. You can also define a password for each operating system by placing the password command after the title line. and each operating system's boot password can be different, but also to enter the command mode of the same password, the maximum degree of security to ensure GRUB.

Note: In general, the startup of Linux operating system, including four lines; title line; root line; kernel line; initrd line;


5, boot into the grub introduction

650) this.width=650; "title=" 1.png "src=" Http://s3.51cto.com/wyfs02/M01/70/2E/wKioL1WznGGCZOLdAAEb6Kwmrj8827.jpg " alt= "Wkiol1wznggczoldaaeb6kwmrj8827.jpg"/>


The way to enter this interface is to press the E key after the Linux system starts to enter this interface, the following is a brief introduction to this interface:

The first behavior of the grub version number;

The second behavior a box shows the enumeration of this operating system kernel;

Finally, the introduction of the command, the upper and lower key is to select the kernel, e key is to enter the editing command, a key is to modify the kernel kernel parameter, c key is to enter the command line.


Here is the result of pressing the E key into the edit command:

650) this.width=650; "title=" 2.png "src=" Http://s3.51cto.com/wyfs02/M01/70/31/wKiom1WzmpbQZJgiAAGEMZKLAAQ651.jpg " alt= "Wkiom1wzmpbqzjgiaagemzklaaq651.jpg"/>

Introduction to the command:

The next key is to select the option to edit, the B key is to enter the system, e key to edit the selected command, the C key is to enter the command line, O key is to add a blank line, d delete the selected row.


Through the introduction of this section we have learned how to operate in the Grub window, here is a tip, in the figure of this section, press the A key or the Kernerl option selected in Figure two to press the E key will enter the kernel file by typing parameters to operate the kernel, usually type 1,s, single, S press ENTER to return to the interface of Figure two, press the B key into the single-user mode, after entering the single-user mode, you can change the root account password. From this point of view even if there is no user root password can change the root password and access to the Linux system, so it is very dangerous, one of the solutions is that we can enter grub to set a password to achieve protection, the next section is about how to operate.


6. Set the password for grub

To generate a MD5 encrypted password:

[[email protected] ~]# grub-md5-crypt   // The password is set to Linux password:retype password: $1$5sbll$wxw/g5lolg.cbzu/kkrus. [[email protected] ~]# grub-md5-crypt   //Password is set to redhatpassword:retype  Password: $1$rybll$vry3ykxqldzii1qpooc2h1[[email protected] ~]# cat /etc/grub.conf  default=0timeout=5splashimage= (hd0,0)/grub/splash.xpm.gzhiddenmenupassword --md5 $1$5sbll$wxw/ g5lolg.cbzu/kkrus.title centos 6  (2.6.32-504.el6.x86_64) root  (hd0,0) kernel / vmlinuz-2.6.32-504.el6.x86_64 ro root=uuid=ba513d9f-378e-4024-af2e-ca76e97129ea nomodeset  Rd_no_luks  keyboardtype=pc keytable=us rd_no_md crashkernel=auto lang=zh_cn. Utf-8 rd_no_lvm rd_no_dm rhgb quietinitrd /initramfs-2.6.32-504.el6.x86_64. IMGPASSWORD --MD5 $1$RYBLL$VRY3YKXQLDZII1QPOOC2H1 


Self-set two MD5 encryption password, respectively placed in the title before and after the configuration file at the end, due to the different places brought the meaning of the same. Restart the system below to see the difference between the two seats.


650) this.width=650; "title=" 3.png "src=" Http://s3.51cto.com/wyfs02/M02/70/2E/wKioL1WznJ6jpVEaAAEn8jP5qWU028.jpg " alt= "Wkiol1wznj6jpveaaaen8jp5qwu028.jpg"/>


This is placed before the title of the password set, after typing e will enter the interface, you need to type the P key to enter the password to enter the Grub debugging interface.


650) this.width=650; "title=" 4.png "src=" Http://s3.51cto.com/wyfs02/M02/70/31/wKiom1WzmtCxAQIUAAHrDQ9kcrM970.jpg " alt= "Wkiom1wzmtcxaqiuaahrdq9kcrm970.jpg"/>


Enter the grub password after entering the kernel will display the interface, will increase the password this line of information, type B key to enter the system will be prompted to enter the password password, That is, in the grub.conf configuration file is the last defined password, after entering the password to start the system, and if the password is set in the future in the system boot regardless of whether or not to enter the grub interface to enter the GRUB.CONF profile defined in the last password, if you do not want to enter the grub.conf configuration file defined by the most After entering the system password, you can move the cursor to the password option type D key Delete, type B key to enter the system without entering the password, do not change the grub configuration file, This allows you to enter the system by typing the password at least once when you want to enter the system when the two passwords are set in the grub.conf configuration file.


7. Grub configuration file is missing

In daily learning if we accidentally lost or damaged the grub configuration file, without knowing that the system will go directly to the GRUB command line interface, the following describes how to resolve this problem:

Manually move the configuration file elsewhere on the command line:

[[email protected] ~]# Mv/boot/grub/grub.conf/boot/grub/grub.conf.bak//Manually move the configuration file elsewhere, this operation will affect the normal startup of the system, with caution. [[email protected] ~]# LS/DEV/ROOT-LH//view root disk partition location, in the future if you forget can only try lrwxrwxrwx 1 root root 4 July 02:55/dev/root-& Gt Sda5[[email protected] ~]# shutdown-r now


650) this.width=650; "title=" 5.png "src=" Http://s3.51cto.com/wyfs02/M00/70/2E/wKioL1WznNijjOpQAAG1hJuJAE8562.jpg " alt= "Wkiol1wznnijjopqaag1hjujae8562.jpg"/>

After rebooting the system because there is no grub configuration file We will enter the GRUB command line interface, after entering the above command, you can type the boot command to restart the system, it is important to note that your root disk partition, and the kernel version must be consistent. After rebooting the system, we are configuring the Grub configuration file from the new brief, as follows:

[Email protected] ~]# cat/boot/grub/grub.confdefault=0timeout=5title= CentOS 6.6root (hd0,0) kernel/ vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/sda5initrd/initramfs-2.6.32-504.el6.x86_64.img


8.Boot Loader is damaged

[[email protected] ~]# dd If=/dev/zero OF=/DEV/SDA bs=100 count=1//note can only destroy the first 446 bytes, if the disk partition 64 bytes also destroyed this method can not repair recorded 1+0 read record 1+0 Write 100 bytes (+ B) copied, 0.00361351 sec, 27.7 kb/sec


650) this.width=650; "title=" 6.png "src=" Http://s3.51cto.com/wyfs02/M00/70/31/wKiom1WzmwmznmG6AAD5poHDS-U646.jpg " alt= "Wkiom1wzmwmznmg6aad5pohds-u646.jpg"/>


After encountering this situation need to use the CD-ROM into the emergency rescue mode and into the shell environment of the CD, the middle how to enter the rescue mode here is not more introduction, here to note that the system version of the disc must be consistent with the repair system version.


650) this.width=650; "title=" 7.png "src=" Http://s3.51cto.com/wyfs02/M01/70/2E/wKioL1WznQ_incyDAAFl8qdQIIE254.jpg " alt= "Wkiol1wznq_incydaafl8qdqiie254.jpg"/>

650) this.width=650; "title=" 8.png "src=" Http://s3.51cto.com/wyfs02/M00/70/2E/wKioL1WznR_TJ7g3AAFK3D4zI4U092.jpg " alt= "Wkiol1wznr_tj7g3aafk3d4zi4u092.jpg"/>


Through the above emergency rescue mode operation, the system can be restarted normally into the Linux system.


9. Grub Entire Directory is deleted

[Email protected] ~]# rm-rf/boot/grub/[[email protected] ~]# shutdown-r now

Because the virtual machine enters the BIOS time is short, it can be used on the virtual machine software on the system boot directly into the BIOS option:

650) this.width=650; "title=" 9.png "src=" Http://s3.51cto.com/wyfs02/M02/70/2E/wKioL1WznTnTC-YyAAGXnMz5Gwc659.jpg " alt= "Wkiol1wzntntc-yyaagxnmz5gwc659.jpg"/>


Error 15 will appear after a reboot. Continue loading the disc into emergency rescue mode, remember that the system version of the disc must be consistent with the version of the repair system.


650) this.width=650; "title=" 10.png "src=" http://s3.51cto.com/wyfs02/M00/70/2E/wKioL1WznVXCg45GAAJtL_4tgL8420.jpg "alt=" Wkiol1wznvxcg45gaajtl_4tgl8420.jpg "/>


Enter the following in the grub configuration file grub.conf:

default=0timeout=5title= CentOS 6.6root (hd0,0) kernel/vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/sda5initrd/ Initramfs-2.6.32-504.el6.x86_64.img


By rebooting the System key can enter the Linux system, the above is about the grub related knowledge of learning, although we can repair grub, but the test of the broken grub file commands do not mess with.


This article is from the "Bread" blog, make sure to keep this source http://cuchadanfan.blog.51cto.com/9940284/1678366

Multi-OS Boot Manager Grub learning in Linux systems

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.