How to restore GRUB?

There was Linux Mint and Windows 7.
Windows flew off.
Reinstalled Windows and rubbed grub. Is it possible to restore the boot sector for linux without reinstalling it ?

Author: Ray, 2011-04-07

2 answers

You need to boot from the LiveCD, then mount the root partition of the installed Linux system, for example, in the /mnt folder.

Becoming a superuser

$ sudo su

Find out what Linux saw partitions and file systems

# fdisk -l /dev/sda
# blkid
# lsblk

Mounting the root

# mount /dev/sda3 /mnt

Where sda3 is the partition with the root file system of the installed Linux.

If the contents of /boot were located in a separate partition from the root filesystem, it is also located in the root filesystem. must be mounted. But at the beginning, of course, the root is always mounted, after which the file system from boot to /mnt/boot is necessary, if after mounting the root, the /boot directory of the installed system is empty.

Example of mounting /boot.

# mount /dev/sda4  /mnt/boot/

Then mount virtual FS

# mount --bind /dev  /mnt/dev
# mount --bind /dev/pts  /mnt/dev/pts
# mount --bind /proc /mnt/proc
# mount --bind /dev  /mnt/dev
# mount --bind /sys  /mnt/sys

Changing the current root

# chroot /mnt

You will find yourself already in your old system, then run

# grub-install
# update-grub2

Let's get out of the root. systems

# exit

The first command will install the boot loader stage1 grub2 in the MBR, the second will update the boot list - search for systems and add them to the boot menu.

Next, you need to unmount all the file systems in the reverse order

# umount /mnt/sys
# umount /mnt/dev
# umount /mnt/proc
# umount /mnt/dev/pts
# umount /mnt/dev
# umount /mnt/

Next, turn off the computer. Turn it on. Install the boot from the hard disk.

# reboot
 14
Author: Andrey Kozhaev, 2015-09-07 16:51:44

This is the safest method of restoring GRUB. It doesn't need a chroot environment, it doesn't even need block devices from /dev.

Explanation:

GRUB defines hard drives connected to the SATA and IDE interfaces as (hdномер устройства); numbering starts from zero. The partition is defined by the next number after the device number.

Examples:

  • (hd0) - the 1st hard disk in its entirety;
  • (hd0,0) - 1st section on the 1st on the disk;
  • (hd0,1) - 2nd partition on the 1st disk;
  • and so on.

GRUB2 starts numbering the partitions with 1, and the devices are still numbered from zero.*

Note: GRUB allows you to get this and other functionality even before loading the OS. To avoid hacking, you need to set a global password. For further details, see the bootloader documentation.

Procedure:

  1. Shipping GNU / Linux from CD or USB.
  2. Running GRUB as root in shell mode:

    # grub 
    
  3. Next, we determine how the grub property is defined. To do this, enter the following command:

    • if /boot is a separate FS: # find /grub/stage1;
    • if not: find /boot/grub/stage1. GRUB in response will display the section on which this file is located. It is the one that is needed for the following manipulations.
  4. Tell GRUB where boot-partition / directory

    # root (номер_нужного_диска,номер_нужного_раздела)
    

    Example:

    # root (hd0,0)    
    
  5. Specify the device to write to the MBR of the first sector:

    # setup (нужный_раздел)    
    

    Example:

    # setup (hd0)
    
  6. It's all done. GRUB has configured the MBR to boot itself from the partition you need. Exiting GRUB:

    # quit
    
 8
Author: modal, 2016-08-24 15:11:41