Grub installation, configuration, and usage

Source: Internet
Author: User
(1) install grub during Linux installation.
When installing RedHat Linux, you will be prompted to install the boot program. If grub is selected as the boot program, it is recommended to install grub to the boot sector MBR of the hard disk. grub can also guide other operating systems, such as FreeBSD, NetBSD, OpenBSD, GNU Hurd and DOS, and Windows 95, 98, NT, 2000, and XP.
(2) grub Configuration
Once grub is selected as the boot program, let's take a look at its configuration.
/Boot/GRUB/grub. conf is used to generate a boot menu for grub and set some options. below is my grub. conf:
#=========== Example start ================
# Grub. conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# Notice: You have a/boot partition. This means that
# All kernel and initrd paths are relative to/boot/, eg.
# Root (hd0, 6)
# Kernel/vmlinuz-version Ro root =/dev/hda10
# Initrd-version.img/initrd
# Boot =/dev/hda
Default = 0
Timeout = 10
Splashimage = (hd0, 6)/GRUB/splash.xpm.gz
# --> RedHat Linux 8.0 <--
Title Red Hat Linux (2.4.18-14)
Root (hd0, 6)
Kernel/vmlinuz-2.4.18-14 Ro root = label =/
Initrd/initrd-2.4.18-14.img
# --> Microsoft Windows XP <--
Title Microsoft Windows XP
Rootnoverify (hd0, 0)
Chainloader + 1
#============ End of the example ==============
Description of configuration options:
The comment line starts.
I have two operating systems, Red Hat Linux and Microsoft Windows XP.
The timeout mark specifies the default wait time. I set this value to 10 seconds. If you have not made any choice for more than 10 seconds, the default Operating System will be automatically selected (RedHat Linux 8.0 is the default here)
The default Operating System is controlled by the default option. The number after the default option indicates the default option. Here 0 indicates the first option and 1 indicates the second option. so if you want to modify the default Operating System, modify the default number.
Title indicates the name of the operating system. Grub does not support Chinese characters (sorry ).
Splashimage specifies the background image of the grub interface. If you are interested, you can modify the grub background!
Root (hd0, 6) identifies the boot kernel from the first hard disk and 7th partitions. Note that the root partition here is different from the root partition in Linux. This root partition is also different from the root partition! The hard disk Identification Method of grub is a little different from that of Linux. in Linux, the first primary partition is hda1, the second primary partition is hda1, and the first logical partition is hda5, which is identified by (hdx, y) In grub, for example, the first primary partition is (hd0, 0) and the first logical partition is (hd0, 1. so here root is the ID of the partition where your/boot is located.
Knowing where the kernel is and specifying which file is the kernel file is the work of the kernel.
Kernel/vmlinuz-2.2.18-14 Ro root = label =/. Description/boot/vmlinuz-2.2.18-14 is the kernel to be loaded. The following are the parameters passed to the kernel. RO means readonly. Note that the path before the kernel here is "/", because my boot is divided into one partition separately. If you do not partition the boot separately, the path before the kernel is "/Boot ".
Initrd is used for the initial Linux image, and the corresponding parameters are set.
Let's take a look at the definition section of windows.
Here, I added an item to guide Windows XP. To complete this operation, grub uses the chainloader ). The chain loader loads WINXP's own Boot Loader from the boot records of the partition (hd0, 0) and then directs it. This is why this technology is called chain loading-It creates a chain from the boot loader to another. This chain mount technology can be used to guide any version of DoS or windows. If you have Win98, winme, Win2k, and WINXP installed on your computer, chainloader will direct the boot permission to win's ntloader.
(3) creation of the grub boot disk
To create a boot disk, perform some simple steps. First, create an ext2 File System on the new floppy disk. Then, install it, copy some grub files to the file system, and finally run the "Grub" program, which will be responsible for setting the Boot Sector of the floppy disk.
Insert an empty disk into the 1.44 MB drive. Enter:
# Mke2fs/dev/fd0
After creating an ext2 file system, you must install the file system:
# Mount/dev/fd0/mnt/floppy
Now, you need to create some directories and copy some key files (these files have been installed before grub was installed) to the floppy disk:
# Mkdir/mnt/floppy/boot
# Mkdir/mnt/floppy/boot/GRUB
# Cp/boot/GRUB/stage1/mnt/floppy/boot/GRUB
# Cp/boot/GRUB/stage2/mnt/floppy/boot/GRUB
In another step, you can obtain the available boot disk.
In Linux bash, running "Grub" from the root user is very interesting and worth noting because it is actually a semi-functional version of the grub boot loader. Although Linux is started and running, you can still run grub and execute some tasks, in addition, the interface is exactly the same as that seen when you use the grub boot disk or install grub to the hard disk MBR (that is, the grub console.
At the grub> prompt, enter:
Grub> root (fd0)
Grub> setup (fd0)
Grub> quit
Now, the boot disk is complete.
(4). Restore grub damaged by windows.
If you use grub to guide Linux and Windows, the grub in MBR will be damaged after Windows is re-installed due to a problem, and grub needs to be restored.
1. Place the first installation disc of Linux to the optical drive, restart the machine, and use the optical drive to guide the system in Bois.
2. After the installation interface is installed, press the [F4] key, that is, the Linux rescue mode.
3. A series of keyboards and a few simple preparations, and then [continue... This process is simple.
4. Then the prompt will appear:
Sh #
5. We can operate grub. Enter GRUB:
Sh # grub
The following prompt appears:
Grub>
After such a character, we can enter:
Grub> root (hdx, Y)
Grub> setup (hd0)
If it succeeds, there will be a successful ......
X here, if it is a disk, It is 0. If the root partition of the Linux installation is on the second hard disk, X is 1; y, is the root partition where the Linux system is installed. Setup (hd0) is to write grub to the hard disk MBR.
(5). Use ntloader to guide Linux.
If you do not choose to install grub when installing Linux, you don't have to worry about it. Now let's take a look at how to install grub after installing Linux and use Windows ntloader to guide Linux.
1. Install grub
My grub is the grub installation package with redhat8.0: grub-0.92-7.rpm
Installation: rpm-IVH grub-0.92-7.rpm
The same is true for other installation methods. You only need to install grub. Grub is used by rh8 by default. Steps 1 and 2 can be saved.
2. Create a grub Environment
CP/usr/share/GRUB/i386-pc/*/boot/GRUB
3. Generate the grub configuration file/boot/GRUB/menu. conf.
Generate a configuration file according to grub. conf mentioned above.
Note that my Linux is in/dev/hda4, so the partition locations of menu. conf are (hd0, 3 ),
You may be different. You can't just draw a picture! The partition location in the Next Step install should also be consistent with your system.
3. Install grub to LINUX partition boot
Install stage1 of grub to the Boot Sector (hd0, 3) of/dev/hda4. The process is as follows:
/Sbin/GRUB (run grub)
Grub> install (hd0, 3)/boot/GRUB/stage1 D (hd0, 3) (hd0, 3)/boot/GRUB/stage2 P (hd0, 3) /boot/GRUB/menu. conf
(Note: The above "Grub>" is the grub prompt, and the post content is written in a line .)
4. Obtain the boot information of grub.
The process is as follows:
Dd If =/dev/hda4 of =/grub. lnx BS = 512 COUNT = 1
In this way, you can get the grub boot information by loading it with NT loader.
5. Get the grub. lnx obtained above to the C-drive root directory of windows.
You can set grub first. lnx gets a floppy disk, starts Windows, and copies it to C:; in this case, you can also directly copy it to C: in Linux. my c drive (device/dev/hda1) is FAT32, which can be obtained directly from Linux. as follows:
Mount-T vfat/dev/hda1/mnt/C
CP/grub. lnx/mnt/C
Umount/mnt/C
6. Modify the boot. ini of NT loader.
Add a line in it: C: grub. lnx = "RedHat Linux-Grub"
After adding boot. ini, the content is as follows:
[Boot loader]
Timeout = 15
Default = C: oot. lnx
[Operating systems]
Multi (0) disk (0) RDISK (0) Partition (1) Windows = "Microsoft Windows XP Professional"/fastdetect
[VGA mode] "/basevideo/SOS
C: grub. lnx = "RedHat Linux-Grub"
OK. you can use nt loader to load Linux. In fact, the above process is basically the same as loading lilo with NT loader. the basic idea is to use nt loader to load the boot zone (grub) of LILO or grub. lnx). The key is to obtain the boot zone of LILO or grub.
(6) Use grub interaction Functions
Grub has powerful interaction functions. Learning it will benefit you a lot!
1. What should I do if grub does not display a menu?
After the instance is started, the grub interface is displayed but there is no menu. There is only one grub> prompt. How can this problem be started? Take a look at the following:
Grub> CAT (hd0, 6)/boot/GRUB/grub. conf (to see the parameters)
Grub> root (hd0, 6)
Grub> kernel (hd0, 6)/vmlinuz-2.4.18-14 Ro root = label =/
Grub> initrd (hd0, 6)/initrd-2.4.18-14.img
Grub> boot
OK! Start it! The preceding numbers must be changed based on your actual situation.
The above method can also be used to test the newly compiled kernel.
2. Enter the single-user mode.
Sometimes you accidentally forget the root user password. You can only enter the single-user mode to reset the root password. The method is as follows:
Start grub, press C to enter the command line mode, and then follow the above method, but add the single parameter to the end of step 3.

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.