1. Introduction Grub is what? In the most normal sense, grub is a bootloader or a bootmanager that can guide a wide variety of systems through grub, such as Linux, FreeBSD, Windows, and so on. But once in the Linux operating system (if no special declaration, the following mentioned operating system or system are Linux operating system), you can hit a grub command, go to the "grub>" prompt state, and then you can enter the operation of several commands. What is grub at this time? is a shell, a shell similar to bash. Two modes of operation, Interactive (interactive) and non-interactive (batch) are provided, and the Grub-install command takes advantage of the non-interactive mode of grub to complete the installation of grub directly under the system.
2. Three ways to install grub there are actually 3 ways, the most commonly used is grub-install, there are two kinds of grub>install and grub>setup, of which Grub>install is the bottom of the way,grub> Setup is a higher-level approach, and Grub-install is the simplest way to be the most advanced. Let's start with Grub>install, and make a distinction between 3 different ways:
2.1. Grub>install after entering the grub> prompt, enter the Help install command with the following prompt:
Install:install [--stage2=stage2_file] [--force-lba] STAGE1 [d] DEVICE STAGE2 [ADDR] [P] [config_file] [real_config_file Where STAGE1 DEVICE STAGE2 is essential, the following is an example:
Install (hd0,0)/grub/stage1 (hd0) (hd0,0)/grub/stage2
Or it can be as follows:
Root (hd0,0)
Install/grub/stage1 (hd0)/grub/stage2
Grub can be successfully installed in such a way, but after the system reboot, it cannot enter the system, but directly into the grub>.why?
Because this installation method did not tell grub where to find grub.conf,stage2 can not find grub.conf will enter Grub>
Installation is OK with the following form.
Root (hd0,0)
Install/grub/stage1 (hd0)/grub/stage2 p/grub/grub.conf
2.2. Grub>setup after entering the grub> prompt, enter the help Setup command with the following prompt:
Setup:setup [--prefix=dir] [--stage2=stage2_file] [--force-lba] install_device [Image_device]
Set up the installation of GRUB automatically. This command uses
The more flexible command "install" in the backend and installs
GRUB into the device Install_device. As we can see from the above, Setup is an automated (automatically) grub installation that runs a more flexible install command in the background (backend). See Example:
grub> Root (hd0,0)
Filesystem type is EXT2FS, partition type 0x83
grub> Setup (hd0)
Checking if "/boot/grub/stage1" exists ... no
Checking if "/grub/stage1" exists ... yes
Checking if "/grub/stage2" exists ... yes
Checking if "/grub/e2fs_stage1_5" exists ... yes
Running "Embed/grub/e2fs_stage1_5 (hd0)" ... Sectors is embedded.
Succeeded
Running "Install/grub/stage1 (hd0) (hd0) 1+16 P (hd0,0)/grub/stage2/grub/grub.conf" ... succeeded done.
As you can see, the Setup command encapsulates the install command, and using the Setup command is much simpler than using the install command. But the actual process is a bit more complicated than the install, which is especially important: Using Setup to implant e2fs_stage1_5 to the first cylinder of the hard drive after the 16th sector (this is not verified correctly), this will bring a big difference with the install installation.
2.3. Grub-install the most common way to install grub is to install it through a Grub-install script after entering the system, and how does this script install differ from the first two?
The script is actually called by the Setup command to install grub through the non-interactive mode of grub. The installation source for the script is Stage1, 2, and various stage1.5 under/usr/share/grub/i386-redhat/, while the source used in the first two methods is the same content under/boot/grub/. So installing grub through grub-instal, it's okay to delete the stage files that were originally under/boot/grub, and the script will delete the files each time it executes. Conversely, the first two ways to install, the corresponding stage file is indispensable, otherwise it will error, installation failure. [*] After installing grub through Grub-install, if we delete the Stage2 file under/boot/grub/, the system will not start, reported the following error: Grub loading Stage 1 .5
GRUB loading, please wait ...
Error 15
However, if GRUB is installed by Grub>install, removing/boot/grub/stage2 is no problem, why? Because through Grub>install installation grub,stage1 is directly through the Stage2 blocklist find Stage2, we delete or rename the Stage2 file, the location of the file is unchanged, so can be found. By Grub-install scripts, or Grub>setup, the corresponding stage1.5 can be found intelligently, for example:/grub/e2fs_stage1_ 5, then through the stage1.5 to understand the file system, is through the file name to find Stage2, so through the two ways to install grub, can not be deleted or renamed/boot/grub/stage2.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A lot of information about grub, but there are some areas are not very clear, I hope to discuss with you here
Statement One
Stage1 is the system put in bootloader, he is to find stage1.5 and stage2 exist. When installing grub, it is already in stage1
stage1.5 and Stage2 are embedded in the physical address of the disk, when Stage1 find stage1.5 stage1.5 by Stage2 to find, if not found
stage1.5 the physical address of the disk Stage2 in Stage1 to find Stage2.
But here are some questions:
Stage1 found stage1.5 after not give control to stage1.5, if the control is given to stage1.5, then when stage1.5
In the way the file system is not found when stage2 directly to the physical address of the disk to find Stage2, which means that stage1.5 also embedded in
The physical address of the stage2. Still is:
Stage1 find stage1.5 after not give control to stage1.5, let stage1.5 to file system way to find stage2, if can't find
Then by Stage1 directly to find Stage2. This means that the physical address of the Stage2 disk is only written in Stage1.
Argument two
Stage1 was not looking for stage1.5 and stage2. Instead, it will go to the start of the second sector at boot, then start to find stage1.5 and Stage2.
There is no physical address of the disk embedded in the Stage1 stage1.5 and Stage2.
The questions and the above are the same. How their control area is delivered! and the physical address of the stage1.5 and Stage2 are embedded in start. and stage1.5.
The physical address of the disk embedded with the stage2.
Can be sure that:
The stage1.5 is placed in the sector set of the 3rd sector and the 64th sector of the 0 track, and when you install grub, it will be stage1.5 based on the filesystem that your/boot partition belongs to.
(If your/boot partition is ext3.) Then install only the ext3 stage1.5 installation, the other is in the form of files in the/boot/grub)
Stage2 was put in/boot/grub.
Three ways to install grub installation