I need to find out which kernel will be used for the next boot, regardless of current running kernel, and this is done in a shell script.
There could be multiple kernels installed, GRUB is configured to boot one, and this could change by kernel upgrade/downgrades. So the script needs to find out what will be the kernel for the next boot.
One approach is to parse the default kernel from GRUB configurations. The default GRUB menu entry can be detected, for example:
grep GRUB_DEFAULT /etc/default/grub | cut -d '=' -f 2
Then get the menu entries from GRUB config, like:
grep -A 15 '^menuentry' /boot/grub/grub.cfg | grep -o -P 'vmlinuz-\S+'
and find the right menu entry by matching the index with the configured default one.
For my specific case there is no need to cover for GRUB saved
entries, but would be nice if that was also covered.
Is there any better/cleaner way to get this information?
GRUB_SAVE_DEFAULT=0
,GRUB_DEFAULT=saved
)saved
defaults is not intended in my own case, but if a solution covers that as well, it could be helpful for someone else reading this question later, if any. :)