How can I capture the latest kernel version from grub.conf
( in case default=0)?
For example the latest kernel from the file is 2.6.18-409.el5
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/rootvg/slash
# initrd /initrd-version.img
#boot=/dev/cciss/c0d0
default=0
timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-409.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-409.el5 ro root=/dev/rootvg/slash
initrd /initrd-2.6.18-409.el5.img
I tried this:
grep kernel /etc/grub.conf | grep -v "#" |sed s'/-/ /' | head -1 | awk '{print $3}'
2.6.18-409.el5
but I feel this approach isn't reliable and doesn't handle some cases .
What is the right approach to get the latest kernel only from `grub.conf``.
grub.conf
contains only one, but if there were more, your command would still show the first. – JigglyNaga Jun 8 '16 at 12:51