Making Windows the default boot option in Grub2

This might be easy to some but it sure took me a long time. By default, if you dual-boot Ubuntu and any version of Windows (XP/Vista/7) by installing Ubuntu AFTER installing Windows, Grub2 will be installed on the master boot record (MBR) and the smart scripts in Ubuntu will ensure that your Windows installation is found and added to the menu.

However, the default option is the latest Ubuntu you have on your machine, not Windows. If you follow the Ubuntu Community guide for Grub2, you could either set the GRUB_DEFAULT option to the menu position of your Windows installation or the exact menu label. e.g.
GRUB_DEFAULT=7
(if your Windows installation is 7th on the Grub list) or
GRUB_DEFAULT="Windows 7 (loader) on /dev/sda1"

An alternative method as outlined by avid (in the comments) on Changing the Default Boot with Ubuntu 9.10 GRUB 2 is to rename one file in /etc/grub.d/ and Windows will be the first listed option in the Grub menu - which is also the default option. In his/her own words:
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.
So that's basically it. Oh and don't forget to run sudo update-grub after incorporating whichever method you choose.

Comments

Popular posts from this blog

Exclude directories from chown

Flash game: Cargo Bridge

Copying Sony recovery partition to new harddisk