Grub: Difference between revisions

From miki
Jump to navigation Jump to search
No edit summary
(Booting Windows partition)
Line 2: Line 2:
* Official manual [http://www.gnu.org/software/grub/manual/grub.html here].
* Official manual [http://www.gnu.org/software/grub/manual/grub.html here].


== Boot from CDROM ==
== Boot from CDROM / Windows ==
When booting on HDD, it is possible to tell ''Grub'' to boot from CDROM instead.
When booting on HDD, it is possible to tell ''Grub'' to boot from CDROM instead. The same command-set can be used to boot the Windows partition (in case it has been removed from Grub menu)
* Press '''esc''' to quit Grub GUI menu.
* Press '''esc''' to quit Grub GUI menu.
* Press '''c''' to go to command-line mode.
* Press '''c''' to go to command-line mode.
* Enter the following commands (adapt <tt>hd2</tt> according to your configuration):
* Enter the following commands (assuming CDROM is on hd2 / Windows is on hd0). Note that Grub uses hd0,hd1... not /dev/sda...):
grub>rootnoverify (hd2)
grub>'''rootnoverify (hd2)''' ''#or '''(hd0,0)''' for Windows partition''
grub>chainloader +1
grub>'''chainloader +1'''
grub>boot
grub>'''boot'''
Note that this might be actually a hack that only works on my machine. More information on normal way to tell Grub to boot on CDROM:
Note that this might be actually a hack that only works on my machine. More information:
* [http://www.gnu.org/software/grub/manual/grub.html#Booting GRUB Manual - Boot]
* http://www.mail-archive.com/bug-grub@gnu.org/msg10280.html
* http://www.mail-archive.com/bug-grub@gnu.org/msg10280.html
* http://gentoo-wiki.com/TIP_Chainloading_a_bootable_CD-ROM_from_GRUB
* http://gentoo-wiki.com/TIP_Chainloading_a_bootable_CD-ROM_from_GRUB
Line 17: Line 18:
'''grubonce''' is an handy tool to force the system to immediately boot a given grub entry at the next reboot.
'''grubonce''' is an handy tool to force the system to immediately boot a given grub entry at the next reboot.


By default, '''grubonce''' can only be run by root, but we can use '''sudo''' to allow any user to use '''grubonce'''. Make the following change to the <tt>/etc/sudoers</tt> file ('''use command <font color="red">visudo</font> to edit this file'''):
(as root)
$ grubonce
0: openSUSE 11.0 - 2.6.25.20-0.1
1: Failsafe -- openSUSE 11.0 - 2.6.25.20-0.1
2: windows
3: Floppy
$ grubonce 2


<pre>
By default, '''grubonce''' can only be run by root. We can use '''sudo''' to allow any user to use '''grubonce'''.
Defaults env_keep = "DISPLAY ..." # add DISPLAY env var to the list of kept var
ALL ALL = (ALL) NOPASSWD: /usr/sbin/grubonce
</pre>


Now, you can reboot immediately a grub entry with:
% su
<source lang="bash">
$ visudo
$ sudo grubonce
... edit the /etc/sudoers file
# 0: openSUSE 11.0 - 2.6.25.20-0.1
$ exit
# 1: Failsafe -- openSUSE 11.0 - 2.6.25.20-0.1
% sudo grubonce 2
# 2: windows

# 3: Floppy
Make the following change to the <tt>sudoers</tt> file:
$ sudo grubonce 2
Defaults env_keep = "DISPLAY ..." # add DISPLAY env var to the list of kept var
</source>
ALL ALL = (ALL) NOPASSWD: /usr/sbin/grubonce


== Restore / Troubleshoot ==
== Restore / Troubleshoot ==

Revision as of 09:22, 10 October 2009

Documentation

  • Official manual here.

Boot from CDROM / Windows

When booting on HDD, it is possible to tell Grub to boot from CDROM instead. The same command-set can be used to boot the Windows partition (in case it has been removed from Grub menu)

  • Press esc to quit Grub GUI menu.
  • Press c to go to command-line mode.
  • Enter the following commands (assuming CDROM is on hd2 / Windows is on hd0). Note that Grub uses hd0,hd1... not /dev/sda...):
grub>rootnoverify (hd2)             #or (hd0,0) for Windows partition
grub>chainloader +1
grub>boot

Note that this might be actually a hack that only works on my machine. More information:

Grubonce

grubonce is an handy tool to force the system to immediately boot a given grub entry at the next reboot.

By default, grubonce can only be run by root, but we can use sudo to allow any user to use grubonce. Make the following change to the /etc/sudoers file (use command visudo to edit this file):

Defaults        env_keep = "DISPLAY ..."             # add DISPLAY env var to the list of kept var
ALL     ALL = (ALL) NOPASSWD: /usr/sbin/grubonce

Now, you can reboot immediately a grub entry with:

$ sudo grubonce
# 0: openSUSE 11.0 - 2.6.25.20-0.1
# 1: Failsafe -- openSUSE 11.0 - 2.6.25.20-0.1
# 2: windows
# 3: Floppy
$ sudo grubonce 2

Restore / Troubleshoot

To repair a broken / lost GRUB, do from any grub prompt (live CD...) [1]:

grub> find /boot/grub/stage1
find /boot/grub/stage1
 (hd0,4)
grub> root (hd0,4)
root (hd0,4)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  23 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+23 p (hd0,4)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
  • try find /grub/stage1 if the first find command doesn't work
  • In my example I set root to (hd0,4) make sure you set it to whatever the find command returns
  • Always run 'setup (hd0)' to install grub on the MBR of the first drive. For second drive use (hd1) etc