Reinstalling grub after restoring a Ghost image

When restoring a Ghost image for a Linux device, it may be necessary to perform extra steps in order to get the system to boot. This is especially relevant if the image has been restored to a different physical device to that where the image was created from.

One way to enable the system to boot is to reinstall the grub boot loader and recreate the boot image. To do this, boot to a Live Linux environment and follow the general steps below.

su -

List the available storage devices on the system. If the system was deployed using LVM, storage devices may be listed under /dev/mapper:

ls /dev/mapper
centos-root -> ../dm-0
centos-swap -> ../dm-1
live-base -> ../dm-3
live-rw -> ../dm-2

This list indicates that the restored volume should reside on centos-root. Mount the restored root device on /mnt:

cd /mnt
mount /dev/mapper/centos-root ./

Remount the supporting file-systems:

mount -t proc proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/
mount --rbind /var/run/ var/run/

Change the root to the point where the restored disk is mounted:

chroot /mnt/

Mount the /boot mount point so that we can work with the grub configuration:

mount /boot
# or if on an EFI-based system
mount /boot/efi

If necessary, connect to the network:

dhclient `/sbin/route -n | grep "^0.0.0.0" | rev | cut -d' ' -f1 | rev`

Update the packages and reinstall grub:

dnf -y update (optional)
dnf -y reinstall grub2 grub2-efi grub2-efi-modules shim

Recreate the grub configuration:

grub2-mkconfig -o /boot/grub2/grub.cfg

Reinstall the grub boot loader onto the primary disk:

grub2-install /dev/sda

Exit the new root and reboot:

exit
reboot

When the system restarts, it should boot into the grub loader allowing the OS(es) to start.


Posted

in

by

Tags: