I dual-boot my machine and I want it to default to boot into windows so that whenever I restart the machine remotely from my home it will be able to get back into Windows (instead of Ubuntu).
The problem is that every time Ubuntu upgrades the kernel, I have to reset the default boot item of grub back to windows. This is because the grub menu loader uses positions i.e. 6 for default OS to boot. And when Ubuntu installs a new kernel it changes that order.
I am looking for a way to configure grub to remember its default boot item under kernel updates.
Best Answer
Grub 1 (Ubuntu 9.04 and earlier)
I find the easiest way to do this is to move the Windows boot entry above the Ubuntu entries in
/boot/grub/menu.lst
. By default, the Grub configuration file is laid out like this:Section 2 is demarcated by these lines in the config file:
Entries for autodetected OS's (eg, Windows) are placed after this section. When you install a new kernel, section 2 is the only section that gets changed. So moving the autodetected OS to somewhere before the
BEGIN
line will place it where the entry number won't change when a new kernel gets installed.Grub 2 (Ubuntu 9.10 and later)
With Grub2, the entire configuration file is created anew anytime
update-grub
is run, so editing/boot/grub/grub.cfg
won't be a permament fix. How that file is generated is handled by the files/etc/default/grub
and the scripts in/etc/grub.d/*
. So we modify the configuration by modifing the files which control individual sections of the configfile, then runningupdate-grub
again.My
/etc/grub.d
includes these files:These are shellscripts that get run in order to generate the config file. The Windows boot entry is generated by
30_os-prober
, which is run after the linux boot entries are generated in10_linux
. So just rename30_os-prober
to something less than 10, and rerunupdate-grub
Now your Windows entry should be the first entry, and you can set that as the default boot entry (
GRUB_DEFAULT=
) in/etc/default/grub
.