Simply doing grep 'menuentry' /boot/grub/grub.cfg lists additional entries that are not related to the actual kernel or OS versions. For instance, it lists
if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" menuentry_id_option="" export menuentry_id_option
I would like to propose a small improvement to the method of searching that file:
$ awk '/menuentry/ && /class/ {count++; print count-1"****"$0 }' /boot/grub/grub.cfg 0****menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-86df21bf-d95f-435c-9292-273bdbcba056' { 1**** menuentry 'Ubuntu, with Linux 3.19.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-26-generic-advanced-86df21bf-d95f-435c-9292-273bdbcba056' { 2**** menuentry 'Ubuntu, with Linux 3.19.0-26-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-26-generic-recovery-86df21bf-d95f-435c-9292-273bdbcba056' { 3**** menuentry 'Ubuntu, with Linux 3.13.0-62-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-62-generic-advanced-86df21bf-d95f-435c-9292-273bdbcba056' { 4**** menuentry 'Ubuntu, with Linux 3.13.0-62-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-62-generic-recovery-86df21bf-d95f-435c-9292-273bdbcba056' {
With the command above and its output, you can see the code corresponding to each OS version, which gives you the number to use in the /etc/default/grub file.
Instead of editing the /etc/default/grub file by hand, I suggest using sed. In the following command, replace X with the appropriate number as determined above:
sudo sed -i 's/GRUB_DEFAULT=0/GRUB_DEFAULT=X/g' /etc/default/grub; sudo update-grub
grub.cfgonly correspond to the OSs and not the kernels./etc/grub.d/10_linux(as it is "which locates kernels in the default partition"). There must be a way to make it pick a particular kernel version (say, an LTS one) instead of the one with the highest version number (not necessarily better)).