The grub thing.

Source: Internet
Author: User
Tags password protection

Introduction to Grub:

Grub is a shorthand for grand Unified bootloader, which translates into a unified boot loader that is Bull X, born under the backdrop of a huge flaw in Lilo's inability to recognize disk 1024 cylinders. So far it has been divided into two versions of Grub 0.x (Grub Legacy) and Grub 1.x (Grub 2), this is about grub legacy.

Grub function;

Supports multi-system coexistence, provides menu options, can pass parameters to the kernel, and provides protection mechanisms.

Grub principle:

It has been said that grub is divided into three stages, namely:

Stage 1: Remember the previous MBR, in that 446K is bootloader? Yes, because only 446K, to accomplish this function is almost impossible, so it is divided into 3 paragraphs, and the first paragraph is in the MBR, is to load the operating system on the hard disk into memory.

Stage 1.5: We all know that under the operating system the hard disk must be formatted as a file system in order to store data, and the kernel is exactly in the operating system of the hard disk (or what to talk about booting the operating system), then want to read the data inside must have the corresponding file system driver, The 1.5 stage is that the sector behind the MBR is stored with a basic filesystem driver (and therefore does not support those such as LVM, because it is only basic AH), so the so-called 1.5 phase is to identify 2 stages.

Stage 2: With the 1.5-stage driver, you can load the kernel and Dandisk files that were placed on the disk partition in 2 stages into memory. This partition is known as the/boot/, under which there are grub and vmlinuz-versions-the hair model and the initramfs-version-the hair model (again the two version number and the hairstyle number must be the same, in 5 is the initrd-version-the hair model).

To start the system from the GRUB command line:

As I said earlier, grub can provide menus, but this menu is not just about selecting enter and starting the operating system, but also editing the menu (by e), and booting with the command line (press E and select the kernel to enter by C).

650) this.width=650; "title=" capture. PNG "src=" Http://s5.51cto.com/wyfs02/M02/7E/16/wKiom1b3Q7rgj7uKAAAe8iK4x0o445.png "alt=" Wkiom1b3q7rgj7ukaaae8ik4x0o445.png "/>

See the following tip, use the up and down arrows to select the menu (but there is only one), press ENTER to start the selected operating system, press E to edit the selected menu, press A to modify the details, press C to enter the command line mode. Here we press C to go in.

650) this.width=650; "title=" capture. PNG "src=" Http://s4.51cto.com/wyfs02/M00/7E/12/wKioL1b3RcyBBw4gAAAYjZEBzcs793.png "alt=" Wkiol1b3rcybbw4gaaayjzebzcs793.png "/>

Just like this, you can enter help to see the assistance, or "help keyword" to look at the specified assistance, you can find the file you want to find, OK now first let grub know where its root is (people should be so, not forggestting AH), here use root (hd#,# In this way, where HD is representing the disk, this is not the same as what the current system SD is, and the first # number represents the disk, and the second # number represents the first partition. Then there is the vmlinuz-version under Kernel grub root-the model, the location of the specified kernel, and then the initramfs-version under INITRD grub root-the model, specifying the location of the Dandisk file. Note here: These two numbers start from 0, meaning that the first 0 represents the first hard disk, the 20th is the first partition, and so on. And this root is not the root filesystem "/", but the root of grub, if your/boot is partitioned separately, then please write down your partition number (recommended on the first partition), that partition is the root of grub, if your/boot is not separate partition (in fact, this is irrational), Then boot at the root of the filesystem is the root of grub. I am partitioned separately here.

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M01/7E/16/wKiom1b3SNKQudT9AAAeIEJyLsk102.png "alt=" Wkiom1b3snkqudt9aaaeiejylsk102.png "/>

My grub root is a separate partition for/boot, this partition is in the first partition under the first disk of my virtual machine, so it is (hd0,0), and Vmlinuz and Initramfs are in grub root/boot, so just write from/start (again this/ is not a file system/, unless your/boot does not have separate partitions, it is/boot/start). Similarly initrd also this meaning, and kernel that the file system must be read-only hanging, but also to specify the root filesystem in which location, otherwise grub how to know, of course, this line can specify a lot of kernel parameters, such as quit silent mode, init=/bin/ BASH specifies that the first process is bash, not/sbin/init, and so on. Then you just need to enter boot to boot the operating system.

Grub configuration file configuration.

The grub configuration file is in/boot/grub/grub.conf or/etc/grub.conf, followed by a soft link in front.

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M00/7E/17/wKiom1b3S22jTBLLAAA6H8q_7Ak377.png "alt=" wkiom1b3s22jtbllaaa6h8q_ 7ak377.png "/>

Information Description:

#boot: Indicates which hard disk is on. (can be specified under Title, this position is specified by the global)

Default=0: Indicates that the first operating system is entered by default

Timeout=5:5 Seconds is not selected, then go directly into

SPLASHIMGE: Specify the location where the boot image is located

Hiddenmenu: Hidden menu (not here)

Title custom Menu Name

Root

Kernel

Initrd:

These three have been said before.

Since grub can support multiple system menus, it is only necessary to add the contents of the title below if multiple systems are installed.

You can also add password protection, specified in the title is the global, in the title of the word is limited to this menu, the method is: password--md5 password (can be generated with Grub-md5-crypt, and then copied into).

650) this.width=650; "title=" capture. PNG "src=" Http://s4.51cto.com/wyfs02/M01/7E/13/wKioL1b3UJ7SWx4XAAAVgDF61zw130.png "alt=" Wkiol1b3uj7swx4xaaavgdf61zw130.png "/>

650) this.width=650; "title=" capture. PNG "src=" Http://s5.51cto.com/wyfs02/M01/7E/17/wKiom1b3UYrBxRbWAABQd4c1hK8011.png "alt=" Wkiom1b3uyrbxrbwaabqd4c1hk8011.png "/>

Here I add a password in the global settings, and in the second inside add a local password, the following to see the effect.

650) this.width=650; "title=" capture. PNG "src=" Http://s5.51cto.com/wyfs02/M02/7E/13/wKioL1b3Uq_j3jRqAAAd6At8hv8443.png "alt=" wkiol1b3uq_ J3jrqaaad6at8hv8443.png "/>

Read the following message and say press the P key to unlock the entry menu

650) this.width=650; "title=" capture. PNG "src=" Http://s4.51cto.com/wyfs02/M00/7E/13/wKioL1b3UxDyMNNGAAAet3SzSxI081.png "alt=" Wkiol1b3uxdymnngaaaet3szsxi081.png "/>

After you press p, the password appears below, see the

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M01/7E/17/wKiom1b3Ur-RsHpeAAAfLX-ZmrM256.png "alt=" Wkiom1b3ur-rshpeaaaflx-zmrm256.png "/>

The familiar scene is back again, but this is the global menu password, select the second carriage return below to see.

650) this.width=650; "title=" capture. PNG "src=" Http://s5.51cto.com/wyfs02/M01/7E/13/wKioL1b3U7iC5iKYAAALnWebEHU140.png "alt=" Wkiol1b3u7ic5ikyaaalnwebehu140.png "/>

A password is required, which is the function of setting the password locally.

Installation of Grub:

What do you do when your grub selves here is hung up, and reload the system? Oh... In fact grub has commands to install. Here are two ways to see grub installed.

Method One: Use the Grub-install command.

Usage: grub-install--root-directory=grub root position/dev/sd[a-z] (specify on which disk), because Grub-install will go to the/boot directory, so we first destroy and reload.

DD If=/dev/zero OF=/DEV/SDA count=1 bs=200 (remember not to be larger than 446K)

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M00/7E/14/wKioL1b3VzjRf87OAAAwKDPODHQ928.png "alt=" Wkiol1b3vzjrf87oaaawkdpodhq928.png "/>

Method Two: Direct access to Grub

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M02/7E/18/wKiom1b3V9rR2OXZAABQ54Khdyo635.png "alt=" Wkiom1b3v9rr2oxzaabq54khdyo635.png "/>

Add a new hard drive, which provides a separate bash system to run.

650) this.width=650; "title=" capture. PNG "src=" Http://s2.51cto.com/wyfs02/M00/7E/14/wKioL1b3WzihmmGUAAAu7t14h1M446.png "alt=" Wkiol1b3wzihmmguaaau7t14h1m446.png "/>

First partition, simple three basic partitions on it,/boot/swap, and then format to file system. Because grub will find/boot this directory, all can build a/mnt/boot directory to mount/DEV/SDB1 this when the boot partition, and in order not to overwrite/DEV/SDB1, you can build a/mnt/sys to mount/dev/sdb3 this when/ Partitions (these basic steps are not demonstrated).

Now install grub on the partition that will be boot/DEV/SDB1

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M02/7E/14/wKioL1b3Xlyi_RoFAAAmkmMg1hE270.png "alt=" Wkiol1b3xlyi_ Rofaaamkmmg1he270.png "/>

Then create the base directory on the FHS/DEV/SDB3 this partition that will do the filesystem root

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M01/7E/14/wKioL1b3X1uToTHrAAAPvTYa08Q739.png "alt=" Wkiol1b3x1utothraaapvtya08q739.png "/>

You can then copy the/bin/bash to/mnt/sys/bin and copy the library files that they need into the appropriate library file directory, and use Ldd/bin/bash to view the required library files.

650) this.width=650; "title=" capture. PNG "src=" Http://s5.51cto.com/wyfs02/M00/7E/14/wKioL1b3YFSCcChiAAA5jLdpKe4784.png "alt=" Wkiol1b3yfsccchiaaa5jldpke4784.png "/>

and chroot into/mnt/sys.

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M02/7E/18/wKiom1b3YCCCreWMAAAbjIZOwKw638.png "alt=" Wkiom1b3ycccrewmaaabjizowkw638.png "/>

Because it's just a bash, you can only use inline commands.

Re-edit the grub.conf, I also by copying, so convenient, of course you can also build your own, with parameters, and then the system's kernel and randisk (in/boot) copied to/mnt/boot

[[email protected] boot]# lsgrub initramfs.img vmlinuz[[email protected] boot]# ls grub/grub.conf grub/grub.conf

Then edit grub.conf

650) this.width=650; "title=" capture. PNG "src=" Http://s4.51cto.com/wyfs02/M01/7E/19/wKiom1b3YpaCo1n3AAAhDPUH6yk556.png "alt=" Wkiom1b3ypaco1n3aaahdpuh6yk556.png "/>

Now build a virtual machine that uses this hard drive.

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M02/7E/15/wKioL1b3Y6rRvYNIAABHHELZuuw444.png "alt=" Wkiol1b3y6rrvyniaabhhelzuuw444.png "/>

Is this step. Then choose your own hard drive. Then the boot is ready to enter.

650) this.width=650; "title=" capture. PNG "src=" Http://s2.51cto.com/wyfs02/M00/7E/17/wKioL1b3bWWgJtNfAAAk0IJH0Xo885.png "alt=" Wkiol1b3bwwgjtnfaaak0ijh0xo885.png "/>

The above is in the case of access to the system, if grub is broken but shut down again? Then we need to get into the emergency rescue mode.

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M01/7E/17/wKioL1b3blfRzZtNAAAWX480A1c701.png "alt=" Wkiol1b3blfrzztnaaawx480a1c701.png "/>

Reboot below to see

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M00/7E/1B/wKiom1b3bijRyoWKAAAaCdqInC0845.png "alt=" Wkiom1b3bijryowkaaaacdqinc0845.png "/>

It's time to mount the system CD to open the emergency rescue mode.

650) this.width=650; "title=" capture. PNG "src=" Http://s4.51cto.com/wyfs02/M00/7E/17/wKioL1b3bzrA_-NLAAGAkDOH23E631.png "alt=" wkiol1b3bzra_- Nlaagakdoh23e631.png "/>

Select rescue installed system or press ESC directly into the command line mode to enter the Linux rescue after entering into the emergency rescue mode.

650) this.width=650; "title=" capture. PNG "src=" Http://s4.51cto.com/wyfs02/M01/7E/1B/wKiom1b3bvug5H8aAAAOemOm0gM502.png "alt=" Wkiom1b3bvug5h8aaaaoemom0gm502.png "/>

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M00/7E/1B/wKiom1b3b1OQVjSdAABcFBy9id0943.png "alt=" Wkiom1b3b1oqvjsdaabcfby9id0943.png "/>

Will come out of this interface, and then always choose on the line until

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M02/7E/17/wKioL1b3cEOiB0qKAABksiTbJtI068.png "alt=" Wkiol1b3ceoib0qkaabksitbjti068.png "/>

The message says my system has been mounted on the/mnt/sysimage, and I'm in.

650) this.width=650; "title=" capture. PNG "src=" Http://s1.51cto.com/wyfs02/M02/7E/17/wKioL1b3cL3Tf6jHAABIY8hUaC8613.png "alt=" Wkiol1b3cl3tf6jhaabiy8huac8613.png "/> OK, now you can install grub in the shell, chroot into/mnt/sysimage, then install GRUB.

650) this.width=650; "title=" capture. PNG "src=" Http://s5.51cto.com/wyfs02/M01/7E/1B/wKiom1b3cVzju4N3AAAfet8GjEA609.png "alt=" Wkiom1b3cvzju4n3aaafet8gjea609.png "/>

The installation is successful and the system can now be restarted.

650) this.width=650; "title=" capture. PNG "src=" Http://s3.51cto.com/wyfs02/M02/7E/17/wKioL1b3cq-CtVSZAAAf3aTUeuo587.png "alt=" Wkiol1b3cq-ctvszaaaf3atueuo587.png "/>

Done!!

The grub thing.

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.