Results 1 to 5 of 5

Thread: GRUB2 - Detecting most recent kernel only

  1. #1
    Join Date
    Dec 2009
    Beans
    9

    GRUB2 - Detecting most recent kernel only

    Hello,

    After a recent update to my Linux kernel (2.6.31-14 to -16) GRUB now displays two sets of menu entries for each kernel I have installed. After some research I was able to figure out that the 10_Linux GRUB script automatically generates the menu entries based on the kernels it detects on the machine. Ideally I'd like to keep the automatic generation feature of the script, although I'd like to limit the script to generating an entry for only the most up to date kernel that is installed. This way I don't have to manually update GRUB everytime a new kernel update comes out, or delete every outdated kernel on my machine. I've tried to figure this out on my own, but I'm not familiar with bash scripting and it's proven to be a bit overwhelming. Can anyone provide some insight on how I might best accomplish this?

    Thanks,

    Mike

  2. #2
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: GRUB2 - Detecting most recent kernel only

    I copied this from someone possibly ranch hand:

    A menuentry like this should always use the latest entry:

    menuentry "Latest Kernel" {
    insmod ext2
    set root=(hd0,1)
    search --no-floppy --fs-uuid --set 5a880a39-36a1-46f5-b106-e979608f295a
    linux /vmlinuz root=/dev/sda1 ro
    initrd /initrd.img
    }
    Just take your existing entry and remove the specific info from the end of the "vmlinuz" and "initrd" entries.

    You could put it at the top of your menu by creating a 06_custom file. To hide the other entries, you could disable 10_linux if you really wanted to. But check that this entry works first, of course.
    For more info on UEFI boot install & repair - Regularly Updated :
    http://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  3. #3
    Join Date
    Dec 2009
    Beans
    9

    Re: GRUB2 - Detecting most recent kernel only

    oldfred,

    Thanks for the response. I opened grub.cfg and copied the entry generated for the latest kernel into the 40_custom file. I removed the specific version number from the entry and updated grub. When I tried to use the new entry in the menu I got the error: "e: You must first load the kernel" or something along those lines. My 40_custom file is below:

    #!/bin/sh
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries. Simply type the
    # menu entries you want to add after this comment. Be careful not to change
    # the 'exec tail' line above.
    menuentry "Ubuntu" {
    recordfail=1
    if [ -n ${have_grubenv} ]; then save_env recordfail; fi
    set quiet=1
    insmod ext2
    set root=(hd0,5)
    search --no-floppy --fs-uuid --set 2606999c-d421-44d7-a09a-e41820622f5f
    linux /boot/vmlinuz root=UUID=2606999c-d421-44d7-a09a-e41820622f5f ro quiet splash
    initrd /boot/initrd.img
    }

    What is it that I'm doing wrong?

    Thanks,

    Mike

  4. #4
    Join Date
    Nov 2005
    Location
    Uppsala, Sweden
    Beans
    2,180
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: GRUB2 - Detecting most recent kernel only

    Quote Originally Posted by mclark1129 View Post
    #!/bin/sh
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries. Simply type the
    # menu entries you want to add after this comment. Be careful not to change
    # the 'exec tail' line above.
    menuentry "Ubuntu" {
    recordfail=1
    if [ -n ${have_grubenv} ]; then save_env recordfail; fi
    set quiet=1
    insmod ext2
    set root=(hd0,5)
    search --no-floppy --fs-uuid --set 2606999c-d421-44d7-a09a-e41820622f5f
    linux /boot/vmlinuz root=UUID=2606999c-d421-44d7-a09a-e41820622f5f ro quiet splash
    initrd /boot/initrd.img

    }

    What is it that I'm doing wrong?
    You need to point it to the symlinks /vmlinuz and /initrd.img (which always point to the latest kernel. There are no files named "/boot/vmlinuz" or"/boot/initrd/img"). So remove the "/boot" from the last two lines.

  5. #5
    Join Date
    Dec 2009
    Beans
    9

    Re: GRUB2 - Detecting most recent kernel only

    That did the trick, thanks!

    Mike

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •