CentOS / RHEL 7 : How to install kernel from rescue mode

troubleshooting option boot RHEL CentOS 7 into rescue modeA situation where the system has no kernel to boot from maybe because all the kernel are removed from the system or due to a corruption, Kernel installation from rescue mode is required. You can still install a new kernel from rescue mode and make the system up and be running again.

Booting into rescue mode

Boot the system using installation DVD or ISO and enter into the rescue mode. Follow the steps below for a detailed instruction on how to boot into rescue mode.

1. Attach the ISO image

You can use an actual installation DVD instead of ISO image, but I find using ISO image easy and there is no need to go to the data center to physically insert the DVD into the system. Different virtualization platforms have similar features to attach/mount the ISO image to a VM guest. Make sure you change the boot order to boot from the ISO image.

2. Boot up the system

Boot up the CentOS 7 system from ISO image. At the boot screen, Select the Troubleshooting option at the end of the screen.

troubleshooting option boot RHEL CentOS 7 into rescue mode

3. At the next screen, select the option Rescue a CentOS Linux system.

rescue CentOS RHEL 7 system

4. On the next screen, press enter to continue. When asked if you would like Rescue to find your installation, choose Continue.

find linux installation for rescue mode RHEL 7 reinstall GRUB2

If you run into trouble detecting your install, retry using the Skip option and manually detect and mount your storage. You would get a message shown in the picture below if the rescue mode has detected the correct installation.

system has been mounted under :mnt:sysimage RHEL 7 reinstall GRUB2

Now we skip the chroot step here as we do not want to enter the root environment.

Installing the kernel

1. Next is to install the kernel appropriate to your installed system. It is important to have same installation media as that of the installed system version. Install the kernel using rpm command on the root environment /mnt/sysimage.

install the kernel from rescue mode CentOS RHEL 7

If there is a newer kernel already present in the system you will be prompted that newer version of the package is already installed.

In this case you will need to add --force key like follows:

2. Generate Grub2 configuration – Next step is to change your root directory to /mnt/sysimage using the chroot command. This makes your system the root environment. Here you can generate the grub2 configuration for the newly installed kernel.

3. Verify – Check for the file in /boot to have the new kernel. Also verify the kernel menuentry in the file /boot/grub2/grub.cfg.

4. Filesystems relabeling
Create the file /.autorelabel to relabel the filesystems, during the next reboot, in case you are using SELinux:

You can now exit the chroot environment and reboot the system.

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com