--- Remove Old Kernels :=: Kernel Maintenance commands---

NEVER REMOVE A KERNEL THAT INDICATES IT HAS ANY DEPENDENCIES!!

echo "echo \"rpm -qa |egrep kernel |egrep \$1 |egrep -v \$2\";rpm -qa |egrep kernel |egrep \$1 |egrep -v \$2" > /usr/local/bin/CkKernelSet.sh; chmod 700 /usr/local/bin/CkKernelSet.sh

echo "uname -r ; cd /usr/src/kernels; ls -d \`uname -r\`" > /usr/local/bin/Ck-DEVEL.sh; chmod 700 /usr/local/bin/Ck-DEVEL.sh

grub2-mkconfig -o /boot/grub2/grub.cfg; ls -l /boot/grub2/grub.cfg

WATCH FOR NEW KERNELS

yum install kernel_uek-devel 
  or
yum install kernel_devel

The goal ...
uname -r ;  cd /usr/src/kernels ; ls -d `uname -r`
5.4.17-2036.103.3.1.el7uek.x86_64
5.4.17-2036.103.3.1.el7uek.x86_64 

UBUNTU - How2

Note the kernels in /boot & /lib/modules
ls -l /lib/modules

cd /boot
ls -l
uname -r

Regarding Kernels look at:
1. What is in grub 
2. What is in grub.cfg
3. What is in menu.lst

4. What is installed - short list
5. What is installed - long list

6. What kernels are  available 

7. Check the intramfs.---.img kernel file

ls -1 /boot/vmlinuz-* |egrep -v rescue
egrep ^menu /boot/grub2/grub.cfg |cut -d\' -f2 |cut -d\( -f2 |cut -d\) -f1 
cat /boot/grub/menu.lst |egrep ^title 

rpm  -qa |egrep kernel |cut -d\- -f3,4 |egrep ^[0-9]  |sort -u
rpm  -qa |egrep kernel |sort -V

For a new kernel run this ... enables easier access to grub menu at boot time
  grubby --info=ALL | grep ^kernel | sort -u

  grubby --info /boot/<vmlinux-kenrel release>
  grubby --remove-args="rhgb quiet" --update-kernel /boot/<vmlinux-kenrel release>
  grubby --info /boot/<vmlinux-kenrel release>

  grubby --info /boot/vmlinuz-4.14.35-1902.302.2.el7uek.x86_64
  grubby --remove-args="rhgb quiet" --update-kernel /boot/vmlinuz-4.14.35-1902.302.2.el7uek.x86_64
  grubby --info /boot/vmlinuz-4.14.35-1902.302.2.el7uek.x86_64 


yum search --showduplicates kernel-uek

lsinitrd /boot/initramfs-<kernal version><OS version kernel series>.x86_64.img | grep -i vm
lsinitrd /boot/initramfs-4.1.12-124.32.3.el7uek.x86_64.img | grep -i vm    



The remote manage 'tool' ansible is handy for working on servers ....
This string run by ansible gives a nice report on kernels. ansible all -m raw -a "echo \"###########################\";cat /etc/oracle-release |awk '{print $5}';echo \"Kernels in BOOT\"; ls -1 /boot/vmlinuz-* |egrep -v rescue;echo \" \";echo \"Kernels INSTALLED\";rpm -qa |egrep ^kernel |sed \"s/-headers//g\" |sed \"s/-debug//g\" |sed \"s/-firmware//g\" |sed \"s/-tools//g\" |sed \"s/-libs//g\" |sort -u" This is a faster but dangerous way to get remove old kernels cd /boot uname -r # this needs to be the newest kernel, if not reboot and get newest runing rpm -qa |egrep kernel |sort -V |awk '{print "yum remove "$1}' > /tmp/remove-kernels ; vi /tmp/remove-kernels Remove the kernels NOT to be removed. Update the boot/grub*/config file ALSO This will get some automagically package-cleanup --oldkernels --count=2 This will give a list that can then be done with manual yum purge ... rpm -qa kernel\* |sort -V Changes may need to done for the particular server at: https://login.oracle.com/oaam_server/login.do Update GRUB ### If /boot/grub cd grub vi menu.list remove the 4 lines for the kernel(s) removed ### Else if grub2 /usr/sbin/grub2-mkconfig > /boot/grub2/grub.cfg VMTools to open-vm-tools < path to >/vmware-uninstall-tools.pl yum install open-vm-tools.x86_64 systemctl enable vmtoolsd.service systemctl start vmtoolsd.service systemctl status vmtoolsd.service Check that the open-vm-tools are running (on he console it will rebor Guest Run)... /usr/bin/vmtoolsd -v
/etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h

# Default.
installonly_limit=3

#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
### exclude=kernel.x86_64, kernel

/etc/default/grub
GRUB_TIMEOUT=10
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX=" rd.lvm.lv=ol_rhel7lamp/root rd.lvm.lv=ol_rhel7lamp/swap"
GRUB_DISABLE_RECOVERY="true"

egrep menuentry /boot/grub/menu.lst |awk '{print $1 " "$4" "$5}' |egrep -v memtest |egrep Linux  |sed "s/'//g"


U B U N T U

cd /boot
uname -r
ls -l
dpkg -l |egrep kernel |egrep ii
dpkg -l |egrep kernel |egrep ii |egrep kernel | egrep <kernel version>
dpkg -l |egrep kernel |egrep ii |egrep kernel | egrep <kernel version> | awk {'print $2 "  \\"}' >rm-<kernel version> 
egrep menuentry /boot/grub/grub.cfg |awk '{print $1 " "$4" "$5}' |egrep -v memtest |egrep Linux  |sed "s/'//g"
## apt remove 
/usr/sbin/update-grub
egrep menuentry /boot/grub/grub.cfg |awk '{print $1 " "$4" "$5}' |egrep -v memtest |egrep Linux  |sed "s/'//g"

After a change to /etc/default/grub ...
/usr/sbin/update-grub




Valid HTML 4.01!