How do I restore the /boot directory after accidentally deleting its contents or corruption?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 7

Issue

  • How do I restore the /boot directory after accidentally deleting its contents?
  • How do I restore the /boot after corruption and missing files?

Resolution

Important Notice


***The following information has been provided by Red Hat, but is outside the scope of the posted [Production Support Scope of Coverage](https://access.redhat.com/support/offerings/production/soc).***
***The supported method to restore the /boot partition is to use the Anaconda installer in the regular Red Hat Enterprise Linux installation process to reinstall the OS.***
***Please follow article [My /boot partition has been deleted, how do I recreate this partition?](https://access.redhat.com/solutions/67543) for Red Hat Enterprise Linux 6 release Legacy BIOS system.***
  • Enable the network to have the yum working Enabling networking in rescue environment without chrooting

  • Mount the to /boot from your disk.

    #mount /dev/<disk_partition> /boot
    Ex:
    #mount /dev/sda1 /boot
    
  • Make the directory structure available.

    #mkdir /boot/grub2
    
  • Copy the modules as or copy the entire things from an identical system as fonts locale directive.

    #cp -r /usr/lib/grub/i386-pc /boot/grub2/i386-pc
    
  • Reinstall the kernel packages as,

    # yum remove kernel-<release>
    # yum install kernel-<release>
    

Note : It is expected to have grubby fatal error: unable to find a suitable template which can be ignored at this stage as the /boot do not have the /boot/grub2/grub.cfg available yet.

  • Install the grub2 packages as

    #yum reinstall $(rpm -qa | grep grub)
    
  • Regenerate the grub configuration as,

    #grub2-mkconfig -o /boot/grub2/grub.cfg
    
  • Check if /etc/grub2.cfg has a symbolic link to /boot/grub2/grub.cfg

  • Finally, reinstall the grub on new created partition as,

    #grub2-install <disk>
    Ex:
    #grub2-install /dev/sda
    
  • If you have UEFI system then follow steps as How to reinstall GRUB and GRUB2 on UEFI-based machines?

  • This all should help to have the /boot contents created and boot the system, but if you have backup of /boot then we strongly recommend to restore it from backup.

Root Cause

  • Accidental delete of /boot contents.
  • Corruption to /boot filesystem leading to cleanup of /boot contents.
SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.