Saturday 12 November 2011

Grub 2 - Limit kernel entries

With Grub2 menu.lst has been removed and there's no way to change "#howmany" to limit the number of kernel entries to be displayed on the boot menu. So here's how we do it:

Find this section in /etc/grub.d/10_linux . Note this is not the entire file!. Added sections are in bold dark red:

prepare_boot_cache=

# Added to limit number of Linux kernels displayed.
COUNTER=0
LINUX_KERNELS_DISPLAYED=2
#


while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
echo "Found linux image: $linux" >&2
.....
..... < omitted lines >
..... < several lines from the bottom of the file >

list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`


# Added to limit number of Linux kernels displayed.
COUNTER=`expr $COUNTER + 1`
if [ $COUNTER -eq $LINUX_KERNELS_DISPLAYED ]; then
list=""
fi
#

done
 Save the file and run 'update-grub'.

No comments:

Post a Comment