After installing a linux system with dual hard disks, grub reports an error after removing one hard disk!

Because the MBR master boot sector where GRUB is located has been destroyed, the system cannot start normally.
Use the installation CD to boot into the rescue mode.
step:

  1. Installation CD or U disk installation method, the installation interface selects the Troubleshooting mode
  2. Select Rescue a CentOS Linux system to enter.
  3. Prompt that the system on the hard disk has been found and mounted under /mnt/sysimage, select 1, continue to load in read-write mode
  4. Prompt to enter chroot /mnt/sysimage to change to the root directory of the disk, please press ENTER to get a shell:
  5. Press Enter to enter sh-4.4# Note: There is no chroot /mnt/sysimage at this time
  6. #chroot /mnt/sysimage
  7. bash4.4##fdisk -l /dev/sda {use fdisk to check the partition}
  8. bash4.4#grub2-install /dev/sda {install the grub boot program to the MBR sector of the disk /dev/sda}
  9. bash4.4#exit
    reboot…Restart it

Or
in a Linux system that you can access, install grub on the added hard disk

sh-4.4#grub
grub>root (hdx,y)
grub>setup (hd0)
grub>quit
where X, if it is a disk, is 0, if the root partition of the linux you are installing is on the second hard disk, Then X is 1; Y is the root partition where the Linux system is installed. setup (hd0) is to write GRUB to the MBR of the hard disk.

Three installation methods for grub installation

  1. Introduction What is grub? The most common understanding is that grub is a bootloader or a bootmanager, through which grub can boot a variety of systems, such as linux, freebsd, windows, etc. But once you enter the linux operating system (if there is no special statement, the operating systems or systems mentioned below are all linux operating systems), you can type a grub command to enter the "grub>" prompt state, and then you can enter to operate several commands. What is grub at this time? It is a shell, a shell similar to bash. It also provides two working modes, interactive mode and batch mode. The grub-install command takes advantage of the non-interactive mode of grub and directly completes the installation of grub under the system.

  2. There are actually 3 ways to install grub. The most commonly used is grub-install. In fact, there are two grub>install and grub>setup. Among them, grub>install is the lowest way, and grub>setup is the higher one. Layer method, and grub-install is the most advanced and simplest method. Next, let’s start with grub>install and make a distinction between three different ways:

2.1. grub>install After entering the grub> prompt, enter the help install command, there will be the following prompt:
install: install [–stage2=STAGE2_FILE] [–force-lba] STAGE1 [d] DEVICE STAGE2 [ADDR] [p] [ CONFIG_FILE] [REAL_CONFIG_FILE] Among them, 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
can successfully install grub in this way, but after the system is rebooted, you cannot enter the system, but go directly to grub>.why?
Because this installation method does not tell grub to go Where to find grub.conf, stage2 will enter grub> if it cannot find grub.conf.
Install with the following form and it will be ok.
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, and the following prompt will
appear : 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. From the above content, we can see that setup is an automatic (automatically) grub installation, it is in the background (backend ) Run the more flexible install command. See the 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)”… 16 sectors are embedded.
succeeded
Running “install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub .conf"... succeeded Done.
As can be seen from the above, the setup command encapsulates the install command. Using the setup command is much simpler than using the install command. But the actual process is more complicated than install. One of the most important points is that using setup will implant e2fs_stage1_5 after the 16th sector of the first cylinder of the hard disk (this has not been accurately verified), which will bring and pass install installs a big difference.

2.3. grub-install The most common way to install grub is to install it through the grub-install script after entering the system. What is the difference between installing through this script and the previous two methods?
The script actually uses the non-interactive mode of grub to install grub by calling the setup command. [ ] The installation source of the script is stage1, 2 and various stage1.5 under /usr/share/grub/i386-redhat/, and the source used in the first two methods is the same content under /boot/grub/. So install grub through grub-instal, it doesn't matter if the stage files originally under /boot/grub are deleted, the script will delete these files every time it is executed. On the contrary, if you install through the first two methods, the corresponding stage file is indispensable, otherwise an error will be reported and the installation will fail. [ ]After installing grub through grub-install, if we delete the stage2 file under /boot/grub/, the system will fail to boot, and the following error will be reported: GRUB loading stage 1.5
GRUB loading, please wait...
Error 15
However, if it is passed For grub installed by grub>install, there is no problem if you delete /boot/grub/stage2, why? Because grub is installed through grub>install, stage1 is directly searched for stage2 through the blocklist where stage2 is located. We delete or rename the stage2 file. The storage location of the file is unchanged, so it can be found. And through the grub-install script, or grub>setup, it will intelligently find the corresponding stage1.5, for example: /grub/e2fs_stage1_5, and then recognize the file system through stage1.5, find stage2 through the file name, so through this The grub installed in two ways cannot be deleted or renamed /boot/grub/stage2.
Stage1.5 is placed in the sector set of the 3rd and 64th sectors of track 0, and when you install grub, you will choose stage1.5 according to the file system your /boot partition belongs to.
(If your /boot partition is ext3. Then only install ext3 stage1.5 during installation, and the others are stored in the form of files in /boot/grub)
stage2 is stored in /boot/grub

Guess you like

Origin blog.csdn.net/seaship/article/details/108192550