Restore the Linux bootloader in Rescue
The main boot loader for Linux operating systems is GRUB. If the Linux boot loader was deleted, corrupted or stopped working after a disk replacement, you can recover the boot loader. To do this, boot the server in Rescue mode, mount the primary partitions the same way they are mounted in the main system, and install the GRUB boot loader.
Disk partitioning without software RAID
Disk partitioning with software RAID
-
Determine the boot mode of the OS:
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"The response will show information about the OS boot mode -
BIOSorUEFI. -
Print information about the partitions on the disks:
lsblk -o +FSTYPEThe response will show 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 partitions on disks. Partition names may be different in your OS. -
Determine the partitions you want to mount:
- root partition
/is usually the largest partition on the disk, in the example in step 3 it is partitionsda4; - boot partition
/boot- usually a partition with ext4 file system and a size of 512 MB to 1 GB. In the example in step 3, this is thesda3partition; - EFI partition
/boot/efi- is used when booting the OS in UEFI mode. It is a partition with a vfat file system. In the example in step 3, this is thesda2partition.
- root partition
-
Mount the root file system to the
/mntdirectory:mount /dev/<system_partition> /mntSpecify
<system_partition>is 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>is the/bootpartition on the disk you selected in step 4, in the example it issda3. -
If you are using a UEFI OS loader, mount the EFI partition:
mount /dev/<efi_partition> /mnt/boot/efiSpecify
<efi_partition>is the EFI/boot/efipartition you selected in step 4, in the example it issda2. -
Mount the service file systems:
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 export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH
-
Install the GRUB boot loader. The command depends on the OS boot loader you defined in step 2:
- UEFI:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB- BIOS:
grub-install /dev/<disk>Specify
<disk>is the system disk where the OS is installed and the root partition/is located, in the example in step 3 this issda. -
Create a GRUB configuration file:
/sbin/grub-mkconfig -o /boot/grub/grub.cfg -
Exit the environment when the work is complete:
exit -
Unmount the service file systems:
umount -t devpts devpts /mnt/dev/ptsumount --bind /dev /mnt/devumount -t sysfs /sys /mnt/sysumount -t proc /proc /mnt/proc -
Unmount the file system:
umount /dev/<system_partition> /mntSpecify
<system_partition>is the root partition/that you mounted in step 5, in the example it issda4.