Monday, June 1, 2009

Set Grub Default to Windows or Last Selected Choice

I was installing a used hard-drive in a friends computer after his drive failed, so had to re-install windows, etc. I took the opportunity to install Ubuntu Linux on the last 6 gigs of the hard-drive as well, in case he is ever having troubles (virus, root-kit, etc) with Windows, he can boot to linux if he still needs to get on the Internet, etc.

I wanted to make it so Windows would be the default on the grub menu. This in itself is actually rather easy, just setting the 'default' option in grub to the line number that Windows shows up in the Grub boot menu. This becomes a problem later in "life" if Ubuntu is updated, and a new kernel is installed in addition to the old kernel, this changes the line that Windows will show up on. One way around this was to move the lines that add Windows to the grub menu up to the top of the menu.lst, therefore it shouldn't change (hopefully)... but I came up with a better suggestion with a little more digging on google. Instead, I simply enabled the usefulness of the savedefault option in Grub, so that any grub menu options (kernel options/operating systems) that have the savedefault in their list of commands would change the default O/S to THAT O/S. If you don't have a "default 0" option, thats fine, just make sure you add the new "default saved" option to your config somewhere in the global area (near the top area).

** The lines with #XX in front of them have been replaced by the respective following line of each of them.

# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
#XXdefault 0
default saved

## should update-grub adjust the value of the default booted system
## can be true or false
#XX# updatedefaultentry=false
# updatedefaultentry=true

## should update-grub add savedefault to the default options
## can be true or false
#XX# savedefault=false
# savedefault=true

If my friend ever goes into Ubuntu, it will change the default to Ubuntu, but all he has to do to get it to default back to windows again, is simply choose to boot into windows again from the grub menu, and it will then default to windows again. Problem solved.

One other option could be to remove the savedefault from any menu entries that you don't want to make changes to the default O/S menu choice during boot-up, if you happen to boot that entry once in a while and don't ever want it to be the default.

No comments: