Thorough GRUB

xiaoxiao2021-03-05  27

Tr: Thoroughly get GRUB (unfinished)

Troustleshooters.com and

T.C Linux Library Present

Grub from the ground up

Copyright (c) 2005 By Steve Litt, All Rights Reserved. Material Provided as-is, Use at your OWN RISK.

Reprinted and translated from the Troubleshooters website, the translation follows the GNU FDL, only the part of the body can be freely modified, and the part other than the text must be published. The translator apologized, but said not to be responsible for the consequences of misunderstanding.

Thorough GRUB

table of Contents

* Disclaimer

* to sum up

* Make simple GRUB boot floppy disk

* You must know what you must know

* Use GRUB to find files

* Make full-featured GRUB boot floppy disk

* Install GRUB from floppy disk

* Use full installed GRUB

Disclaimer

This document contains a series of exercises accessing, and in some cases overwriting, your boot loader. There's a significant possibility of overwriting your existing boot loader, which can lead to lost time and even lost data. There may be other risks.

You use this document at your own risk. I am not responsible for any damage or injury caused by your use of this document, or caused by errors and / or omissions in this document. If that's not acceptable to you, you may not use this . by using this document you are accepting this discuClaim.

Disclaimer

This document consists of a series of experiments, reads or even overrides your bootr (Boot loader). Rewriting your existing bootstrap probabilities is very large, which may result in time-consuming repairs or even data loss. There are other dangers.

With this document, you have to take yourself. I am not responsible for using this document, misreading documents or ignoring any loss of some documents. If you are unacceptable, don't use this document. If this document is used, it is considered that this disclaimer has accepted.

[Text start]

to sum up

GRUB is an ultra-first-class boot program, but there are few documents. Many places are much better than LILO. For example, reconstructing a GRUB boot program using Knoppix, which is much easier than rebuilding a LILO boot. However, unless you are familiar with GRUB, you will feel the opposite. GRUB often sends a prompt

Code:

GRUB>

But don't tell you what to do. You may have heard that as long as three orders can be successfully restarted, but which three is it? The GRUB document is that, unless you already know what it means, you can't understand.

This article is to be solved, it is this embarrassing situation. This article will teach you enough professional GRUB skills so that you can create a GRUB boot floppy disk on a machine installed in GRUB (as long as you install it, you don't have to use the boot program), using this floppy-driven simple boot program Start a Linux machine and use this floppy disk to truly install the grub as a boot program.

This article does not discuss using GRUB to boot (or configure multi-boot) Windows, Mach, BSD, or other non-Linux operating system. Maybe I will write another document. However, when you are more familiar with the principles and practices of GRUB, study existing documents, you will learn how to use GRUB to boot the non-Linux operating system. Making a simple GRUB boot floppy disk

Most of this article are about what should be done in the "GRUB>" prompt, so you have to enter such an environment. The easiest way is to use a simple GRUB boot floppy disk. It can be created on any machine installed in GRUB, regardless of whether this machine is booted with GRUB. The following bash command demonstrates how to make a simple GRUB boot floppy disk

Code:

[root @ mydesk grub] # cd / boot / grub [root @ mydesk grub] # cat stage1 stage2> / dev / fd0u1440 [root @ mydesk grub] #

To remind a sentence. In 1990, if you bought 50 soft disks, more than 45 of them were very good. Now, if you are in the floppy disk you bought, it is good, you can use it again, it is very good. In 1990, the price of the hard drive is close to $ 100, and it can work for a long time. Today's floppy drive is only 1/10 price, but the working time is only 1/10. Therefore, create a few GRUB boot floppy disk, if a read error occurs during the startup process, you can change it.

Don't worry, although you want to enter the "GRUB>" prompt environment, just insert your finished floppy disk into the floppy drive, restart your computer, adjust the BIOS settings to start priority from the floppy drive, and then restart to continue. But first, you must know something ...

What you must know must know

In order to start the computer with GRUB, you have to know the following:

1. Containing the partition of the kernel

2. Directory path and file name in the partition, kernel

3. Partition containing / sbin / init

In addition, you may need to know the partitions, paths, and file names of the initrd file, but usually not necessary in GRUB.

Quote:

Note that I encountered the case where the kernel does not have the initrd statement, it can only start in the case where INITRD is present. However, wait until the startup is completed, I can remove the initrd statement, re-run the GRUB installation command, when starting, INITRD statement is required. If you encounter the case of kernel PANIC, you don't know why, then add an initrd statement.

Now let's take an example. Suppose a system mounts / dev / hda1 as / boot, mount / dev / hda9 to /. In the / boot directory, the file name of the kernel is VMLinuz-i686-Up-4GB. Now we can answer the four questions above:

1. The partition containing the kernel is / dev / hda1, if using GRUB, (HD0, 0)

2. Directory path and file name where the kernel is located is / Vmlinuz-i686-Up-4GB (remember, because / dev / hda1 is mounted directly to / boot, the kernel is in its root directory)

3. Partition containing / sbin / init is / dev / hda9

In this case, to boot the system, you should enter such a command.

Code:

GRUB> root (HD0, 0) GRUB> KERNEL / VMLINUZ-I686-UP-4GB root = / dev / hda9 grub> boot

Such orders are usually sufficient for booting a Linux host. A separate root statement gives a partition containing the kernel.

The kernel statement describes the path and file names of the kernel file in the partition. parameter

Root = gives a partition containing / sbin / init, which is of course the root partition of the system.

Be careful here that there is two root keywords. The individual is the root partition that GRUB, which contains the kernel. As the kernel statement parameter, it is the root partition that the system after the startup system is included, including / sbin / init.

It is also necessary to use the partition of GRUB, sometimes use Linux partition representation. In addition to the root = parameter in the kernel statement, the partition representation of GRUB should be used ((HD0, 0)). In root = parameters, use Linux partition representation. In the representation of Linux, the driver represents a main drive of the first IDE port, b represents the slave driver of the first IDE port, c represents the main drive of the second IDE port, D represents the second IDE port from Drive, other IDE ports are pushed. In the representation of Linux, the partition number in the drive starts from 1.

In the partition representation of GRUB, the first block readable hard drive is (HD0), the second block readable hard drive (even if it is connected to the third, fourth or higher IDE port) (HD1), so on. In the partition representation of GRUB, the partition number starts from 0. Therefore, / DEV / HDA1 and (HD0, 0) are the same partition.

Sometimes you need to specify initrd, although this is very little. In this case, as long as the boot statement is added, add such a sentence as long as the Kernel statement

Code:

INITRD /INITRD-I686-UP-4GB.IMG

If you want to use the initrd statement, then the initrd file you use must match the kernel file you use.

Another way from GRUB starts with the GRUB's root statement to combine with the kernel statement:

Code:

Grub> kernel (HD0, 0) / VMLINUZ-I686-UP-4GB root = / dev / hda9grub> boot

If this is done, the root statement must also be combined in the initrd statement.

Guide the release of foreign language

If your native language is American English, but using GRUB to launch a Knoppix machine that lost the bootstrap, the previously mentioned commands can start Knoppix, but various message prompts even the keyboard layout will be German. If you want to get an American English environment, you can add parameters lang = us behind the Kernel statement, just like this:

Code:

GRUB> KERNEL (HD0, 0) / VMLINUZ-I686-UP-4GB root = / dev / hda9 lang = usgrub> boot or grub> root (HD0, 0) GRUB> KERNEL / VMLINUZ-I686-UP-4GB root = / DEV / HDA9 LANG = USGRUB> Boot

Setting of single partitions

In the previous example, there is a specialized / boot partition in the system. Bios, modern computers, can boot the system after 1024 cylinders, so many people are no longer partitioned separately for / boot. That is, the root partition is / dev / hda1, and / Boot is only a directory in the root partition. At this time you need such a command:

Code:

GRUB> root (HD0, 0) GRUB> KERNEL / VMLINUZ-I686-UP-4GB root = / dev / hda1grub> boot is only different, where GRUB's root is the same as the system's root.

Search using GRUB

Usually you know the partitions of the kernel, as well as the path and file name of the kernel, and partitions that should be mounted after startup. This is very simple in this case.

However, sometimes things are not so simple. For example, you accidentally installed the configured erroneous LILO, or reinstalling WIN $, and covers the boot manager in the MBR inadvertently. At this time, you need the help of GRUB, but for the partition of the kernel, the status of the root partition and the name of the kernel are not known. Fortunately, GRUB can help you.

The first step is to find partitions that contain kernels and contain / sbin / init partitions. Enter such a command at the GRUB> prompt

Code:

Find / sbin / init

On a host installing multiple different Linux systems, the machine will respond to the following results:

Quote:

GRUB> Find / Sbin / Init (HD0, 11) (HD1, 11) GRUB>

In this example, you will find that there are three partitions containing / sbin / init

Quote:

GRUB partition number Linux partition number (HD0, 8) / DEV / HDA9 (HD0, 11) / DEV / HDA12 (HD1, 11) / DEV / HDE12 (can be inferred here, HD1 is mapped to HDE, because this machine There are two hard drives, which have received HDA and HDC respectively.

Next, look for all partitions that contain the kernel. First, we assume that at least one file name is VMLinuz

Code:

GRUB> Find / VMLinuz (HD0, 11) (HD1, 11) GRUB>

Then, search for VMLinuz contained in the / boot directory

Code:

Grub> Find / Boot / VMLinuz (HD0, 11) (HD1, 11) GRUB>

This time, two of the three results were found, so it can be inferred that (HD0, 0) is a system / boot partition.

GRUB's Find command function is limited. It can only find ordinary files and cannot find the directory. It is usually necessary to specify the entire directory path, although in the above experiment, two / boot / vmlinuz were found when searching / VMLinuz. Don't rely on this behavior.

Another technique for finding information in GRUB is a feature that uses file name complements. If you know that the kernel is located (HD0, 0), and the kernel file name starts with VML. Enter such a command, but do not execute, but press the TAB button after entering:

Code:

NULL (HD0, 0) / VML

GRUB will make up, as if you have the shell command line prompt.

Code:

GRUB> NULL (HD0, 0) / VMLinuz Possible Files Are: VMLinuz VMLinuz-2.6.3-7MDK VMLINUZ-2.6.3-7MDK-I686-UP-4GBVMLINUZ-I686-UP-4GBGRUB>

NULL is not a keyword in the experiment above. It is specifically looking for a non-key word, you can also use the words of other non-critical words of WHAT or BOGUS. When you see the list in the prompt, you can enter more prompts, then press Tab again, just like the shell command line prompt. Doing so as much as possible reduces input errors.

Sometimes GRUB can't find all the information you need. If you need more information, it is best to use Knoppix. See Troubleshooters.com's Knoppix Knowhow webpage.

Making a complete GRUB boot floppy disk

At the beginning of this document, you created a simple GRUB boot floppy disk that does not include the file system. For start-up systems, it is already enough, but it is not used to install GRUB. To install the GRUB, you need a GRUB boot floppy disk containing the file system. It can be made in any Linux system installed in GRUB. Below is the detailed steps

Code:

[root @ mydesk root] # mkfs -t ext2 -c / dev / fd0u1440 [root @ mydesk root] # umount / dev / fd0 [root @ mydesk root] # umount / dev / fd0u1440 [root @ mydesk root] # MKDIR / MNT / TEST [root @ mydesk root] # mount / dev / fd0u1440 / mnt / test [root @ mydesk root] # mkdir -p / mnt / test / boot / grub [root @ mydesk root] # CP / boot / grub / STAGE1 / MNT / TEST / BOOT / GRUB [root @ mydesk root] # cp / boot / boot / gate2 / mnt / test / boot / grub [root @ mydesk root] # chmod AW / MNT / TEST / BOOT / GRUB / Stage2umount / dev / fd0u1440 [root @ mydesk root] # Grubgrub> root (fd0) GRUB> Setup (fd0) grub> quit [root @ mydesk root] #

This makes a startable GRUB floppy disk. It is best to join a menu.lst file on the floppy disk as an example. The menu.lst file adds a menu for GRUB and is important when you install GRUB to other machines. On the machine you need to start, you can modify this menu.lst file, create the menu when you start, and then install the GRUB to the system. Note that before the steps above are executed, do not copy the menu.lst scrutation to the floppy disk. Here's how to add an example file. Note Mount Mount and Umount must be run again.

Code:

[root @ mydesk root] # mount / dev / fd0u1440 / mnt / test [root @ mydesk root] # cp -p /usr/share/doc/grub-doc-0.93/Menu.lst / MNT / TEST / BOOT / GRUB / stage1 stage2 [root @ mydesk root] # cp -p /usr/share/doc/grub-doc-0.93/Menu.lst / mnt/test/boot/grub/Menu.lst.example [ROOT@mydesk root] # Umount / dev / fd0u1440 [root @ mydesk root] #

Install GRUB through a floppy disk

Don't do this unless you have already done all the experiments. In addition, it is important to understand the operation of the GRUB command line.

WARNING The next experiment teaches you how to create a GRUB boot floppy disk on a computer installed in GRUB, and then use this floppy to start and configure grub on another computer. This process deletes the original boot manager on the second computer. If you are going well, GRUB will replace the original boot manager, but no one can guarantee everything smooth. In fact, this document is only for Linux, if your machine is a Windows or BSD system, this article can't help you recover. Therefore, the second computer must be an experiment, even if there is no relationship of the data and operating system, you have created a floppy disk, including stage1, stage2 And an example menu file called Menu.lst.example. Now, it is when using this floppy disk on another machine. As mentioned in the warning, this must be an experimental system, even if the boot manager is overwritten, there is no relationship.

If GRUB has been installed on that machine, we can temporarily move the relevant files to other places. Run such a command

Code:

MV / Boot / Grub / Boot / Orggrubmv / Sbin / Grub / Sbin / Orgrubmv / Sbin / Grub-Install / Sbin / Orgrub-Install

That is to say, the / boot / grub is renamed and all executables related to GRUB are renamed. This way, you can simulate a machine that never installed GRUB. After you want to use them in the future, you can use several MV commands to change. Unfortunately, MBR to be changed to modify is not so simple.

Insert the GRUB boot floppy disk in the experimental system, turn off the computer correctly, start it again. In the BIOS self-test, set the computer's first boot drive to FLOPPY

Basically the process is like this

1. Start the floppy disk start from the GRUB

2. Copy the files on the floppy drive to the / boot / grub directory on the hard disk

3. Configure /boot/grub/menu.lst files on your computer.

4. Restart, start the floppy disk from the GRUB, install GRUB

Start the floppy disk start from the GRUB

Code:

GRUB> root (HD0, 0) GRUB> KERNEL / VMLINUZ-I686-UP-4GB root = / dev / hda9grub> boot

As mentioned earlier, if you want to launch a foreign language, you should attach a suitable lang = core parameter to get the working environment of the native language. If the execution is correct, your experimental system starts.

Copy the file from the floppy drive to the hard disk / boot / grub directory

First, we determine that there is no / boot / grub on the machine. If there is, change it. As an experiment, it should not cover the original things in the system.

Then run such a command

Code:

MKDIR / MNT / TESTMOUNT / DEV / FD0U1440 / MNT / TESTCP -RP / MNT / TEST / BOOT / GRUB / BOOT

Configuring /boot/grub/menu.lst files for this computer

If you don't know about GRUB before reading this document, then the menu.lst sample file comes with you is not used by you. But as long as you learn a little, you will understand a lot! Now you have known how to start a machine in the GRUB> prompt; you also know what is different from the root partition that the GRUB root partition is started after the LINUX is started; you also know how to configure the GRUB's kernel command.

The menu.lst file is actually the command you are using in the GRUB> prompt, but does not include the boot command. The sample file includes commands that initiate a variety of operating systems, even MACH and Windows. The file also contains commands that install GRUB to the system, and change the commands of the menu color. These are irrelevant. What you have to do is deleted with Linux content, just configure Linux related commands, make them match your experimental system: the partition, Linux's partition area, kernel file name ... Is a configuration file, the saved file name is Menu.lst reference:

# # Sample Boot Menu Configuration File # # boot Automatically After 30 Secs. Timeout 30 # by Default, Boot The First Entry. Default 0 # Fallback to The second entry. # Fallback 1 # be sure to comment this out !!!!! !!!!!!!!!!

There are some places that need attention:

* Be sure to comment out this command, because we only have the only choice, that is, No. 0 selection

* DEFAULT 0 command means which option should be made when the user has not responded?

* If you don't start a foreign language release, you don't need a lang = parameter.

* Command root (HD0, 0) should be adjusted, pointing to partitions that contain kernels

* Parameters root = / dev / hda1 should be adjusted, pointing to the partition of the root partition after startup. It is named in Linux, not a grub's way

* The kernel file name in the kernel command should use the path relative to the GRUB root partition. In this example, Linux's / boot and root partition are the same partition, so the kernel file name is /boot/vmlinuz-2.6.7; if Linux saves a partition separately, assume that this partition is / dev / hda1 (Usually this), then the kernel command should be used by the kernel file name /VMLINUZ-2.6.7 instead of example, because the file is in the root folder of the partition, only after the startup, this partition is mounted It is meaningful to mention / boot.

* GRUB's default menu file is /boot/grub/menu.lst. Other files can also be used, but ... (<"" What is the meaning?> "

* These orders are not new to you. In the previous exercise, you have done all the commands in the GRUB> prompt.

After /boot/grub/menu.lst file, you can install GRUB from the floppy disk

Restart, still start using the floppy disk, install GRUB

To ensure that the floppy is still in the experimental machine, restart the machine. After the machine starts from the floppy drive, you will bring you to the GRUB> prompt. If you are doing the front, you will be very simple.

Code:

GRUB> root (HD0, 0) GRUB> Setup (HD0) GRUB> Reboot

The machine will restart again. You should take the floppy, set the BIOS to start from the hard drive, you will see the GRUB menu that only contains a project. Just like this: [Image]

Press Enter to launch the kernel listed in the Menu.lst file. Note where you need to pay attention:

* Do not take out the floppy disk when the floppy drive is on

* If you have not come and remove the floppy disk, the system will start from the floppy disk again. At this time, just after the startup, remove the floppy disk and restart it.

to sum up

The whole is like this. You created a bootable floppy disk that contains the Stage1, Stage2, and Sample menu files, install the GRUB boot manager to another machine using this floppy disk. That's how to replace a machine's bad guidance manager to a GRUB method.

However, this installation is incomplete. First, no GRUB executable

# Grub

# Grub-floppy

# Grub-install

# Grub-MD5-CRYPT

# Grub-reboot grub-terminfo

Second, there are no files in many / boot / grubs.

# device.map

# e2fs_stage1_5

# JFS_STAGE1_5

# minix_stage1_5

# REISERFS_STAGE1_5

# xfs_stage1_5

Finally, there are still those documents in the / usr / share / doc / grub directory.

When your machine is stable and normal to start using GRUB, you should use a package management tool or source code to reinstall the complete grub. Be careful to back up your existing /boot/grub/Menu.lst

Installed complete grub

Always start with floppy, enter the GRUB> prompt or to install the boot manager to the MBR is very bored. If a complete GRUB is installed, you don't have to do this again. You can use Grub-Install to install a newly configured boot manager, do not have to make the launch floppy disk. In addition, you can use GRUB to preview the effect of MENU.LST.

For example, after the GRUB is installed (or after retrieving the original GRUB), edit the menu.lst, insert a new startup item. I intend to add a 2.4 core as the second choice, start it automatically when the first choice cannot start. Modified Menu.lst is like this

Quote:

# # Sample boot menu configuration file # # Boot automatically after 30 secs. Timeout 30 # By default, boot the first entry. Default 0 # Fallback to the second entry. Fallback 1 # For booting GNU / Linux title 26 root (hd0,0 ) kernel / boot/vmlinuz-2.6.7 root = / dev / hda1 lang = us # for booting gnu / linux Title 24 root (HD0, 0) kernel /boot/vmlinuz-2.4.27 root = / dev / hda1 lang = US

Such files provide two options, one is 2.6 kernel, named "26", the other is 2.4 kernel, name is "24". When you start the machine next time, you will see two options "26" and "24". Their behavior is this: "26" is launched by default, but if "26" can't start, "24" will be launched.

After the file is saved, the GRUB-INSTALL / DEV / HDA performs this command to install the GRUB to the MBR of the hard disk. Quote:

Note that you can also run GRUB> Root (HD0, 0) GRUB> Setup (HD0) to achieve this command GRUB-INSTALL / DEV / HDA. Here, we assume that the kernel is located (HD0, 0) is / dev / hda1, and we have to install GRUB on the MBR of the first hard disk, that is, / dev / hda

If you want to preview menu effects, you can use this command.

Code:

Grub --config-file /(HD0, 0/ )/boot/grub/menu.lst

Note To use a backslash to escape, otherwise shell will understand them as a special meaning character. When you run this command, you will see the menu, just like this.

[image]

The GRUB running in the command line will not start the system. (If the configuration file is correct, then GRUB will quit quietly)

[End]

Return

Troustleshooters.com

Return

Linux Library

postscript:

According to the rules, the disclaimer should not be translated, but this is a GRUB document.

In addition, the original text prohibits the creation of derivatives, prohibits translation or reprint, so please understand the brothers of English to the tough and stubborn website.

转载请注明原文地址:https://www.9cbs.com/read-33340.html

New Post(0)