How do I restore the /boot directory after accidentally deleting its contents or corruption?
Environment
- Red Hat Enterprise Linux 7
Issue
- How do I restore the
/bootdirectory after accidentally deleting its contents? - How do I restore the
/bootafter 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
yumworking 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
grub2packages 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
/bootcontents created and boot the system, but if you have backup of/bootthen we strongly recommend to restore it from backup.
Root Cause
- Accidental delete of
/bootcontents. - Corruption to
/bootfilesystem leading to cleanup of/bootcontents.
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.