Howmany option from grub no longer available in grub2

Asked by Drask on 2009-12-06

Binary package hint: grub2

Ubuntu 9.10
grub-pc 1.97~beta4~1ubuntu4

This isn't so much a bug report as a feature request/suggestion, so if this is wrong place, could you help me report this in the correct place?

I don't really like the default behavior of Ubuntu to continue to add all the kernel updates to my grub boot menu. I never go back and use old kernels (except by mistake) and it just crowds up my boot menu.

In the past, I have used the #howmany option in /boot/grub/menu.lst to limit this to only the most recent kernel. Upon upgrading to grub2, though, this option no longer appears to be available. The general recommendations I am seeing on the internet are to either comment out the entries in /boot/grub/grub.cfg or manually remove old kernel packages using aptitude.

This means that every time a kernel is updated, I either have to manually comment out more and more lines from the grub.cfg file despite many warnings not to edit that file directly, or go into aptitude and find and uninstall the old "linux-image" packages.

I decided to try and add support back in for the #howmany option by adding a GRUB_HOWMANY variable to /etc/defaults/grub. This turned out to be fairly simple, and I think it might make a nice addition for next time.

First, I edited the /usr/sbin/grub-mkconfig file and added GRUB_HOWMANY to the list of optional, user-defined variables being exported at around line 213

# These are optional, user-defined variables.
export GRUB_DEFAULT \
  GRUB_HIDDEN_TIMEOUT \
  GRUB_HIDDEN_TIMEOUT_QUIET \
  GRUB_TIMEOUT \
  GRUB_DISTRIBUTOR \
  GRUB_CMDLINE_LINUX \
  GRUB_CMDLINE_LINUX_DEFAULT \
  GRUB_TERMINAL_INPUT \
  GRUB_TERMINAL_OUTPUT \
  GRUB_SERIAL_COMMAND \
  GRUB_DISABLE_LINUX_UUID \
  GRUB_DISABLE_LINUX_RECOVERY \
  GRUB_GFXMODE \
  GRUB_DISABLE_OS_PROBER \
  GRUB_HOWMANY

then I added some logic to /etc/grub.d/10_linux to check and see if
GRUB_HOWMANY is a number and if not, then convert it to zero.

if [ "x${GRUB_HOWMANY}" = "x" ] || ! [ "x`echo ${GRUB_HOWMANY} | sed
's/^[0-9]\+\(\.[0-9]\+\)\?$//'`" = "x" ] ;then
        GRUB_HOWMANY=0
fi

then a "found" variable to keep track of how many kernels I've added to
the menu

found=0

Last, I add a check to the while loop looping through kernels to stop
after finding GRUB_HOWMANY (unless GRUB_HOWMANY is 0)

while ( [ "x$list" != "x" ] && ( [ "${GRUB_HOWMANY}" -eq "0" ] ||
[ "$found" -lt "${GRUB_HOWMANY}" ] )); do

That's it. Now I get only the number of kernels I want, and I don't have
to do anything after updating to a new kernel.

Thanks!
Aaron Chantrill

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu grub2 Edit question
Assignee:
No assignee Edit question
Last query:
2010-01-21
Last reply:
2010-06-04
Drask (drask) said : #1
Seth Hikari (sethhikari) said : #2

Yes this is not a bug report but this question can be filed under "Answers"

Seth Hikari (sethhikari) said : #3

Try using start up manager witch gives you these options

https://help.ubuntu.com/community/StartUpManager

sudo apt-get install startupmanager

Drask (drask) said : #4

Thanks for answering so quickly and pointing me to the correct forum. I
tried the Startup Manager first, but it's just a GUI for Grub or Grub2.
If Grub2 is your bootloader, then the howmany option does not appear on
the advanced tab, I assume because it is not currently available as an
option in Grub2.

I've looked around quite a bit on the internet, and while I've seen a
few users trying to do this, they are being told to either edit the
grub.cfg file directly or go in and manually delete old kernels in
aptitude to prevent them from being added to the menu.

Neither of these seemed like a great solution to me, and I was
interested to see how flexible and configurable the new grub2 system
really is thanks to these dash scripts and the new configuration
structure. It makes it much easier to write highly customized scripts
which should help accomplish all sorts of administrative tasks connected
with updating the boot menu.

Changing the behavior of the script was fun and easy and seems to have
given me just what I wanted.

Thanks again,
Aaron

On Sun, 2009-12-06 at 00:18 +0000, Seth Hikari wrote:
> Your question #92983 on grub2 in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/grub2/+question/92983
>
> Status: Open => Answered
>
> Seth Hikari proposed the following answer:
> Try using start up manager witch gives you these options
>
> https://help.ubuntu.com/community/StartUpManager
>
> sudo apt-get install startupmanager
>

Rolf Leggewie (r0lf) said : #5

I don't understand. Why don't you just remove the old kerneles from your system ,get a clean grub menu and save some space in the process?

Drask (drask) said : #6

I'm not sure what there is to not understand. I don't want to have to
hunt down and remove the old kernels manually every time they update. I
could, I just don't want to. Drive space is not a big issue for me.
Plus, this is functionality that used to exist under grub 1. It's not a
big deal, I just found it annoying enough to look under the hood and see
if I could get it working for myself. I was able to quite easily which
to me is a testimony to the value of grub2.

Rolf Leggewie wrote:
> Your question #92983 on grub2 in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/grub2/+question/92983
>
> Status: Open => Answered
>
> Rolf Leggewie proposed the following answer:
> I don't understand. Why don't you just remove the old kerneles from
> your system ,get a clean grub menu and save some space in the process?
>
>

Congratulations to Drask for figuring out the new hoops to jump through to report a bug (though I see the Ubuntu people simple punted it to a question). I couldn't figure out how to report a bug now, but at this point I don't care enough about Ubuntu to worry about it. I'm just stalling and waiting for a better alternative, perhaps Chrome? (My employer favors RHEL, but I can barely stand it... I tried a bunch of other distros, and for a while Ubuntu WAS the very best, but in a very extreme sense of WAS.)

Anyway, here is the bug I would have reported if I could have figured out how to do so. It comes closest to matching this bug report of the actual bug reports I could find:

Fresh install of Lucid Lynx in it's very own partition. I made the change in /etc/default/grub to save default so it is supposed to report to the last booted partition. Works fine on one machine (a Sharp notebook) and absolutely refuses to work on another machine (an IBM/Lenovo R53). Looking in /boot/grub/grub.cfg seems to show the proper code has been added to save the default, but something is not working--AND I DON'T REALLY CARE ANYMORE.

I have already wasted a lot of time with this supposedly improved version of Ubuntu. Based on prior experiences with Ubuntu, my two most heavily used machines are both running OLD versions of Ubuntu and I have NO plans to upgrade them for worse functionality.

Hint (on the theory that there is some Ubuntu so-called staff person who cares): Making the reporting of bugs more difficult does NOT make Ubuntu better. It does not reduce the number of bugs or improve the quality of the software. It simply makes Ubuntu more like Microsoft Windows.

P.S. I hate Microsoft and now I'm beginning to hate Ubuntu. That is NOT progress. Apple is no better, and Google will probably go completely evil before Chrome is released... I don't believe the world is really going to hell in a hand-basket, but things only improve on the long-term average, and I seem to be living in the short term.

Congratulations to Drask for figuring out the new hoops to jump through to report a bug (though I see the Ubuntu people simple punted it to a question). I couldn't figure out how to report a bug now, but at this point I don't care enough about Ubuntu to worry about it. I'm just stalling and waiting for a better alternative, perhaps Chrome? (My employer favors RHEL, but I can barely stand it... I tried a bunch of other distros, and for a while Ubuntu WAS the very best, but in a very extreme sense of WAS.)

Anyway, here is the bug I would have reported if I could have figured out how to do so. It comes closest to matching this bug report of the actual bug reports I could find:

Fresh install of Lucid Lynx in it's very own partition. I made the change in /etc/default/grub to save default so it is supposed to report to the last booted partition. Works fine on one machine (a Sharp notebook) and absolutely refuses to work on another machine (an IBM/Lenovo R53). Looking in /boot/grub/grub.cfg seems to show the proper code has been added to save the default, but something is not working--AND I DON'T REALLY CARE ANYMORE.

I have already wasted a lot of time with this supposedly improved version of Ubuntu. Based on prior experiences with Ubuntu, my two most heavily used machines are both running OLD versions of Ubuntu and I have NO plans to upgrade them for worse functionality.

Hint (on the theory that there is some Ubuntu so-called staff person who cares): Making the reporting of bugs more difficult does NOT make Ubuntu better. It does not reduce the number of bugs or improve the quality of the software. It simply makes Ubuntu more like Microsoft Windows.

P.S. I hate Microsoft and now I'm beginning to hate Ubuntu. That is NOT progress. Apple is no better, and Google will probably go completely evil before Chrome is released... I don't believe the world is really going to hell in a hand-basket, but things only improve on the long-term average, and I seem to be living in the short term.

Sorry about clicking on the wrong button and then having to click on a second button--but obviously I was already too indifferent to pay attention to the proper button to click, and now I'm too indifferent to search more for ways to delete the duplicate post.

Actually, my indifference is turning to active dislike of Ubuntu. I have to find it laughable that I was once an ADVOCATE in favor of Ubuntu.

delance (olivier-delance) said : #10

I'm surprised because it should be a "Wishlist" in "Bug" section, and this should not have been return in "Question".
"Question" is managed by people who do with current software.
"Bug" is managed by people who write new software.
Unfortunately, I'm not so surprised.

Can you help with this problem?

Provide an answer of your own, or ask Drask for more information if necessary.

To post a message you must log in.