Gnu grub startup Manager

Source: Internet
Author: User
Tags password protection

What is the startup manager?
The startup manager is a program stored in the Start sector of the disk. For example, the hard disk MBR (Master Boot Record). After the system completes the startup test, if the system starts from the MBR, the BiOS (Basic Input/Output System) sends the control to the MBR. The program stored in MBR will run. This program is called the start manager. Its task is to send the control to the operating system to complete the startup process.
There are many available start managers, including GNU grub (Grand uniied Boot Loader), bootmanager, Lilo (Linux Loader), ntldr (Boot Loader for Windows NT systems), and so on. Next I will discuss GNU grub and its usage.

What is grub?
Grub is a powerful startup manager that can load multiple operating systems, such as Windows, DOS, Linux, GNU Hurd, and * BSD.
Currently, Lilo is the most popular startup manager, which is used to manage the boot of multiple systems. However, if lilo is used, you must remember that every time you change its configuration or install a new kernel, you must re-run Lilo. Moreover, Lilo's flexibility is inferior to grub's.
Grub is flexible to use. Its latest version, 0.5.96.1, supports ext2 (a file system used in Linux), FFs (fast file system used by * bsd unix ), reiserfs (a new log file system developed for Linux, to be integrated into the 2.4.1 kernel, minix (an old-fashioned file system developed for the minix system, in earlier Linux versions ). With grub, you can "see" these file systems without even booting the operating system. For example, if you want to view the date and time in the text file and do not want to guide the entire operating system, you can use grub shell ("Grub>" prompt "), run the following command:

Grub> cat (partition number)/home/god/2003104110531.htm.txt.

You can see all information related to the file, including the date and time.
The best application of GRUB is that you can easily guide any kernel that is not in any partition in the list. For example, if you haven't added the newly compiled kernel to the boot list, and you need to boot it, you can add it to the list first and use it after restart. However, after GRUB is used, you can simply use GRUB shell to load the required kernel image.
Now I will explain the three basic steps for using GRUB: compilation, installation, and configuration.

Step 1: Compile and install GRUB
You can download the GRUB source code from the ftp://alpha.gnu.org/pub/gnu/grub.
Run tar-xvzf 2003104110531.htm.tar.gz To uncompress the file. The file I got is grub-0.5.96.1.tar.gz, so I do this:

# Tar-xvzf grub-0.5.96.1.tar.gz

This command places the unwrapped files and directories in a directory named grub-0.5.96.1. Run the following command:

[Root @ heaven ~ /Grub-0.5.96.1] #./configure

If you want to customize GRUB to include popular file systems and support for NICs, or delete NICs you do not need, run the following command:

[Root @ heaven ~ /Grub-0.5.96.1] #./configure -- help

This command outputs all command options. You can now use the-enable and-Disable options to add or remove support for a specific Nic. (Note: grub supports Network startup)
To start the compilation process, enter the following command:

[Root @ heaven ~ /Grub-0.5.96.1] # Make

To correctly install all files, type the following command:

[Root @ heaven ~ /Grub-0.5.96.1] # make install

Now you are ready to install grub.
It is a good idea to save grub-related files in directories such as/boot/grub. To do this, follow these steps:
1. by default, all grub files will be installed in the/usr/share/GRUB/i386-pc or/usr/local/share/GRUB/i386-pc directory, it only depends on the setting of your shell variable.
2. Create a directory named/boot/grub and copy the following files to the directory:
Stage1
Stage2
* _ Stage00005

I will explain these files later. At the same time, copy grub (possibly in the/usr/sbin or/usr/local/sbin directory) to the/boot/GRUB directory.
Before installing grub, You Need To Know How grub recognizes your hard disk and partition information. First, the count starts from 0, not from 1. In Linux, the first hard disk you connect to the master controller is called "had ". In grub, it is "hd0 ". Similarly, in grub, your first soft drive is "fd0 ". In this way, the first, second, and third partitions on the first hard disk are "hd0, 0", "hd0, 1", and "hd0, 2 ". Note: The comma (,) is a required component of the grub partition name method.
Parentheses are used to combine the separated parts. For example: (hd0, 0) (hd0, 1) (hd0, 2. (Hd0, 0) is the first partition on the first hard disk. Similarly, (hd1, 5) is the sixth partition on the second fast hard disk, and (hd2, 0) is the first partition on the third hard disk.
Message. This may take a long time.

Step 2: Install grub
You can install grub in three separate steps:
1. Install "stage1" in MBR.
2. Set the address or location of "stage2.
3. Set a menu or option to decide which operating system to start.
Run the following command to install grub.

[Root @ heaven/boot/GRUB] #./GRUB

This command detects hardware devices based on bios settings and generates some output information. This takes a long time.
End_request: I/O error, Dev 02: 00 (floppy), Sector 0
GRUB version 0.5.96.1 (640 K lower/3072 K upper memory)
Note: although it is amazing, GRUB does have a simple interface-just like supporting row editing. TAB to list possible commands. In other cases, the TAB lists the devices or file names. You will be surprised to see this. The following prompt appears:

Grub>

Now, I assume that you have installed Linux in the first extended partition of the first hard disk or/dev/hda5. Remember the naming rules of GRUB and change the above name to (hd0, 4 ). Type the following command:
Grub> install (hd0, 4)/boot/grub/stage1 (hd0) (hd0, 4)/boot/grub/stage2 p (hd0, 4) /boot/grub/menu. conf
Now let's analyze the details of this command.

Install
A built-in command tells GRUB to install (hd0, 4)/boot/grub/stage1 to the Master boot Record of hd0.
(Hd0, 4)/boot/grub/stage2
The location of the GRUB stage2 image.
P with the following options: (hd0, 4)/boot/grub/menu. conf
Set the configuration file for the menu display. I will discuss the structure of this configuration file later.
The following is a summary of the usage of this command:
1. nstall
2. ource_of_stage1
3. where_to_install
4. source_of_stage2
5. P source_of_configuration_file
Now you have completed the basic installation on the hard disk.

Install on a floppy disk:
To install grub on a floppy disk, run the "DD" command and learn how it works. To create a grub boot disk, you need to put the stage1 and stage2 files in the Start sector of the floppy disk.

Install stage1 on a floppy disk:
Insert a formatted floppy disk and run the following command:
[Root @ heaven/boot/GRUB] # dd If = stage1 of =/dev/fd0 BS = 512 COUNT = 1
The command details are as follows:
If = input file
I. e., stage1
Of = output file
I. e., Floppy Drive (this may be different on your computer)
BS = bytes to read and write
Here it is 512 bytes.
Count = how many times to perform this operation
Copy the "bs" block to the target address each time.
Install stage2 to a floppy disk

[Root @ heaven/boot/grub] # dd if = stage2 of =/dev/fd0 bs = 512 seek = 1

The steps here are the same as those in stage1, except for the seek option. The Seek option calls a "bs ". For example, in the above command, the bs value is 512, so that seek = 1 means that the first 512 bytes of the floppy disk will be skipped, starting from 513 bytes. This will prevent the first step from overwriting the first 512 bytes of stage1.
Now you have installed the basic Floppy Drive.

Step 3: Configure GRUB
In this section, let's take a look at how to enter various operating systems after startup and how to create a menu. conf file.
We start with the startup process supported by GRUB. There are two methods to complete the startup process:
· A. Local startup by calling the kernel
· B. Continuous start or transfer control to another pilot

Startup Process of Mode
1. Connect to the device or tell GRUB your root file system.
2. V. GRUB the location of your kernel image, and then transmit the parameter to the kernel.
3. Restart and try again.
To start Linux, I put the kernel in the/boot/directory with the bzimage file name, and the file system is/dev/hda5 or GRUB (hd0, 4 ). My startup process is as follows:
1. Root (hd0, 4) [This sets the root partition]
2. kernel/boot/bzimage root =/dev/hda5 [This sets the kernel]

Start Process in B mode (this mode assumes that another start manager, such as LILO or ntldr, is installed in the current partition ):
1. Set the root partition but do not install it
2. Activate this partition
3. Configure the first sector of the partition to be started
4. Restart and check the effect.
We are trying to start widows installed in/dev/hda1 or (hd0, 0. Start Windows as follows:
1. rootnoverify (hd0, 0)
2. makeactive
3. chainloader + 1 [+ 1 sets the first sector of the current root partition]
4. Boot [transfers the control and quits grub]
Menu. conf file: it is used to create a menu when multiple operating systems are started. It is not difficult to create menu. conf. It uses simple English, as you can see in this section.
All menu items start with "title titlename" without commas. You can set titlename at will.
To set the Linux Startup menu, follow these steps:
1. Set the title
2. Set the root Partition
3. Set Kernel Parameters
4. Start

A menu example:
Title Debian GNU/Linux 2.2 kernel 2.4.1
Root (hd0, 4)
Kernel/boot/bzimage.2.4.1
Boot
#----

The line with # above is a comment.

Create a menu to start Windows or DoS:
Title shortze
Rootnoverify (hd0, 0)
Makeactive
Chainloader + 1
Boot
#----

If you have installed two versions of Windows-one for your own use and the other for your family-so that the second one cannot be installed, because a prompt says Windows has been installed.
There is a simple way to install two versions of Windows, that is, hide one partition at startup and use the other. You can even set password protection for your partition to prevent others from loading your partition incorrectly. The following describes how to install hda1 and hda2, or (hd0, 0) and (hd0, 1) on two Windows systems. The commands used include lock, password, hide, and unhide.

Create a windows project "My Entry ":
Title My Entry
Lock
Unhide (hd0, 0)
Hide (hd0, 1)
Rootnoverify (hd0, 0)
Makeactive
Chainloader + 1
Boot
#----

To better use the lock command, you need to use the password command at the beginning of the configuration file. The Password command syntax is as follows: password secret ("secret" indicates the Password ). You can press p to enter the password at any time.

Create a Windows project "Family Entry"
Title Family Entry
Unhide (hd0, 1)
Hide (hd0, 0)
Rootnoverify (hd0, 1)
Makeactive
Chainloader + 1
Boot
----
 
Anyone can start this project without entering a password.
This is an interesting trick to use the password command. To hide certain items in the default menu list or configuration file, you can use the following command to load a custom list:

Password secret

In this command, "secret" is the password, And/boot/grub/secret-list.conf is the password file. Before doing so, you must first enter the root directory or give a full path name. For example:

Password secret (hd0, 4)/boot/grub/secret-list.conf

Another more important command is "map ". If you have two hard disks, an operating system that cannot be started from the second one, such as Windows, you can use the map command. For example, you can map hd0 to hd1 and hd1 to hd0. In other words, you can switch two hard disks and start the required operating system. The command format is as follows:
Grub> map (hd0) (hd1)
Grub> map (hd1) (hd0)

Start FreeBSD:
Title FreeBSD 4.0
Root (hd0, 4,)
Kernel/boot/loader
Boot
#----

Here we call the startup manager of FreeBSD. Root (hd0, 4, A) consists of four parameters because FreeBSD performs virtual segmentation on a separate partition. The root partition is called "". If FreeBSD occupies the second hard disk, it should be root (hd0, ). In this way, instead of calling the kernel, calling the FreeBSD startup manager is easier to use than calling the kernel.
(Note: Before using OpenBSD and GNU/Hurd, we recommend that you first try chain loading .)
Now you have completed the basic grub compilation, installation, and configuration. The more you know about grub, the more you will find that grub is an easy-to-use and efficient method to control startup.

Various grub commands:
Default xx
XX is the default startup project.
Timeout YY
Indicates that the project will be started by default after YY seconds
Fallback ZZ
After the first project fails to be started and the timeout time expires, the ZZ project will be started.
Color
This command generates a color menu. Its syntax is: Color normal current_selection. Both fields can have two values, such as foreground/background. For example:

Color green/black or light-gray/blue

You can also use related numbers.
Remember: All values start from 0, so 0 is the first.
In my next article, I will talk about the test of GNU/Hurd and OpenBSD, and some network startup content. However, you have to wait for at least three months or more until I talk about my test results. Wait.
 

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.