Restore the Linux bootloader in Rescue
The primary boot loader for Linux operating systems is GRUB.If the Linux boot loader has been 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 on the primary 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 available disks:
lsblk -o +FSTYPEA list of disks with partitions will appear in the response. 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 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/sys
mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount -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/pts
umount --bind /dev /mnt/dev
umount -t sysfs /sys /mnt/sys
umount -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.
-
Determine the boot mode of the OS:
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"The response will show information about the boot mode of the OS —
BIOSorUEFI. -
Check if the system has detected RAID arrays, to do this, display the partition information on the available disks:
lsblk -o +FSTYPEA list of disks with partitions will appear in the response. For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT FSTYPE
sda 8:0 0 447.6G 0 disk
├─sda1 8:1 0 512M 0 part vfat
├─sda2 8:2 0 500M 0 part
│ └─md0 9:0 0 500M 0 raid1 ext4
└─sda3 8:3 0 446.6G 0 part
└─md1 9:1 0 446.6G 0 raid1 ext4
sdb 8:16 0 447.6G 0 disk
├─sdb1 8:17 0 512M 0 part
├─sdb2 8:18 0 500M 0 part
│ └─md0 9:0 0 500M 0 raid1 ext4
└─sdb3 8:19 0 446.6G 0 part
└─md1 9:1 0 446.6G 0 raid1 ext4Here
md0,md1are RAID arrays on disk partitions. RAID names may be different in your OS. -
If there are RAIDs in the
lsblkoutput at step 3, skip this step.If there are no RAIDs, run RAID build:mdadm --assemble --scan -
Print information about the partitions on the available disks:
lsblk -o +FSTYPEA list of disks with partitions will appear in the response. For example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT FSTYPE
sda 8:0 0 447.6G 0 disk
├─sda1 8:1 0 512M 0 part vfat
├─sda2 8:2 0 500M 0 part
│ └─md0 9:0 0 500M 0 raid1 ext4
└─sda3 8:3 0 446.6G 0 part
└─md1 9:1 0 446.6G 0 raid1 ext4
sdb 8:16 0 447.6G 0 disk
├─sdb1 8:17 0 512M 0 part
├─sdb2 8:18 0 500M 0 part
│ └─md0 9:0 0 500M 0 raid1 ext4
└─sdb3 8:19 0 446.6G 0 part
└─md1 9:1 0 446.6G 0 raid1 ext4Here
md0,md1are RAID arrays on disk partitions. RAID names may be different in your OS. -
Determine the RAID partitions to be mounted:
- root RAID partition
/— this is usually the largest partition on the disk, in the example in step 5 this is arraymd1; - boot RAID partition
/boot— usually a partition with ext4 file system and a size of 512 MB to 1 GB. In the example in step 5, this is themd0array; - 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 5 it issda1and, if the EFI partition has been cloned to a second disk,sdb1.
- root RAID partition
-
Mount the root file system to the
/mntdirectory:mount /dev/<system_raid_array> /mntHere
<system_raid_array>is the root RAID partition you selected in step 6, in the example it ismd1. -
Mount the bootable RAID partition:
mount /dev/<boot_raid_array> /mnt/bootSpecify
<boot_raid_array>is the boot RAID array/bootthat you selected in step 6, in the example it ismd0. -
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 6, in the example it issda1. -
Mount the service file systems:
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount -t devpts devpts /mnt/dev/pts -
Connect to the environment:
chroot /mnt /bin/bash -
Export the PATH variable:
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin -
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 — Install a boot loader on each disk from which the OS will boot:
grub-install /dev/<disk_1>
grub-install /dev/<disk_2>Specify
<disk_1>,<disk_2>— system disks where the OS is installed and the root partition/is located, in the example at step 5 these aresdaandsdb.Depending on the number of devices in RAID there may be more disks. -
Create a GRUB configuration file:
/sbin/grub-mkconfig -o /boot/grub/grub.cfg -
Exit the environment when the work is complete:
exit -
If your system has only one EFI partition, skip this step.If your system has an EFI partition cloned to multiple disks, install the GRUB boot loader on each disk:
16.1 Unmount the EFI partition:
unmount /mnt/boot/efi16.2 Mount the EFI partition:
mount /dev/<efi_partition_2> /mnt/efi2Specify
<efi_partition_2>is the EFI partition on the second disk, in the example in step 5 it issdb1.16.3 Mount the service file systems:
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount -t devpts devpts /mnt/dev/pts16.4 Connect to the environment:
chroot /mnt /bin/bash16.5 Install the GRUB boot loader:
grub-install --target=x86_64-efi --efi-directory=/efi2 --bootloader-id=GRUB16.6 Create a GRUB configuration file:
/sbin/grub-mkconfig -o /boot/grub/grub.cfg16.7 After the work is completed, exit the environment:
exit -
Unmount the service file systems:
umount -t devpts devpts /mnt/dev/pts
umount --bind /dev /mnt/dev
umount -t sysfs /sys /mnt/sys
umount -t proc /proc /mnt/proc -
Unmount the file system:
umount /dev/<system_raid_array> /mntSpecify
<system_raid_array>is the root RAID partition/that you mounted in step 7, in the example it ismd1.