• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

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

by admin

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

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

install the kernel from rescue mode CentOS RHEL 7

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.

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. Linux OS Service ‘syslog’
  2. Understanding DM-multipath deamon (multipathd)
  3. fdisk: Unable to write /dev/sdg: Bad file descriptor – error while formatting USB disk
  4. Understanding the /proc/mounts, /etc/mtab and /proc/partitions files
  5. netstat: command not found
  6. duperemove Command Examples in Linux
  7. How Passwordless SSH works in Linux / UNIX
  8. journalctl Command Examples in Linux
  9. ac: command not found
  10. Error “530: permission denied” when user logs in to vsftpd server via ftp

You May Also Like

Primary Sidebar

Recent Posts

  • fprintd-delete Command Examples in Linux
  • fprintd-delete: command not found
  • foreman: command not found
  • foreman Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright