Learn how to repair GRUB bootloader in CentOS 8 with our step-by-step guide. Troubleshoot boot issues and restore your system’s functionality easily. #centlinux #linux #grub
GRUB (GRand Unified Bootloader) 2 is part of GNU Project and the default bootloader for famous Linux distros like RHEL, CentOS, Ubuntu, etc. GRUB is the first software program that runs when a computer is started. GRUB is responsible for loading the Kernel software. The Kernel then initializes the rest of the operating system.
GRUB (Grand Unified Bootloader) is a crucial component in the boot process of many Unix-like operating systems, including Linux distributions. It is responsible for loading the kernel of the operating system and transferring control to it, thus starting the OS.
Key features and functionalities of GRUB include:
/boot/grub/grub.cfg
. Users can modify boot entries, set default operating systems, and change timeout values.Understanding and managing GRUB is essential for system administrators and power users, as it directly impacts the bootability and flexibility of the operating system. Problems with GRUB, such as corrupted configurations or missing bootloader files, can prevent a system from starting, making GRUB troubleshooting skills valuable for maintaining system uptime and stability.
Recommended Online Training: Learn Bash Shell in Linux for Beginners
There are situations in which GRUB bootloader is corrupted. In such scenarios, System Administrators have to repair GRUB bootloader.
In this article, we are discussing the following four scenarios and how to repair GRUB bootloader in CentOS 8.
We have provisioned virtual machine with minimally installed CentOS 8 operating system with following specification.
Connect with grub-recovery-01.recipes.com using ssh as root user.
To produce this recovery scenario, we are deleting the grub.cfg file.
[root@grub-recovery-01 ~]# rm -f /boot/grub2/grub.cfg
Your system will continue to perform smoothly, unless you restart it and it will then unable to find the grub.cfg file and it will failed to boot Linux operating system.
Reboot the system now.
[root@grub-recovery-01 ~]# systemctl reboot
The machine will now boot into GRUB prompt because of the missing grub.cfg file.
Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists possible device or file completions. grub>
Restart the system and boot using CentOS 8 ISO/DVD to repair grub.cfg.
At the CentOS 8 installation menu, select Troubleshooting and press <ENTER>.
Select Rescue a CentOS Linux system and press <ENTER>.
It will ask you for mounting your filesystem, choose the option and ‘1’ and press <ENTER>.
Press <ENTER> again to acquire a shell.
Execute chroot command to access your filesystem.
sh-4.4# chroot /mnt/sysimage
By using grub2-mkconfig command, you can regenerate grub.cfg file.
bash-4.4# grub2-mkconfig -o /boot/grub2/grub.cfg
If you are working on an UEFI based machine then you have to generate grub.cfg file in /boot/efi/EFI/centos/ directory.
If you are using SELinux, then create following file to trigger SELinux file relabeling process on next startup.
bash-4.4# touch /.autorelabel
Finally exit from chrooted environment and reboot your system.
bash-4.4# exit sh-4.4# reboot
Boot from your Hard Disk.
If you have repair grub.cfg file by following the above steps correctly, then it will now display the GRUB boot menu.
We have successfully recovered grub.cfg file on CentOS 8.
Connect with grub-recovery-01.recipes.com using ssh as root user.
To produce this recovery scenario, we are removing the vmlinuz-4.18.0-80.el8.x86_64 file.
[root@grub-recovery-01 ~]# rm -f /boot/vmlinuz-4.18.0-80.el8.x86_64
Reboot the system.
[root@grub-recovery-01 ~]# systemctl reboot
On boot, GRUB will display the following warning and unable to load Kernel file.
error: ../../grub-core/fs/fshelp.c:258:file '/vmlinuz-4.18.0-80.el8.x86_64' not found. error: ../../grub-core/loader/i386/pc/linux.c:413:you need to load the kernel first. Press any key to continue...
Restart your system and boot using CentOS 8 ISO/DVD to repair vmlinuz.
At the CentOS 8 installation menu, select Troubleshooting and press <ENTER>.
Select Rescue a CentOS Linux system and press <ENTER>.
It will ask you for mounting your filesystem, choose the option and ‘1’ and press <ENTER>.
Press <ENTER> again to acquire a shell.
Go to Packages directory in ISO/DVD.
sh-4.4# cd /mnt/install/repo/BaseOS/Packages
Reinstall CentOS 8 Kernel using following command.
sh-4.4# rpm -ivh --root=/mnt/sysimage --replacepkgs kernel-core-4.18.0-80.el8.x86_64.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:kernel-core-4.18.0-80.el8 ################################# [100%]
Verify that vmlinuz-4.x file is created by the installer.
sh-4.4# ls /mnt/sysimage/boot/vmlinuz* /mnt/sysimage/boot/vmlinuz-0-rescue-9239012f800e401d86d70eef6bc4f8b6 /mnt/sysimage/boot/vmlinuz-4.18.0-80.el8.x86_64
If you are using SELinux then create following file to trigger SELinux file relabeling process on next startup.
sh-4.4# touch /mnt/sysimage/.autorelabel
Reboot the system now.
sh-4.4# reboot
The GRUB will be able to load the Kernel now and you will reach at the login prompt after successful startup.
CentOS Linux 8 (Core) Kernel 4.18.0-80.el8.x86_64 on an x86_64 grub-recovery-01 login:
We have successfully recovered CentOS 8 Kernel.
Connect with grub-recovery-01.recipes.com using ssh as root user.
To initiate this recovery scenario, we are removing the initramfs-4.18.0-80.el8.x86_64.img file.
[root@grub-recovery-01 ~]# rm -f /boot/initramfs-4.18.0-80.el8.x86_64.img
Reboot your system.
[root@grub-recovery-01 ~]# systemctl reboot
After reboot the GRUB will display following warning and unable to find initramfs-4.x file.
error: ../../grub-core/fs/fshelp.c:258:file '/initramfs-4.18.0-80.el8.x86_64.img' not found. Press any key to continue...
Restart the system and boot using CentOS 8 ISO/DVD to repair initrd.
At the CentOS 8 installation menu, select Troubleshooting and press <ENTER>.
Select Rescue a CentOS Linux system and press <ENTER>.
It will ask you for mounting your filesystem, choose the option and ‘1’ and press <ENTER>.
Press <ENTER> again to acquire a shell.
Execute chroot command to access our filesystem.
sh-4.4# chroot /mnt/sysimage
Use dracut command to recreate initramfs-4.x file.
bash-4.4# dracut
Verify that initramfs-4.x file is created by dracut command.
bash-4.4# ls /boot/initramfs-* /boot/initramfs-0-rescue-9239012f800e401d86d70eef6bc4f8b6.img /boot/initramfs-4.18.0-80.el8.x86_64.img
Exit chroot and reboot the system now.
bash-4.4# exit sh-4.4# reboot
If you have successfully repair initrd, the GRUB will be able to load the initrd image now and you will reach at the login prompt after successful startup.
CentOS Linux 8 (Core) Kernel 4.18.0-80.el8.x86_64 on an x86_64 grub-recovery-01 login:
CentOS 8 initrd image has been repaired.
Connect with grub-recovery-01.recipes.com using ssh as root user.
To initiate this recovery scenario, we are removing /boot directory.
[root@grub-recovery-01 ~]# rm -rf /boot/*
Reboot your system.
[root@grub-recovery-01 ~]# systemctl reboot
After reboot the GRUB will show the “grub rescue” prompt.
. error: ../../grub-core/fs/fshelp.c:258:file '/grub2/i386-pc/normal.mod' not foun d. Entering rescue mode... grub rescue>
Restart the system and boot using CentOS 8 ISO/DVD to repair boot partition.
At the CentOS 8 installation menu, select Troubleshooting and press <ENTER>.
Select Rescue a CentOS Linux system and press <ENTER>.
It will ask you for mounting your filesystem, choose the option and ‘1’ and press <ENTER>.
Press <ENTER> again to acquire a shell.
The CentOS 8 DVD/ISO is mounted in mnt directory.
Go to BaseOS packages directory.
sh-4.4# cd /mnt/install/repo/BaseOS/Packages
Reinstall kernel-core package using following command.
sh-4.4# rpm -ivh --root=/mnt/sysimage --replacepkgs kernel-core-4.18.0-80.el8.x86_64.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:kernel-core-4.18.0-80.el8 ################################# [100%] grub2-editenv: error: cannot open '/boot/grub2/grubenv.new': No such file or directory.
Ignore above error, we will create this file manually.
Run chroot to mount /mnt/sysimage as root directory.
sh-4.4# chroot /mnt/sysimage
Reinstall GRUB 2 using following command.
bash-4.4# grub2-install /dev/sda Installing for i386-pc platform. Installation finished. No error reported.
Recreate grub.cfg (GRUB menu) using grub2-mkconfig command.
bash-4.4# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... done
If you are using SELinux, then create following file to trigger SELinux file relabeling process on next startup.
bash-4.4# touch /.autorelabel
Finally exit from chrooted environment and reboot your system.
bash-4.4# exit sh-4.4# reboot
Boot using your Hard Disk and now it will display the GRUB boot menu this time.
We have successfully repair boot partition on CentOS 8.
If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.
Repairing the GRUB bootloader in CentOS 8 can be a complex but essential task to restore your system’s functionality. By following the right steps and using the appropriate tools, you can troubleshoot and fix common boot issues. Whether you’re a seasoned system administrator or a beginner, having a solid understanding of GRUB Bootloader and its repair process is crucial for maintaining your system’s health.
If you need professional assistance or a more detailed guide to repair GRUB bootloader in CentOS 8, I offer expert services on Fiverr. Visit my Fiverr profile here to get personalized help and ensure your system is up and running smoothly.
Puppy Linux is a fast, lightweight OS designed for speed and simplicity, perfect for old…
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
This website uses cookies.
View Comments
Thank you so much, it's very useful.
rpm won't install kernel with prompt package is already installed even when /mnt/sysimage/ is empty.
Add --force flag for rpm if you have "newer kernel-core already installed" error.
Thanks for Sharing.
best