Skip to main content

Restore the Linux bootloader in Rescue

The primary Linux operating system bootloader is GRUB. If the Linux bootloader has been deleted, corrupted, or stopped working after a disk replacement, you can restore it. To do this, boot the server in Rescue mode, mount the main partitions in the same way they are mounted in the main system, and install the GRUB bootloader.

  1. Boot the server into Rescue recovery and diagnostics mode.

  2. Determine the OS boot mode:

    [ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"

    The response will contain information about the OS boot mode — BIOS or UEFI.

  3. Output information about the partitions on the disks:

    lsblk -o +FSTYPE

    The response will contain information about the partitions on the disks. For example:

    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS FSTYPE
    sda 8:0 0 25G 0 disk
    ├─sda1 8:1 0 1M 0 part
    ├─sda2 8:2 0 512M 0 part vfat
    ├─sda3 8:2 0 1G 0 part ext4
    └─sda4 8:3 0 23,5G 0 part ext4
    sdb 8:16 0 8G 0 disk
    ├─sdb1 8:17 0 4G 0 part ext4
    └─sdb2 8:20 0 4G 0 part xfs

    Here sda1, sda2, sda3, sda4, sdb1, sdb2 are disk partitions. In your OS, the partition names may differ.

  4. Identify the partitions that need to be mounted:

    • root partition / — usually the largest partition on the disk; in the example in step 3, this is partition sda4;
    • boot partition /boot — usually a partition with the ext4 filesystem and a size of 512 MB — 1 GB. In the example in step 3, this is partition sda3;
    • EFI partition /boot/efi — used when booting the OS in UEFI mode. This is a partition with the vfat filesystem. In the example in step 3, this is partition sda2.
  5. Mount the root filesystem to the /mnt directory:

    mount /dev/<system_partition> /mnt

    Specify <system_partition> — the root partition / that you selected in step 4; in the example, this is sda4.

  6. Mount the boot partition:

    mount /dev/<boot_partition> /mnt/boot

    Specify <boot_partition> — the boot partition /boot on the disk that you selected in step 4; in the example, this is sda3.

  7. If using the OS UEFI bootloader, mount the EFI partition:

    mount /dev/<efi_partition> /mnt/boot/efi

    Specify <efi_partition> — the EFI partition /boot/efi that you selected in step 4; in the example, this is sda2.

  8. Mount the system filesystems:

    mount --bind /sys /mnt/sys
    mount --bind /proc /mnt/proc
    mount --bind /dev /mnt/dev
    mount -t devpts devpts /mnt/dev/pts
  9. Connect to the environment:

    chroot /mnt /bin/bash
  10. Export the PATH variable:

export export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH
  1. Install the GRUB bootloader. The command depends on the OS bootloader you identified in step 2:

    • UEFI:
    grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
    • BIOS:
    grub-install /dev/<disk>

    Specify <disk> — the system disk where the OS is installed and the root partition / is located; in the example in step 3, this is sda.

  2. Create the GRUB configuration file:

    /sbin/grub-mkconfig -o /boot/grub/grub.cfg
  3. After completing the work, exit the environment:

    exit
  4. Unmount the system filesystems:

    umount -t devpts devpts /mnt/dev/pts
    umount --bind /dev /mnt/dev
    umount -t sysfs /sys /mnt/sys
    umount -t proc /proc /mnt/proc
  5. Unmount the filesystem:

    umount /dev/<system_partition> /mnt

    Specify <system_partition> — the root partition / that you mounted in step 5; in the example, this is sda4.