A Digital Age Deserves A Digital Leader

How to edit GRUB default OS multi booting Linux and Windows

How to edit GRUB default OS multi booting Linux and Windows

Postby Grav!ty » Fri May 29, 2009 3:50 am

GRUB seems to be an excellent bootloader, and picks up installations of other operating systems automatically on installation of Linux after Windows is installed.

I'm still spending most PC time in Windows and would like to be able to edit the default OS so that it's the Other operating systems entry in GRUB. Using the C or E key (I forget which) to edit GRUB doesn't seem to let me actually edit the default OS selection or the countdown timer which is set at 10 seconds.

Any idea how I can do that or if there's an MBR editor I can use for that? I haven't tried MS dskprobe.exe from within Windows XP, which does allow one to edit the MBR, but I'm not sure it will edit GRUB.
Image

"The great majority of mankind are satisfied with appearances, as though they were realities, and are often more influenced by the things that seem than by those that are." - Niccolo Machiavelli
PROfessional Member
User avatar
Posts: 15790
Joined: Tue Sep 14, 2004 5:22 am
Real Name: Graham

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby imnuts » Fri May 29, 2009 11:19 am

You'll need access to the GRUB config file, so you probably won't be able to edit it unless you boot into Linux. Once there, you need to have root access, so open a root terminal, or open a normal terminal and use the su command to get the needed access. Make sure that /boot is mounted, then you can open the config file with any text editor. If you're using GNOME, it would likely be easiest in Gedit, so from the root terminal, use the following command to open it
Code: Select all
gedit /boot/grub/menu.lst

It should have all the boot options there, you'll just need to change the default entry number to whatever you want to boot first. You can also change the countdown timer if you want as well.
Image
PRO SUPREME
User avatar
Posts: 7457
Joined: Wed Mar 24, 2004 5:19 am
Location: Boothwyn, Pennsylvania
Real Name: Mark

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby gries818 » Fri May 29, 2009 12:20 pm

I suggest making a backup before you edit it ^*^

Code: Select all
cp /boot/grub/menu.lst /boot/grub/menu.backup
sudo gedit /boot/grub/menu.lst
Image

Mac OS 10.6.7 - Personal
Ubuntu Server 11.04 - Server
Software Development
User avatar
Posts: 3991
Joined: Wed Jul 07, 2004 6:28 pm

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby Grav!ty » Fri May 29, 2009 3:53 pm

Thanks guys. I opened a terminal window and then ran sudo gedit /boot/grub/menu.lst. After entering my password, a second terminal window opened and after checking around I figured to first try changing the boot timeout, which I did to 30 seconds, saved, exited and rebooted. The timeout changed perfectly. Here's a screenie for those unfamiliar with this stuff:

Image

I'm not confident about making the default OS changes, so here's the entire contents of menu.lst (/boot/grub) - gedit. Please tell me exactly what to change...looks like what needs changing is at the very end of the text below. For the Windows Vista (loader) entry, do I just add =true so that the line savedefault there reads savedefault=true ?

Code: Select all
# menu.lst - See: grub(8), info grub, update-grub(8)
#            grub-install(8), grub-floppy(8),
#            grub-md5-crypt, /usr/share/doc/grub
#            and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# 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 use 'savedefault' or your
# array will desync and will not let you boot your system.
default      0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout      30

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line)  and entries protected by the
# command 'lock'
# e.g. password topsecret
#      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title      Windows 95/98/NT/2000
# root      (hd0,0)
# makeactive
# chainloader   +1
#
# title      Linux
# root      (hd0,1)
# kernel   /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
##      kopt_2_6_8=root=/dev/hdc1 ro
##      kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 ro

## default grub root device
## e.g. groot=(hd0,0)
# groot=0299b33f-1d8f-48ed-8226-69e6fa31e5e3

## should update-grub create alternative automagic boot options
## e.g. alternative=true
##      alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
##      lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
##      lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
##      howmany=7
# howmany=all

## specify if running in Xen domU or have grub detect automatically
## update-grub will ignore non-xen kernels when running in domU and vice versa
## e.g. indomU=detect
##      indomU=true
##      indomU=false
# indomU=detect

## should update-grub create memtest86 boot option
## e.g. memtest86=true
##      memtest86=false
# memtest86=true

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

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

## ## End Default Options ##

title      Ubuntu 9.04, kernel 2.6.28-11-generic
uuid      0299b33f-1d8f-48ed-8226-69e6fa31e5e3
kernel      /boot/vmlinuz-2.6.28-11-generic root=UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 ro quiet splash
initrd      /boot/initrd.img-2.6.28-11-generic
quiet

title      Ubuntu 9.04, kernel 2.6.28-11-generic (recovery mode)
uuid      0299b33f-1d8f-48ed-8226-69e6fa31e5e3
kernel      /boot/vmlinuz-2.6.28-11-generic root=UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 ro  single
initrd      /boot/initrd.img-2.6.28-11-generic

title      Ubuntu 9.04, memtest86+
uuid      0299b33f-1d8f-48ed-8226-69e6fa31e5e3
kernel      /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title      Other operating systems:
root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title      Windows Vista (loader)
rootnoverify   (hd0,0)
savedefault
makeactive
chainloader   +1
Image

"The great majority of mankind are satisfied with appearances, as though they were realities, and are often more influenced by the things that seem than by those that are." - Niccolo Machiavelli
PROfessional Member
User avatar
Posts: 15790
Joined: Tue Sep 14, 2004 5:22 am
Real Name: Graham

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby imnuts » Fri May 29, 2009 9:09 pm

I'm thinking this should work for you if you want it to default to Windows. If not, change the default to 4 and that should work. That one line in the middle there may screw things up (where it says other operating systems). Hopefully it doesn't count that as an entry.
Code: Select all
# menu.lst - See: grub(8), info grub, update-grub(8)
#            grub-install(8), grub-floppy(8),
#            grub-md5-crypt, /usr/share/doc/grub
#            and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# 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 use 'savedefault' or your
# array will desync and will not let you boot your system.
default      3

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout      30

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line)  and entries protected by the
# command 'lock'
# e.g. password topsecret
#      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title      Windows 95/98/NT/2000
# root      (hd0,0)
# makeactive
# chainloader   +1
#
# title      Linux
# root      (hd0,1)
# kernel   /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
##      kopt_2_6_8=root=/dev/hdc1 ro
##      kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 ro

## default grub root device
## e.g. groot=(hd0,0)
# groot=0299b33f-1d8f-48ed-8226-69e6fa31e5e3

## should update-grub create alternative automagic boot options
## e.g. alternative=true
##      alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
##      lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
##      lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
##      howmany=7
# howmany=all

## specify if running in Xen domU or have grub detect automatically
## update-grub will ignore non-xen kernels when running in domU and vice versa
## e.g. indomU=detect
##      indomU=true
##      indomU=false
# indomU=detect

## should update-grub create memtest86 boot option
## e.g. memtest86=true
##      memtest86=false
# memtest86=true

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

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

## ## End Default Options ##

title      Ubuntu 9.04, kernel 2.6.28-11-generic
uuid      0299b33f-1d8f-48ed-8226-69e6fa31e5e3
kernel      /boot/vmlinuz-2.6.28-11-generic root=UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 ro quiet splash
initrd      /boot/initrd.img-2.6.28-11-generic
quiet

title      Ubuntu 9.04, kernel 2.6.28-11-generic (recovery mode)
uuid      0299b33f-1d8f-48ed-8226-69e6fa31e5e3
kernel      /boot/vmlinuz-2.6.28-11-generic root=UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 ro  single
initrd      /boot/initrd.img-2.6.28-11-generic

title      Ubuntu 9.04, memtest86+
uuid      0299b33f-1d8f-48ed-8226-69e6fa31e5e3
kernel      /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title      Other operating systems:
root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title      Windows Vista (loader)
rootnoverify   (hd0,0)
savedefault
makeactive
chainloader   +1
Image
PRO SUPREME
User avatar
Posts: 7457
Joined: Wed Mar 24, 2004 5:19 am
Location: Boothwyn, Pennsylvania
Real Name: Mark

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby Grav!ty » Sat May 30, 2009 5:29 am

Thanks again guys. I changed default to 3 and as you suspected Mark, that highlighted the Other operating systems entry, which worked anyway. When I pressed Enter it took me to the Vista boot menu.

Then I went back and changed default to 4 and that took me directly to the entry named Windows Vista (loader) :harley:

Question: If I'd caused things to go belly up, and was unable to enter Ubuntu at all after that, how would I restore my GRUB loader backup? By booting to the live CD? If so, then what command would I need to run from the sudo terminal?
Image

"The great majority of mankind are satisfied with appearances, as though they were realities, and are often more influenced by the things that seem than by those that are." - Niccolo Machiavelli
PROfessional Member
User avatar
Posts: 15790
Joined: Tue Sep 14, 2004 5:22 am
Real Name: Graham

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby imnuts » Sat May 30, 2009 3:34 pm

you would have had to mount the /boot partition. Not sure of your hard drive setup though, so I can't give the exact command. When you get a chance and get back into Ubuntu, can you post the contents of the file /etc/fstab ? Once I have that, I can give you the steps you'd have to take to restore the backup.
Image
PRO SUPREME
User avatar
Posts: 7457
Joined: Wed Mar 24, 2004 5:19 am
Location: Boothwyn, Pennsylvania
Real Name: Mark

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby Grav!ty » Sun May 31, 2009 12:14 pm

Here you go Mark.

Code: Select all
# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# / was on /dev/sdc5 during installation
UUID=0299b33f-1d8f-48ed-8226-69e6fa31e5e3 /               ext3    relatime,errors=remount-ro 0       1
# swap was on /dev/sdc6 during installation
UUID=f91e66dc-7342-4309-bd85-9313b65c927c none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0
Image

"The great majority of mankind are satisfied with appearances, as though they were realities, and are often more influenced by the things that seem than by those that are." - Niccolo Machiavelli
PROfessional Member
User avatar
Posts: 15790
Joined: Tue Sep 14, 2004 5:22 am
Real Name: Graham

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby imnuts » Sun May 31, 2009 3:55 pm

the way it looks, it should be something like this, though it's a little hard to tell since it's using UUIDs rather than the device name.
Code: Select all
sudo mount /dev/sdc5 /mnt
mv /mnt/boot/grub/menu.backup /mnt/boot/grub/menu.lst


That should work as it looks like Ubuntu put the boot files with all of the other files and not on another partition. It may also be possible that it will mount the drives automatically, and you would be able to move the file in Nautilus.
Image
PRO SUPREME
User avatar
Posts: 7457
Joined: Wed Mar 24, 2004 5:19 am
Location: Boothwyn, Pennsylvania
Real Name: Mark

Re: How to edit GRUB default OS multi booting Linux and Windows

Postby Grav!ty » Wed Jun 03, 2009 12:56 am

I reinstalled XP and of course that totally fubared GRUB. I'll get to give that a try when I get GRUB reinstalled and back into Ubuntu :yesnod:
Image

"The great majority of mankind are satisfied with appearances, as though they were realities, and are often more influenced by the things that seem than by those that are." - Niccolo Machiavelli
PROfessional Member
User avatar
Posts: 15790
Joined: Tue Sep 14, 2004 5:22 am
Real Name: Graham

Return to Other Operating Systems

Who is online

Users browsing this forum: No registered users and 5 guests

cron
cron