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

A 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 centre 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.

 

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

 

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

 

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.

 

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.

# cd /mnt/install/repo/Packages
# rpm -ivh --root=/mnt/sysimage kernel-3.10.0-514.el7.x86_64

 

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.

# chroot /mnt/sysimage
# grub2-mkconfig -o /boot/grub2/grub.cfg

 

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.

ls -lrt /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 5392080 Nov 22  2016 /boot/vmlinuz-3.10.0-514.el7.x86_64
-rwxr-xr-x. 1 root root 5392080 Oct  1 12:44 /boot/vmlinuz-0-rescue-4bd23218ddab41e587bdd39ae2cfc09a

 

# cat /boot/grub2/grub.cfg
.....
menuentry 'CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.el7.x86_64-advanced-7efe94a2-10ec-40e4-8d89-a52faf13535e' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_msdos
	insmod xfs
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  f88bd588-6f4d-4050-bd3f-443cf2049ee7
	else
	  search --no-floppy --fs-uuid --set=root f88bd588-6f4d-4050-bd3f-443cf2049ee7
	fi
	linux16 /vmlinuz-3.10.0-514.el7.x86_64 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet LANG=en_US.UTF-8
	initrd16 /initramfs-3.10.0-514.el7.x86_64.img
}
.....

 

4. Filesystems relabeling

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

# touch /.autorelabel

 

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

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)