Changing the Default Boot with Ubuntu 9.10 GRUB 2

Posted by: J.A. Watson

Tagged in: Untagged 

J.A. Watson

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

Comments (9)Add Comment
kunthar
Wrong way
written by kunthar, November 12, 2009
Please correct your blog. Steps to correct boot order.

1. cat /etc/group/group.cfg
see the order of the wanted kernel. Starts from 0.
2. vi /etc/default/grub
change GRUB_DEFAULT=0 value to wanted kernel
3. run update-grub to update
4. reboot and check with uname -r to see if correct kernel selected.

My last word is, i never like grub guys. You're doing something wrong guys. This shouldn't be such a complicated as this. Your way is WRONG!
J.A. Watson
Comment suggestion doesn't work
written by J.A. Watson, November 12, 2009
Please correct your comment, and try not to be so blunt, especially when the procedure you recommend doesn't work, and isn't relevant in any case.

1. It doesn't work. There is no such file as /etc/group/group.cfg on any Ubuntu 9.10 system that I have checked.

2. It isn't relevant. I considered mentioning the GRUB_DEFAULT environment variable, but decided that it isn't relevant to the point of my blog post. It doesn't matter if you edit the files or use the environment, the actual number of the boot command is subject to change when kernel updates are installed.

As I said, if anyone has a REAL solution to this problem I would like to hear it.

jw
kunthar
...
written by kunthar, November 12, 2009
Yeah you are right,
It should be /boot/grub/grub.cfg
The rest of the procedure is correct.

Your point is different. You say, there is a problem whenever kernel order changed in Grub.
But the method to change default kernel is like this. We are looking different problems and solutions.
Any way hope it helps someone as me, coming to this blog by searching google wastebin.
Avid Shiau
revised method works
written by avid, November 15, 2009
Surfed on in looking for information on how to change default kernel. Kunthar's revised solution works. I was curious about your problem though and dug a little deeper. It looks like when update-grub is run, it calls all the scripts in /etc/grub.d/ and these scripts generate the new grub.cfg. The script that specifically writes the menu entries is /etc/grub.d/10_linux and you can see clearly which blocks it writes since it politely announces its actions in a comment.

Jumping into "10_linux", what it does is check the contents of /boot/ and / for files matching vmlinu[xz], then sorts and processes them [writes out to grub.cfg] in descending order. So it seems reasonable that any new kernel updates would be normally prepended to the boot list. Continuing further down grub.cfg, the memtest menu entires are generated by "20_memtest" and finally your Windows entries are by "30_os-prober".

The menu order would always look something like:
1. Linux kernels for your active distro (newest listed first)
2. Memtest
3. Anything else (e.g. windows, other linux distros)

It seems that the system was designed around presenting a logical menu ordering first and in the process of doing so, alienate most grub users familiar with grub "Default" by making the behavior of the new "GRUB_DEFAULT" unintuitive.

Regarding your problem, since "GRUB_DEFAULT" has no real weight in determining a default other than something like 'latest kernel (0)' or 'second latest kernel (1), etc, you will have to look into changing the ordering of execution of the scripts creating grub.cfg. Fortunately, I discovered that this can be done easily by renaming '30_os-prober" to something like "09_os-prober". The result is that update-grub will process it before "10_linux" and inserts these menu items on top of the heap. I can't test this definitely though as I don't currently have anything else installed.

I hope this helps! I certainly learned more about grub2!
digital pbk
...
written by digitalpbk, November 16, 2009
This seems like a story! For concise instructions I have posted em over at my blog here,
http://digitalpbk.com/2009/11/...ubuntu-910
J.A. Watson
What happens when new kernels are generated?
written by J.A. Watson, November 16, 2009
@digitalpbk - You don't mention, either here or in your blog, whether your "solution" will continue to work when a new kernel is compiled and appears in the /boot directory. I suspected that it would not, so I just made a quick test (which I wish you had done before posting a comment), and confirmed that in fact it does not. The problem is exactly as I described it originally. Immediately after installing ubuntu, there is only one kernel present in /boot, so the entries in boot.cfg are:

0 - current kernel, normal boot
1 - current kernel, recovery boot
2 - memtest86+, normal boot
3 - memtest86+, serial console boot
4 - Windows

If you edit /etc/default/grub and change GRUB_DEFAULT to 4, you will in fact boot Windows by default.

However, when Ubuntu eventually updates the kernel there will be TWO kernel boot files in /boot. For purposes of this discussion, and this test, let's say they are vmlinuz-2.6.31-14-generic (the real current kernel) and vmlinuz-2.6.31-15-generic (a likely candidate for the next kernel). When this happens, and update-grub is run, the grub.cfg file will contain:

0 - current kernel (-15), normal boot
1 - current kernel (-15), recovery boot
2 - previous kernel (-14), normal boot
3 - previous kernel (-14), recovery boot
4 - memtest86+, normal boot
5 - memtest86+, serial console boot
6 - Windows

However, nothing has changed in /etc/default/grub, so when update-grub runs, your default will be a normal boot of the previous kernel, not Windows! If you want to boot Windows, you have to edit /etc/default/grub again, and change the default to 6, and this is EXACTLY what I don't want to happen when I am preparing a computer to give to someone who has no idea about boot default settings, editing system files, or anything else.

@avid - The theory you described sounds to me like it is the only one which is likely to work across kernel changes and the like - effectively moving the Windows boot ahead of the Linux boots in grub.cfg, so their default value is not affected by changes in the Linux boot entries. I have not yet tried this, but it certainly looks like it will work. Thanks.

@kunthar - It is not clear to me why you would bother to post a comment which "solves" a problem other than the one I was writing about.

I appreciate people reading and commenting on my blog. However, if you are going to post a comment with a "solution", please at least have the courtesy to other readers of ensuring that your "solution" corresponds to the situation being discussed - otherwise, just start your own blog somewhere, and write until your heart is content. Likewise, please at least make some minimal effort to ensure that your "solution" is correct, and works for the specific situation described. I believe that I was quite clear in describing what the problem being addressed in my original post was - NOT the simple changing of the default boot, but getting that change to continue to work when new Linux kernels appeared. Posting a purported "solution" which does not work in exactly that situation is misleading and counterproductive.

Thanks.

jw
kunthar
Because of the nature of net
written by kunthar, November 17, 2009
My aim was not to deviate a main subject any way.
We are not all nature English speakers. We are searching the internet and finding the results. I found this blog while searched about grub2 boot problem. Sure, here is not an exact place to put those comments on. But it works. It seems so many people comes to this blog exactly with same purposes as me. Because this site is indexing more frequently then mine by Google. And you see someone made a blog as well as me. Mine is here too.
http://www.kunthar.com/blogs/kunthar.php/grub2-switching-boot-order

The nature of semantic internet connections couldn't be classified easily. I respect your problem but the things on the internet are not always crystal clear. Hope i could express myself.
vasya
...
written by vasya, November 17, 2009
just what you've looked for, i guess

for example:

# GRUB_DEFAULT="xxxx" - An exact menu entry, including the quotation symbols, may also be used. In this case, location in the menu will not matter. Example: GRUB_DEFAULT="Windows 7 (loader) on /dev/sda1"

see
http://ubuntuforums.org/showthread.php?t=1195275
for more
J.A. Watson
Thanks
written by J.A. Watson, November 17, 2009
@vasya - Yes, exactly what I was looking for, thanks very much.

Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.

busy