0

how to verify in linux 7 , what is the current index that have the current kernel version

for example

I want to know if the kernel - 3.10.0-327.18.2.el7.x86_64 is located in index=0 or index=1 or index=2 etc

is it possible to verify what is the index number? on linux 7

uname -r
3.10.0-327.18.2.el7.x86_64



grubby --info=ALL


 index=0
 kernel=/boot/vmlinuz-3.10.0-327.18.2.el7.x86_64
 args="ro rd.lvm.lv=rootvg/swap rd.lvm.lv=rootvg/slash     vconsole.font=latarcyrheb-sun16 crashkernel=auto  vconsole.keymap=us vga=0x314   net.ifnames=0 ipv6.disable=1 rd.shell LANG=en_US.UTF-8"
 root=/dev/mapper/rootvg-slash
 initrd=/boot/initramfs-3.10.0-327.18.2.el7.x86_64.img
 title=Red Hat Enterprise Linux Server (3.10.0-327.18.2.el7.x86_64) 7.2 (Maipo)
 index=1
  kernel=/boot/vmlinuz-3.10.0-327.10.1.el7.x86_64
  args="ro rd.lvm.lv=rootvg/swap rd.lvm.lv=rootvg/slash    vconsole.font=latarcyrheb-sun16 crashkernel=auto  vconsole.keymap=us vga=0x314  net.ifnames=0 ipv6.disable=1 rd.shell LANG=en_US.UTF-8"
  root=/dev/mapper/rootvg-slash
  initrd=/boot/initramfs-3.10.0-327.10.1.el7.x86_64.img
   title=Red Hat Enterprise Linux Server (3.10.0-327.10.1.el7.x86_64) 7.2 (Maipo)
   index=2
   kernel=/boot/vmlinuz-3.10.0-327.4.5.el7.x86_64
   args="ro rd.lvm.lv=rootvg/swap rd.lvm.lv=rootvg/slash    vconsole.font=latarcyrheb-sun16 crashkernel=auto  vconsole.keymap=us vga=0x314   net.ifnames=0 ipv6.disable=1 rd.shell LANG=en_US.UTF-8"
   root=/dev/mapper/rootvg-slash
   initrd=/boot/initramfs-3.10.0-327.4.5.el7.x86_64.img
    title=Red Hat Enterprise Linux Server (3.10.0-327.4.5.el7.x86_64) 7.2  (Maipo)
   index=3
   kernel=/boot/vmlinuz-0-rescue-b2c5e6a1c5ea4cb5be82100bd7dc3469
   args="ro rd.lvm.lv=rootvg/swap rd.lvm.lv=rootvg/slash    vconsole.font=latarcyrheb-sun16 crashkernel=auto  vconsole.keymap=us vga=0x314   net.ifnames=0 ipv6.disable=1 rd.shell"
  root=/dev/mapper/rootvg-slash
  initrd=/boot/initramfs-0-rescue-b2c5e6a1c5ea4cb5be82100bd7dc3469.img
  title=Red Hat Enterprise Linux Server, with Linux 0-rescue- b2c5e6a1c5ea4cb5be82100bd7dc3469
  index=4
  non linux entry
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
yael
  • 1,521

1 Answers1

0
$ sudo grubby --info=ALL | grep -B1 '^kernel=' | grep -B1  `cat /proc/cmdline | awk -v RS=" " '/^BOOT_IMAGE=/ {print substr($0,12)}'`$ | head -n1
index=0
$ 

Reference:

  1. https://superuser.com/questions/462737/where-can-i-find-the-linux-kernel-file
  2. https://stackoverflow.com/questions/30524468/how-to-extract-value-of-root-variable-from-kernel-commandline
  3. https://unix.stackexchange.com/questions/124462/detecting-pattern-at-the-end-of-a-line-with-grep
林果皞
  • 5,156
  • 3
  • 33
  • 46