Restore the Linux bootloader in Rescue
The main bootloader for Linux operating systems is GRUB. If the Linux bootloader was deleted, corrupted, or stopped working after replacing a disk, 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.
Disk partitioning without software RAID
Disk partitioning with software RAID
-
Determine the OS boot mode:
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"The output will show information about the OS boot mode —
BIOSorUEFI. -
Output information about the partitions on the disks:
lsblk -o +FSTYPEThe response will contain information about the partitions on the disks. For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS FSTYPEsda 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 ext4sdb 8:16 0 8G 0 disk├─sdb1 8:17 0 4G 0 part ext4└─sdb2 8:20 0 4G 0 part xfsHere
sda1,sda2,sda3,sda4,sdb1,sdb2are disk partitions. In your OS, partition names may differ. -
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 partitionsda4; - boot partition
/boot— usually a partition with the ext4 file system and a size of 512 MB – 1 GB. In the example in step 3, this is partitionsda3; - EFI partition
/boot/efi— used when booting the OS in UEFI mode. This is a partition with the vfat file system. In the example in step 3, this is partitionsda2.
- root partition
-
Mount the root file system to the
/mntdirectory:mount /dev/<system_partition> /mntSpecify
<system_partition>— the root partition/that you selected in step 4; in the example, it issda4. -
Mount the boot partition:
mount /dev/<boot_partition> /mnt/bootSpecify
<boot_partition>— the boot partition/booton the disk that you selected in step 4; in the example, it issda3. -
If using the OS UEFI bootloader, mount the EFI partition:
mount /dev/<efi_partition> /mnt/boot/efiSpecify
<efi_partition>— the EFI partition/boot/efithat you selected in step 4; in the example, it issda2. -
Mount the system filesystems:
mount --bind /sys /mnt/sysmount --bind /proc /mnt/procmount --bind /dev /mnt/devmount -t devpts devpts /mnt/dev/pts -
Connect to the environment:
chroot /mnt /bin/bash -
Export the PATH variable:
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH
-
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, it issda. -
Create the GRUB configuration file:
/sbin/grub-mkconfig -o /boot/grub/grub.cfg -
After completing the work, exit the environment:
exit -
Unmount the system filesystems:
umount -t devpts devpts /mnt/dev/ptsumount --bind /dev /mnt/devumount -t sysfs /sys /mnt/sysumount -t proc /proc /mnt/proc -
Unmount the filesystem:
umount /dev/<system_partition> /mntSpecify
<system_partition>— the root partition/that you mounted in step 5; in the example, it issda4.