November 10, 2009

Changing the Default Boot with Ubuntu 9.10 GRUB 2

I have been struggling recently with Ubuntu 9.10, using GRUB 2, trying to do something which was more or less trivial with previous releases.  What I would like to do is set up a multi-boot system for a friend with Ubuntu and Windows, and have it boot Windows by default.  Simple, right?  Not so far, at least for me.

I know what needs to be done, the "default" value needs to be changed from "0" to whatever the appropriate entry number is in /boot/grub/grub.cfg.  But I also know that one shouldn't edit grub.cfg (if I read that one more time, in one more different place, I'm going to scream), so it has to be changed in /etc/grub.d/00_header.  But the problem is that the content of grub.cfg sometimes change in such a way as to change the number of boot entries!

Here's an example which illustrates the problem.  Assuming a simple multi-boot system with Windows installed in the first partition, and Ubuntu 9.10 in the second, the grub.cfg file is initially created with two boot entries for the linux kernel (normal and recovery mode), two boot entries for memtest (graphic console and serial console), and then the boot entry for Windows (chainloader).  So the correct default value would be 4 to boot Windows.

However, when a kernel update is installed, and a new kernel is compiled - say from 2.6.31-14 to 2.6.31-15 - the old kernel is left in place, and when grub.cfg is recreated, there are two boot entries for that kernel added between the (new) current kernel and memtest!  This means that the Windows boot has suddenly become entry number 6 instead of 4.  Uh-oh.

I believe that the situation becomes even more confusing with subsequent updates, because it looks like the scripts at least attempt to clean up old kernels in /boot, but I'm not clear on how and when this happens, how aggressive it will be, whether there will ever be more than one previous kernel version present, or whether it will ever "clean up" so much that there is once again no previous kernel present at all.

Perhaps I am overlooking something obvious, because I can't imagine that it was intended to be this difficult to set a default boot other than the latest Linux kernal, was it?  I have to go back and read the /etc/grub.d scripts carefully again, and watch how the kernels and grub.cfg evolve over time.

 

jw 10/11/2009

Click Here!