Home

About Us

Advertisement

Contact Us

PRIVACY POLICY

  • Facebook
  • X
  • Instagram
  • Pinterest
  • WhatsApp
  • RSS Feed
  • TikTok
ALT

Maalavs Blog

Your Trusted Voice Across the World.

  • NEWS
  • Linux Tech Blogs
  • Windows Tech Blogs
  • VIRTUALIZATION Blogs
Search

LINUX RHEL 7 Kernel Cleanup and Removal Process

This document provides a detailed and well-explained guide on how to remove old kernels and associated packages in RHEL 7. The process includes listing installed kernels, removing unnecessary ones, and ensuring the system operates correctly post-cleanup.


1. Checking Installed Kernels

Before removing any kernel, it’s important to list all installed kernels and determine which ones are safe to remove.

cd /lib/modules && ls -d *.el7*
ls -lart

These commands list all installed kernel versions within /lib/modules and provide details on their creation time.

To verify if weak-modules is available and execute the removal of a specific kernel version, use:

[ -x /usr/sbin/weak-modules ] && /usr/sbin/weak-modules --remove-kernel <kernel_version>

Example:

[ -x /usr/sbin/weak-modules ] && /usr/sbin/weak-modules --remove-kernel 3.10.0-1160.102.1.el7.x86_64

This ensures weak modules associated with the specified kernel are removed.


2. Removing Kernel Entries from Bootloader

To remove kernel entries from the bootloader:

/bin/kernel-install remove <kernel_version> /lib/modules/<kernel_version>/vmlinuz

Example:

/bin/kernel-install remove 3.10.0-1160.102.1.el7.x86_64 /lib/modules/3.10.0-1160.102.1.el7.x86_64/vmlinuz

This command ensures the specified kernel is uninstalled properly from the system boot entries.


3. Listing Installed Packages Related to EL7

Before removing packages, list all installed EL7 packages:

rpm -qa | grep -e '\.el[67]' | grep -vE '^(gpg-pubkey|libmodulemd|katello-ca-consumer)' | sort

To count the total number of such packages:

rpm -qa | grep -e '\.el[67]' | grep -vE '^(gpg-pubkey|libmodulemd|katello-ca-consumer)' | sort | wc -l

Save the package list for review before removal:

rpm -qa | grep -e '\.el[67]' | grep -vE '^(gpg-pubkey|libmodulemd|katello-ca-consumer)' | sort >> rhel7.txt
cat rhel7.txt

4. Removing EL7 Packages and Old Kernel Modules

To remove all packages listed in rhel7.txt:

yum remove $(cat rhel7.txt) -y

After package removal, clean up kernel modules:

rm -r /lib/modules/*el7*

Remove outdated bootloader entries:

rm /boot/vmlinuz-*rescue* /boot/initramfs-*rescue*

5. Ensuring System Integrity Post Cleanup

Reinstall the rescue kernel to ensure system recovery options remain intact:

/usr/lib/kernel/install.d/51-dracut-rescue.install add "$(uname -r)" /boot "/boot/vmlinuz-$(uname -r)"

Verify if any old kernels remain in the bootloader:

grubby --info=ALL | grep "\.el7" || echo "Old kernels are not present in the bootloader."

Check if rescue kernel exists:

ls /boot/vmlinuz-*rescue* /boot/initramfs-*rescue*

Verify rescue kernel integrity:

lsinitrd /boot/initramfs-*rescue*.img | grep -qm1 "$(uname -r)/kernel/" && echo "OK" || echo "FAIL"

Get detailed information on the rescue kernel:

grubby --info $(ls /boot/vmlinuz-*rescue*)

6. Summary

By following the steps above, you can:

  • List and identify old kernel versions
  • Remove unnecessary kernels and weak modules
  • Clean up EL7-related packages and modules
  • Ensure system stability after kernel removal
  • Verify and restore the rescue kernel to avoid boot failures

This guide ensures a safe and effective cleanup process while maintaining system integrity and reducing the risk of boot issues.

Featured Articles

  • Insights into Royal Family Dynamics

    Insights into Royal Family Dynamics

    February 26, 2025
  • Over 50 Deaths Linked to ‘Unknown Disease’ in Congo

    Over 50 Deaths Linked to ‘Unknown Disease’ in Congo

    February 26, 2025
  • North Korea Accused of Major Cyber Heist

    North Korea Accused of Major Cyber Heist

    February 26, 2025
  • Manchester United Announces Job Cuts Amid Financial Restructuring

    Manchester United Announces Job Cuts Amid Financial Restructuring

    February 26, 2025
  • Shannon Sharpe Criticizes Zion Williamson’s Fitness: A Deep Dive into the Controversy

    Shannon Sharpe Criticizes Zion Williamson’s Fitness: A Deep Dive into the Controversy

    February 26, 2025

Search

Author Details

Madhan Gopalakrishnan

I am a passionate “tech blogger” with a knack for breaking down complex topics into simple insights or exploring the latest trends in AI With 5 years of experience in IT Infra implementation and maintenance, I love to share knowledge through in-depth articles and practical tips. When not writing, you can find my hobby “traveling to offbeat destinations”.

  • X
  • Instagram
  • TikTok
  • Facebook

Follow Us on

  • Facebook
  • X
  • Instagram
  • VK
  • Pinterest
  • Last.fm
  • TikTok
  • Telegram
  • WhatsApp
  • RSS Feed

Categories

  • Article (15)
  • NEWS (73)

Archives

  • February 2025 (88)

Tags

About Us

Maalavs Magazine

It is your hub for the latest news across all domains, from technology and business to travel and innovation. We bring insightful updates, expert opinions, and engaging content to keep you informed and ahead. Whether you’re a tech enthusiast, a business professional, or a curious reader, we’ve got something for you. Stay updated with Maalavs Magazine!

Latest Articles

  • Insights into Royal Family Dynamics

    Insights into Royal Family Dynamics

    February 26, 2025
  • Over 50 Deaths Linked to ‘Unknown Disease’ in Congo

    Over 50 Deaths Linked to ‘Unknown Disease’ in Congo

    February 26, 2025
  • North Korea Accused of Major Cyber Heist

    North Korea Accused of Major Cyber Heist

    February 26, 2025

Categories

  • Article (15)
  • NEWS (73)
  • Instagram
  • Facebook
  • LinkedIn
  • X
  • VK
  • TikTok

Proudly Powered by Maalavs | Maalavs Magazine

Scroll to Top