个人工具

“UbuntuHelp:RecoveringUbuntuAfterInstallingWindows”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第13行: 第13行:
 
sudo grub
 
sudo grub
 
</nowiki></pre>
 
</nowiki></pre>
4. You will get a grub prompt (see below) which we will use to find the root partition and install grub to the MBR (hd0,0)  
+
4. You will get a grub prompt (see below) which we will use to find the root partition and install grub to the MBR (hd0,0)
  
<pre><nowiki>   [ Minimal BASH-like line editing is supported.  For
+
<pre><nowiki>
 +
        [ Minimal BASH-like line editing is supported.  For
 
         the  first  word,  TAB  lists  possible  command
 
         the  first  word,  TAB  lists  possible  command
 
         completions.  Anywhere else TAB lists the possible
 
         completions.  Anywhere else TAB lists the possible
 
         completions of a device/filename. ]
 
         completions of a device/filename. ]
  
grub></nowiki></pre>  
+
grub>
 +
</nowiki></pre>
 
Type the following and press enter:
 
Type the following and press enter:
 
<pre><nowiki>
 
<pre><nowiki>
第55行: 第57行:
 
  chainloader +1
 
  chainloader +1
 
  </nowiki></pre>
 
  </nowiki></pre>
 +
Note: Put your Windows stanza before or after AUTOMAGIC KERNEL LIST in the menu.lst
 
=== Overwriting the Windows bootloader ===
 
=== Overwriting the Windows bootloader ===
 
Boot from a Live CD and open a terminal. You'll need to run a few commands as root so you can use ''sudo -i'' to get a root shell and run them normally instead of using ''sudo'' on each of them. Be extra careful when running a root shell, especially for typos !
 
Boot from a Live CD and open a terminal. You'll need to run a few commands as root so you can use ''sudo -i'' to get a root shell and run them normally instead of using ''sudo'' on each of them. Be extra careful when running a root shell, especially for typos !
 
We'll need to find which partition your Ubuntu system is installed on. Type the command ''fdisk -l''. It will output a list of all your partitions, for example :
 
We'll need to find which partition your Ubuntu system is installed on. Type the command ''fdisk -l''. It will output a list of all your partitions, for example :
<pre><nowiki>$ fdisk -l
+
<pre><nowiki>
 +
fdisk -l
  
 
Disk /dev/hda: 120.0 GB, 120034123776 bytes
 
Disk /dev/hda: 120.0 GB, 120034123776 bytes
第72行: 第76行:
 
/dev/hda6            2441      14530    97112862  83  Linux
 
/dev/hda6            2441      14530    97112862  83  Linux
  
Partition table entries are not in disk order</nowiki></pre>
+
Partition table entries are not in disk order </nowiki></pre>
Here I have three Linux partitions. /dev/hda2 is my root partition, /dev/hda1 is my /boot partition and /dev/hda6 is my /home partitoins. If you only have one, obviously this is the one your Ubuntu system is installed on. If you have more than one and you don't know which one your Ubuntu is installed on, we'll look for it later. First, create a mountpoint for your partition, for example :
+
Here I have three Linux partitions. /dev/hda2 is my root partition, /dev/hda1 is my /boot partition and /dev/hda6 is my /home partitions. If you only have one, obviously this is the one your Ubuntu system is installed on. If you have more than one and you don't know which one your Ubuntu is installed on, we'll look for it later. First, create a mountpoint for your partition, for example :
<code><nowiki>mkdir /mnt/root</nowiki></code>
+
<pre><nowiki>
 +
mkdir /mnt/root
 +
</nowiki></pre>
 
Then mount your partition in it. If you don't know which one it is, then mount any of them, we'll se if it's the correct one.
 
Then mount your partition in it. If you don't know which one it is, then mount any of them, we'll se if it's the correct one.
<code><nowiki>mount -t ext3 /dev/hda2 /mnt/root</nowiki></code>
+
<pre><nowiki>
 +
mount -t ext3 /dev/hda2 /mnt/root
 +
</nowiki></pre>
 
Of course, replace /dev/hda2 with the correct name of your partition. You can check if it's the correct one by running ''ls /mnt/root'', which should output something like this :
 
Of course, replace /dev/hda2 with the correct name of your partition. You can check if it's the correct one by running ''ls /mnt/root'', which should output something like this :
<pre><nowiki>bin    dev      home        lib    mnt  root    srv  usr
+
<pre><nowiki>
 +
bin    dev      home        lib    mnt  root    srv  usr
 
boot  etc      initrd      lib64  opt  sbin    sys  var
 
boot  etc      initrd      lib64  opt  sbin    sys  var
cdrom  initrd.img  media  proc  selinux  tmp  vmlinuz</nowiki></pre>
+
cdrom  initrd.img  media  proc  selinux  tmp  vmlinuz
 +
</nowiki></pre>
 
If what you have looks not at all like this, you didn't mount the correct partition. Do ''umount /mnt/root'' to unmount it and try another one. You also need to mount your /boot partition if you made one, like this :
 
If what you have looks not at all like this, you didn't mount the correct partition. Do ''umount /mnt/root'' to unmount it and try another one. You also need to mount your /boot partition if you made one, like this :
<code><nowiki>mount -t ext3 /dev/hda1 /mnt/root/boot</nowiki></code>
+
<pre><nowiki>
 +
mount -t ext3 /dev/hda1 /mnt/root/boot
 +
</nowiki></pre>
 
To make sure it was the correct one, run ''ls /mnt/root/boot'', which sould output something like this :
 
To make sure it was the correct one, run ''ls /mnt/root/boot'', which sould output something like this :
<pre><nowiki>config-2.6.18-3-686      initrd.img-2.6.18-3-686.bak  System.map-2.6.18-3-686
+
<pre><nowiki>
 +
config-2.6.18-3-686      initrd.img-2.6.18-3-686.bak  System.map-2.6.18-3-686
 
grub                    lost+found                  vmlinuz-2.6.18-3-686
 
grub                    lost+found                  vmlinuz-2.6.18-3-686
initrd.img-2.6.18-3-686  memtest86+.bin</nowiki></pre>
+
initrd.img-2.6.18-3-686  memtest86+.bin
 +
</nowiki></pre>
 
Once again, if what you have doesn't fit, unmount it and try another partition.
 
Once again, if what you have doesn't fit, unmount it and try another partition.
 
Now that everything is mounted, we just need to reinstall GRUB :
 
Now that everything is mounted, we just need to reinstall GRUB :
<code><nowiki>sudo grub-install --root-directory=/mnt/root /dev/hda</nowiki></code>
+
<pre><nowiki>
 +
sudo grub-install --root-directory=/mnt/root /dev/hda
 +
</nowiki></pre>
 
If you got BIOS warnings try:
 
If you got BIOS warnings try:
<code><nowiki>sudo grub-install --root-directory=/mnt/root /dev/hda --recheck</nowiki></code>
+
<pre><nowiki>
 +
sudo grub-install --root-directory=/mnt/root /dev/hda --recheck
 +
</nowiki></pre>
 
Of course, replace /dev/hda with the location you want to install GRUB on. If all went well, you should see something like this :
 
Of course, replace /dev/hda with the location you want to install GRUB on. If all went well, you should see something like this :
<pre><nowiki>Installation finished. No error reported.
+
<pre><nowiki>
 +
Installation finished. No error reported.
 
This is the contents of the device map /boot/grub/device.map.
 
This is the contents of the device map /boot/grub/device.map.
 
Check if this is correct or not. If any of the lines is incorrect,
 
Check if this is correct or not. If any of the lines is incorrect,
 
fix it and re-run the script `grub-install'.
 
fix it and re-run the script `grub-install'.
  
(hd0)  /dev/hda</nowiki></pre>
+
(hd0)  /dev/hda
 +
</nowiki></pre>
 
Now you can reboot and the GRUB menu should appear. If you see a warning message regarding XFS filesystem, you can ignore it.
 
Now you can reboot and the GRUB menu should appear. If you see a warning message regarding XFS filesystem, you can ignore it.
 
=== Preserving Windows Bootloader ===
 
=== Preserving Windows Bootloader ===
The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition.  But you probably won't want that, if you use a third-party boot manager like Boot Magic or System Commander.  (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.)  In that case, use this alternative.
+
The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition.  But you probably won't want that, if you use a third-party boot manager like Boot Magic or System Commander.  (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.)  In that case, use this alternative.
 
This alternative, used without a third-party boot manager, will not cause Ubuntu to boot.
 
This alternative, used without a third-party boot manager, will not cause Ubuntu to boot.
 +
'''If you have your Linux system in a second (or third...) hard disk this method will not work. Please check Super Grub Disk's method that address this problem.'''
 
1. Boot from a Live CD, like Ubuntu Live, Knoppix, Mepis, or similar.
 
1. Boot from a Live CD, like Ubuntu Live, Knoppix, Mepis, or similar.
 
2. Open a Terminal. Open a root terminal (that is, type "su" in a non-Ubuntu distro, or "sudo -i" in Ubuntu). Enter root passwords as necessary.
 
2. Open a Terminal. Open a root terminal (that is, type "su" in a non-Ubuntu distro, or "sudo -i" in Ubuntu). Enter root passwords as necessary.
第115行: 第136行:
 
== From Inside Ubuntu ==
 
== From Inside Ubuntu ==
 
You have to run "grub" not from the Ubuntu Desktop/Live CD, but from your disk installation to make it work. To do this mount your root partition (following examples assume a root partition on hda1):
 
You have to run "grub" not from the Ubuntu Desktop/Live CD, but from your disk installation to make it work. To do this mount your root partition (following examples assume a root partition on hda1):
<pre><nowiki>sudo mkdir /mnt/linux
+
<pre><nowiki>
 +
sudo mkdir /mnt/linux
 
sudo mount /dev/hda1 /mnt/linux
 
sudo mount /dev/hda1 /mnt/linux
 
</nowiki></pre>
 
</nowiki></pre>
 
then change directory to your installation sbin and run grub from there
 
then change directory to your installation sbin and run grub from there
<pre><nowiki>cd /mnt/linux/sbin
+
<pre><nowiki>
 +
cd /mnt/linux/sbin
 
sudo ./grub
 
sudo ./grub
 
</nowiki></pre>
 
</nowiki></pre>
第130行: 第153行:
 
* Next time you boot Windows, click yes when asked to remove UNetbootin-supergrubdisk to remove the Super Grub Disk menu entry.
 
* Next time you boot Windows, click yes when asked to remove UNetbootin-supergrubdisk to remove the Super Grub Disk menu entry.
 
=== As a standalone cd/floppy/usb ===
 
=== As a standalone cd/floppy/usb ===
* Download [http://forjamari.linex.org/projects/supergrub/ Super Grub Disk]  
+
* Download [http://forjamari.linex.org/projects/supergrub/ Super Grub Disk]
 
* Burn into a cdrom (better) or a floppy
 
* Burn into a cdrom (better) or a floppy
 
* Boot from it
 
* Boot from it
第139行: 第162行:
 
* You're done.
 
* You're done.
 
=== Preserving Windows Bootloader ===
 
=== Preserving Windows Bootloader ===
The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition.  But you probably won't want that, if you use a third-party boot manager like Boot Magic or System Commander.  (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.)  In that case, use this alternative.
+
The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition.  But you probably won't want that, if you use a third-party boot manager like Boot Magic or System Commander.  (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.)  In that case, use this alternative.
 
This alternative, used without a third-party boot manager, will not cause Ubuntu to boot.
 
This alternative, used without a third-party boot manager, will not cause Ubuntu to boot.
 
''' This alternative will let you boot your second hard disk Linux installations from Windows while the Using the Ubuntu Desktop/Live CD Preserving Windows Bootloader instructions will not.'''
 
''' This alternative will let you boot your second hard disk Linux installations from Windows while the Using the Ubuntu Desktop/Live CD Preserving Windows Bootloader instructions will not.'''
 
Either:
 
Either:
* Download [http://forjamari.linex.org/projects/supergrub/ Super Grub Disk]  
+
* Download [http://forjamari.linex.org/projects/supergrub/ Super Grub Disk]
 
* Burn into a cdrom (better) or a floppy
 
* Burn into a cdrom (better) or a floppy
 
* Boot from it
 
* Boot from it
第162行: 第185行:
 
If you have Vista installed and you installed Ubuntu and when you rebooted it didn't show up as a dual boot option, try going into Vista (since that is all you can do), use the program EasyBCD version 1.7
 
If you have Vista installed and you installed Ubuntu and when you rebooted it didn't show up as a dual boot option, try going into Vista (since that is all you can do), use the program EasyBCD version 1.7
 
It looks like this:
 
It looks like this:
http://aycu01.webshots.com/image/31560/2002188190250314159_rs.jpg
+
{{http://aycu01.webshots.com/image/31560/2002188190250314159_rs.jpg}}
 
Add your Linux install to the boot sequence.
 
Add your Linux install to the boot sequence.
 
== Troubleshooting ==
 
== Troubleshooting ==
第183行: 第206行:
 
'''Note''': Since this is a [[UbuntuHelp:LiveCD|LiveCD]] environment, any changes to user accounts or filesystem layouts at this level will not be permanent. This means you can set a temporary root password and create directories without affecting your actual installation.
 
'''Note''': Since this is a [[UbuntuHelp:LiveCD|LiveCD]] environment, any changes to user accounts or filesystem layouts at this level will not be permanent. This means you can set a temporary root password and create directories without affecting your actual installation.
 
Now, you need to gain root access. Under Ubuntu, this can be done with the following commands:
 
Now, you need to gain root access. Under Ubuntu, this can be done with the following commands:
<pre><nowiki>sudo -i
+
<pre><nowiki>
 +
sudo -i
 
</nowiki></pre>
 
</nowiki></pre>
 
Under Knoppix, the following command will suffice, and you will not be prompted for a password.
 
Under Knoppix, the following command will suffice, and you will not be prompted for a password.
<pre><nowiki>su -
+
<pre><nowiki>
 +
su -
 
</nowiki></pre>
 
</nowiki></pre>
 
Now that you have root access, you need to mount the partition(s) containing your bootloader files.
 
Now that you have root access, you need to mount the partition(s) containing your bootloader files.
 
You will need access to both your `/sbin/` and `/boot/` directories. If you have a `/boot/` listing in your `fstab`, you are among those who will need to mount two partitions.
 
You will need access to both your `/sbin/` and `/boot/` directories. If you have a `/boot/` listing in your `fstab`, you are among those who will need to mount two partitions.
 
Begin by creating a mount point for your working environment -- you'll notice this is the same as creating a directory.
 
Begin by creating a mount point for your working environment -- you'll notice this is the same as creating a directory.
<pre><nowiki>mkdir /mnt/work
+
<pre><nowiki>
 +
mkdir /mnt/work
 
</nowiki></pre>
 
</nowiki></pre>
 
If you need to mount `/boot/`, too, run the following command.
 
If you need to mount `/boot/`, too, run the following command.
<pre><nowiki>mkdir /mnt/work/boot
+
<pre><nowiki>
 +
mkdir /mnt/work/boot
 
</nowiki></pre>
 
</nowiki></pre>
 
Now it's time to actually load your filesystem data. Review your `fstab` and identify the location(s) of `/` and `/boot/`; these will likely look something like `/dev/hda3` and `/dev/hda4`, though the letter 'a' and the numbers 3 and 4 may differ.
 
Now it's time to actually load your filesystem data. Review your `fstab` and identify the location(s) of `/` and `/boot/`; these will likely look something like `/dev/hda3` and `/dev/hda4`, though the letter 'a' and the numbers 3 and 4 may differ.
 
'''Note''': For the remainder of this howto, `/dev/hda3` and `/dev/hda4` will be assumed, so alter them as needed when typing them in yourself.
 
'''Note''': For the remainder of this howto, `/dev/hda3` and `/dev/hda4` will be assumed, so alter them as needed when typing them in yourself.
 
Enter the following commands to load your filesystem and some information GRUB may need.
 
Enter the following commands to load your filesystem and some information GRUB may need.
<pre><nowiki>mount /dev/hda4 /mnt/work
+
<pre><nowiki>
 +
mount /dev/hda4 /mnt/work
 
mount -o bind /dev /mnt/work/dev
 
mount -o bind /dev /mnt/work/dev
 
mount -o bind /proc /mnt/work/proc
 
mount -o bind /proc /mnt/work/proc
cp /proc/mounts /mnt/work/etc/mtab</nowiki></pre>
+
cp /proc/mounts /mnt/work/etc/mtab
 +
</nowiki></pre>
 
Now, you have to enter your working environment. The following command will take care of that.
 
Now, you have to enter your working environment. The following command will take care of that.
<pre><nowiki>chroot /mnt/work/ /bin/bash
+
<pre><nowiki>
 +
chroot /mnt/work/ /bin/bash
 
</nowiki></pre>
 
</nowiki></pre>
 
'''Warning''': From this point on, any files you modify will affect your Ubuntu system. You have left the safety of the [[UbuntuHelp:LiveCD|LiveCD]]. Excercise caution.
 
'''Warning''': From this point on, any files you modify will affect your Ubuntu system. You have left the safety of the [[UbuntuHelp:LiveCD|LiveCD]]. Excercise caution.
 
==== Recovering GRUB Automatically ====
 
==== Recovering GRUB Automatically ====
 
If you have a separate `/boot/` partition, type the following line.
 
If you have a separate `/boot/` partition, type the following line.
<pre><nowiki>sudo mount /dev/hda3 /boot/
+
<pre><nowiki>
 +
sudo mount /dev/hda3 /boot/
 
</nowiki></pre>
 
</nowiki></pre>
 
Reinstalling GRUB from this point is easy. Just enter the following command.
 
Reinstalling GRUB from this point is easy. Just enter the following command.
<pre><nowiki>sudo /sbin/grub-install /dev/hda
+
<pre><nowiki>
 +
sudo /sbin/grub-install /dev/hda
 
</nowiki></pre>
 
</nowiki></pre>
 
If the command you used above failed, which is unlikely, you will need to configure GRUB manually (it isn't too hard); if it succeeded, you should read the note at the start of the final section: "Configuring the GRUB Menu".
 
If the command you used above failed, which is unlikely, you will need to configure GRUB manually (it isn't too hard); if it succeeded, you should read the note at the start of the final section: "Configuring the GRUB Menu".
第221行: 第253行:
 
Similarly, `/dev/hdb3` is "hd1,2".
 
Similarly, `/dev/hdb3` is "hd1,2".
 
'''Note''': The "root" line must point to the location of your `/boot/` partition if you have one. If you do not have one, point it at your `/` partition.
 
'''Note''': The "root" line must point to the location of your `/boot/` partition if you have one. If you do not have one, point it at your `/` partition.
<pre><nowiki>sudo /sbin/grub
+
<pre><nowiki>
 +
sudo /sbin/grub
 
grub> root (hd0,2)
 
grub> root (hd0,2)
 
grub> setup (hd0)
 
grub> setup (hd0)
grub> quit</nowiki></pre>
+
grub> quit
 +
</nowiki></pre>
 
==== Configuring the GRUB Menu ====
 
==== Configuring the GRUB Menu ====
 
'''Note''': This step does not need to be done if you're just trying to recover your MBR. Installing Windows will not alter the contents of your existing `menu.lst`, so if everything was working right before, everything will continue to work right now, and you can restart your computer.
 
'''Note''': This step does not need to be done if you're just trying to recover your MBR. Installing Windows will not alter the contents of your existing `menu.lst`, so if everything was working right before, everything will continue to work right now, and you can restart your computer.
 
Open the GRUB menu file, `/boot/grub/menu.lst`, with your favourite text editor. An example follows.
 
Open the GRUB menu file, `/boot/grub/menu.lst`, with your favourite text editor. An example follows.
<pre><nowiki>sudo nano /boot/grub/menu.lst
+
<pre><nowiki>
 +
sudo nano /boot/grub/menu.lst
 
</nowiki></pre>
 
</nowiki></pre>
 
'''Note''': Your `menu.lst` file is used to control the operating systems GRUB displays on startup, as well as its visual appearance. This howto will only explain how to get your operating systems to boot; it will not tell you how to make your bootloader pretty.
 
'''Note''': Your `menu.lst` file is used to control the operating systems GRUB displays on startup, as well as its visual appearance. This howto will only explain how to get your operating systems to boot; it will not tell you how to make your bootloader pretty.
 
A sample `menu.lst`, stripped of unnecessary comments, appears below. It is based on the `/dev/hda3` and `/dev/hda4` example above, and assumes Windows resides at `/dev/hda1`.
 
A sample `menu.lst`, stripped of unnecessary comments, appears below. It is based on the `/dev/hda3` and `/dev/hda4` example above, and assumes Windows resides at `/dev/hda1`.
<pre><nowiki>timeout 5 #The number of seconds GRUB should wait before booting an OS
+
<pre><nowiki>
 +
timeout 5 #The number of seconds GRUB should wait before booting an OS
 
default 0 #The entry which should be booted by default
 
default 0 #The entry which should be booted by default
 
fallback 1 #The entry which should be booted in the event of the first one failing
 
fallback 1 #The entry which should be booted in the event of the first one failing
第253行: 第289行:
 
root  (hd0,0)
 
root  (hd0,0)
 
makeactive
 
makeactive
chainloader +1</nowiki></pre>
+
chainloader +1
 +
</nowiki></pre>
 
And that's it. Save and close the file, then reboot and try out the entries.
 
And that's it. Save and close the file, then reboot and try out the entries.
 
== Using the Ubuntu Alternate/Install CD ==
 
== Using the Ubuntu Alternate/Install CD ==
第272行: 第309行:
 
</li><li>Mount your appropriate linux partions:</li></ol>
 
</li><li>Mount your appropriate linux partions:</li></ol>
  
*/  
+
*/
 
*/boot
 
*/boot
 
*swap
 
*swap
第297行: 第334行:
 
* [http://www.geocities.com/lode_leroy/grubinstall/ GRUB Installer for Windows]
 
* [http://www.geocities.com/lode_leroy/grubinstall/ GRUB Installer for Windows]
 
* [http://grub.linuxeden.com/ GRUB for DOS] - Bridging DOS/Windows to Unix/Linux
 
* [http://grub.linuxeden.com/ GRUB for DOS] - Bridging DOS/Windows to Unix/Linux
[[category:CategoryLive]] [[category:CategoryBackupRecovery]] [[category:CategoryCleanup]]
+
----
 +
[[category:CategoryLive]] [[category:CategoryBackupRecovery]] [[category:CategoryCleanup]] [[category:CategoryBootAndPartition]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2008年10月19日 (日) 17:03的版本


  1. title Recovering Ubuntu after installing Windows

This page documents how to restore or recover from a boot-loader problem. Ubuntu uses the Grub bootloader, please see GrubHowto for more information on Grub. Some common reasons for repairing your bootloader are installing Microsoft Windows, adding or removing a hard drive, or even changing hard drive settings.

Using the Ubuntu Desktop/Live CD

Quick Start

This option will use the Desktop/Live CD to install Grub into your MBR (Master Boot Record). This option will overwrite your Windows Boot Loader It is OK to do this, in fact that is the goal of this how to (in order to boot Ubuntu) B) 1. Boot the Desktop/Live CD. 2. Open a terminal (Applications -> Accessories -> Terminal) 3. Start grub as root with the following command :

sudo grub

4. You will get a grub prompt (see below) which we will use to find the root partition and install grub to the MBR (hd0,0)

         [ Minimal BASH-like line editing is supported.   For
         the   first   word,  TAB  lists  possible  command
         completions.  Anywhere else TAB lists the possible
         completions of a device/filename. ]

grub>

Type the following and press enter:

find /boot/grub/stage1

Using this information, set the root device:

grub> root (hd0,1)

Install Grub:

grub> setup (hd0)

Exit Grub:

grub> quit

5. Reboot (to hard drive). Grub should be installed and both Ubuntu and Windows should have been automatically detected. 6. If, after installing grub, Windows will not boot you may need to edit /boot/grub/menu.lst (That is a small "L" and not the number 1 in menu.lst)

Open a terminal and enter :

 gksu gedit /boot/grub/menu.lst
 

Or, in Kubuntu:

 kdesu kate /boot/grub/menu.lst
 

Your Windows stanza should look something like this :

 title Windows XP/Vista # You can use any title you wish, this will appear on your grub boot menu
 rootnoverify (hd0,0) #(hd0,0) will be most common, you may need to adjust accordingly
 makeactive
 chainloader +1
 

Note: Put your Windows stanza before or after AUTOMAGIC KERNEL LIST in the menu.lst

Overwriting the Windows bootloader

Boot from a Live CD and open a terminal. You'll need to run a few commands as root so you can use sudo -i to get a root shell and run them normally instead of using sudo on each of them. Be extra careful when running a root shell, especially for typos ! We'll need to find which partition your Ubuntu system is installed on. Type the command fdisk -l. It will output a list of all your partitions, for example :

fdisk -l

Disk /dev/hda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1           8       64228+  83  Linux
/dev/hda2               9        1224     9767520   83  Linux
/dev/hda3   *        1225        2440     9767520   a5  FreeBSD
/dev/hda4            2441       14593    97618972+   5  Extended
/dev/hda5           14532       14593      498015   82  Linux swap / Solaris
/dev/hda6            2441       14530    97112862   83  Linux

Partition table entries are not in disk order 

Here I have three Linux partitions. /dev/hda2 is my root partition, /dev/hda1 is my /boot partition and /dev/hda6 is my /home partitions. If you only have one, obviously this is the one your Ubuntu system is installed on. If you have more than one and you don't know which one your Ubuntu is installed on, we'll look for it later. First, create a mountpoint for your partition, for example :

mkdir /mnt/root

Then mount your partition in it. If you don't know which one it is, then mount any of them, we'll se if it's the correct one.

mount -t ext3 /dev/hda2 /mnt/root

Of course, replace /dev/hda2 with the correct name of your partition. You can check if it's the correct one by running ls /mnt/root, which should output something like this :

bin    dev      home        lib    mnt   root     srv  usr
boot   etc      initrd      lib64  opt   sbin     sys  var
cdrom  initrd.img  media  proc  selinux  tmp  vmlinuz

If what you have looks not at all like this, you didn't mount the correct partition. Do umount /mnt/root to unmount it and try another one. You also need to mount your /boot partition if you made one, like this :

mount -t ext3 /dev/hda1 /mnt/root/boot

To make sure it was the correct one, run ls /mnt/root/boot, which sould output something like this :

config-2.6.18-3-686      initrd.img-2.6.18-3-686.bak  System.map-2.6.18-3-686
grub                     lost+found                   vmlinuz-2.6.18-3-686
initrd.img-2.6.18-3-686  memtest86+.bin

Once again, if what you have doesn't fit, unmount it and try another partition. Now that everything is mounted, we just need to reinstall GRUB :

sudo grub-install --root-directory=/mnt/root /dev/hda

If you got BIOS warnings try:

sudo grub-install --root-directory=/mnt/root /dev/hda --recheck

Of course, replace /dev/hda with the location you want to install GRUB on. If all went well, you should see something like this :

Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(hd0)   /dev/hda

Now you can reboot and the GRUB menu should appear. If you see a warning message regarding XFS filesystem, you can ignore it.

Preserving Windows Bootloader

The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition. But you probably won't want that, if you use a third-party boot manager like Boot Magic or System Commander. (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.) In that case, use this alternative. This alternative, used without a third-party boot manager, will not cause Ubuntu to boot. If you have your Linux system in a second (or third...) hard disk this method will not work. Please check Super Grub Disk's method that address this problem. 1. Boot from a Live CD, like Ubuntu Live, Knoppix, Mepis, or similar. 2. Open a Terminal. Open a root terminal (that is, type "su" in a non-Ubuntu distro, or "sudo -i" in Ubuntu). Enter root passwords as necessary. 3. Type "grub" which makes a GRUB prompt appear. 4. Type "find /boot/grub/stage1". You'll get a response like "(hd0)" or in my case "(hd0,3)". Use whatever your computer spits out for the following lines. Note that you should have mounted the partition which has your Linux system before typing this command. (e.g. In Knoppix Live CD partitions are shown on the desktop but they're not mounted until you double-click on them or mount them manually) 5. Type "root (hd0,3)". 6. Type "setup (hd0,3)". This is key. Other instructions say to use "(hd0)", and that's fine if you want to write GRUB to the MBR. If you want to write it to your linux root partition, then you want the number after the comma, such as "(hd0,3)". 7. Type "quit". 8. Restart the system. Remove the bootable CD.

From: http://ubuntuforums.org/showpost.php?p=121355&postcount=5

From Inside Ubuntu

You have to run "grub" not from the Ubuntu Desktop/Live CD, but from your disk installation to make it work. To do this mount your root partition (following examples assume a root partition on hda1):

sudo mkdir /mnt/linux
sudo mount /dev/hda1 /mnt/linux

then change directory to your installation sbin and run grub from there

cd /mnt/linux/sbin
sudo ./grub

Using the Unofficial "Super Grub Disk"

From within Windows

  • Download Auto Super Grub Disk
  • Double-click auto_super_grub_disk_1.0 icon, install it, and reboot.
  • On the next boot, select the UNetbootin-supergrubdisk menu entry; this will launch the Auto Super Grub Disk.
  • Do nothing till you see your Grub menu again.
  • Next time you boot Windows, click yes when asked to remove UNetbootin-supergrubdisk to remove the Super Grub Disk menu entry.

As a standalone cd/floppy/usb

  • Download Super Grub Disk
  • Burn into a cdrom (better) or a floppy
  • Boot from it
  • Select: GRUB => MBR & !LINUX! (>2) MANUAL |8-)
  • Select the Linux or Grub installation you want to restore.
  • You see the message: SGD has done it!
  • Reboot
  • You're done.

Preserving Windows Bootloader

The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition. But you probably won't want that, if you use a third-party boot manager like Boot Magic or System Commander. (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.) In that case, use this alternative. This alternative, used without a third-party boot manager, will not cause Ubuntu to boot. This alternative will let you boot your second hard disk Linux installations from Windows while the Using the Ubuntu Desktop/Live CD Preserving Windows Bootloader instructions will not. Either:

  • Download Super Grub Disk
  • Burn into a cdrom (better) or a floppy
  • Boot from it

Or:

  • Download UNetbootin Super Grub Disk Loader (Windows .exe version)
  • Run the installer and reboot when once done installing.
  • On the next boot, select the "UNetbootin-supergrubdisk" menu entry; this will launch the Super Grub Disk interface.

Then:

  • Super Grub Disk (WITH HELP)  :-)))
  • Select: your language
  • Select: Windows
  • Select: Windows chainloads Grub!
  • Select the Linux or Grub installation you want to restore to its own partition.
  • You see the message: SGD has done it!
  • Reboot
  • You're done.

Using Microsoft Vista

If you have Vista installed and you installed Ubuntu and when you rebooted it didn't show up as a dual boot option, try going into Vista (since that is all you can do), use the program EasyBCD version 1.7 It looks like this: 模板:Http://aycu01.webshots.com/image/31560/2002188190250314159 rs.jpg Add your Linux install to the boot sequence.

Troubleshooting

This section applies to...

  • Dual-boot setups in which Windows was installed after Ubuntu
  • Conditions where Windows failure forced a re-installation
  • Windows recovery techniques involving the "restoration" of the MBR
  • Cases where GRUB failed to install

Prerequisites:

  • Your Ubuntu partitions are all still intact
  • You have a LiveCD, such as the Ubuntu Desktop CD, or anything you're comfortable with
  • You're familiar enough with your LiveCD to gain access to a console
  • You remember how you set up your partitions (having a printout of `/etc/fstab` is ideal, though you can make do with the output of fdisk -l /dev/hda)
  • Knowledge of how your kernel works (specifically with regards to initrd), if you're using a non-Ubuntu kernel or built your own
  • Your kernel's version; this howto assumes 2.6.10-5-386

Preparing Your Working Environment

To begin the restoration procedure, insert your LiveCD and reboot your computer. Proceed with your LiveCD's bootup proceedure until you are presented with an interface. If your LiveCD does not immediately present you with a console, also called a terminal, open one -- to do this with the Ubuntu LiveCD, click Applications -> System Tools -> Terminal. Note: Since this is a LiveCD environment, any changes to user accounts or filesystem layouts at this level will not be permanent. This means you can set a temporary root password and create directories without affecting your actual installation. Now, you need to gain root access. Under Ubuntu, this can be done with the following commands:

sudo -i

Under Knoppix, the following command will suffice, and you will not be prompted for a password.

su -

Now that you have root access, you need to mount the partition(s) containing your bootloader files. You will need access to both your `/sbin/` and `/boot/` directories. If you have a `/boot/` listing in your `fstab`, you are among those who will need to mount two partitions. Begin by creating a mount point for your working environment -- you'll notice this is the same as creating a directory.

mkdir /mnt/work

If you need to mount `/boot/`, too, run the following command.

mkdir /mnt/work/boot

Now it's time to actually load your filesystem data. Review your `fstab` and identify the location(s) of `/` and `/boot/`; these will likely look something like `/dev/hda3` and `/dev/hda4`, though the letter 'a' and the numbers 3 and 4 may differ. Note: For the remainder of this howto, `/dev/hda3` and `/dev/hda4` will be assumed, so alter them as needed when typing them in yourself. Enter the following commands to load your filesystem and some information GRUB may need.

mount /dev/hda4 /mnt/work
mount -o bind /dev /mnt/work/dev
mount -o bind /proc /mnt/work/proc
cp /proc/mounts /mnt/work/etc/mtab

Now, you have to enter your working environment. The following command will take care of that.

chroot /mnt/work/ /bin/bash

Warning: From this point on, any files you modify will affect your Ubuntu system. You have left the safety of the LiveCD. Excercise caution.

Recovering GRUB Automatically

If you have a separate `/boot/` partition, type the following line.

sudo mount /dev/hda3 /boot/

Reinstalling GRUB from this point is easy. Just enter the following command.

sudo /sbin/grub-install /dev/hda

If the command you used above failed, which is unlikely, you will need to configure GRUB manually (it isn't too hard); if it succeeded, you should read the note at the start of the final section: "Configuring the GRUB Menu".

Recovering GRUB Manually

Before you can undertake the next step, it's important that you understand how GRUB identifies partitions. To GRUB, numbers begin with 0, and letters are expressed numerically, also beginning with 0. For example, `/dev/hda1` is "hd0,0" to GRUB. Similarly, `/dev/hdb3` is "hd1,2". Note: The "root" line must point to the location of your `/boot/` partition if you have one. If you do not have one, point it at your `/` partition.

sudo /sbin/grub
grub> root (hd0,2)
grub> setup (hd0)
grub> quit

Configuring the GRUB Menu

Note: This step does not need to be done if you're just trying to recover your MBR. Installing Windows will not alter the contents of your existing `menu.lst`, so if everything was working right before, everything will continue to work right now, and you can restart your computer. Open the GRUB menu file, `/boot/grub/menu.lst`, with your favourite text editor. An example follows.

sudo nano /boot/grub/menu.lst

Note: Your `menu.lst` file is used to control the operating systems GRUB displays on startup, as well as its visual appearance. This howto will only explain how to get your operating systems to boot; it will not tell you how to make your bootloader pretty. A sample `menu.lst`, stripped of unnecessary comments, appears below. It is based on the `/dev/hda3` and `/dev/hda4` example above, and assumes Windows resides at `/dev/hda1`.

timeout 5 #The number of seconds GRUB should wait before booting an OS
default 0 #The entry which should be booted by default
fallback 1 #The entry which should be booted in the event of the first one failing

title  Ubuntu, 2.6.10 #A 32-bit Ubuntu entry
#This (or something like it) should be in your configuration
root   (hd0,2)
initrd /initrd.img-2.6.10-5-386
kernel /vmlinuz-2.6.10-5-386 root=/dev/hda4

title  Ubuntu, 2.6.10 #Another 32-bit Ubuntu entry
#This is an example of an Ubuntu entry which does not have a separate /boot/ partition
#(it is provided only as an alternate to the example above -- do not use them together)
root   (hd0,2)
initrd /boot/initrd.img-2.6.10-5-386
kernel /boot/vmlinuz-2.6.10-5-386

title  Microsoft Windows XP Home #An entry for a Windows installation
#If you're reading this guide, you probably want this
root   (hd0,0)
makeactive
chainloader +1

And that's it. Save and close the file, then reboot and try out the entries.

Using the Ubuntu Alternate/Install CD

This section explains how to rescue GRUB (the GRand Unified Boot loader), using the Ubuntu alternate/install CD ROM.

  1. Enter your computers BIOS to check computer can boot from CD ROM. If you can boot from CD, insert CD ROM into drive. Exit the BIOS (if needed save your settings to make sure the computer boots from the CD ROM).
  2. When the Ubuntu splash screen comes up with the `boot:` prompt, type in `rescue` and press enter.
  3. Choose your language, location (country) and then keyboard layout as if you were doing a fresh install.
  4. Enter a host name, or leave it with the default (Ubuntu).
  5. At this stage you are presented with a screen where you can select which partition is your root partition (there is a list of the partitions on your hard drive, so you are required to know which partition number Ubuntu is on). This will be dev/discs/disc0/partX, where the X is a partition number.
  6. you are then presented with a command prompt (a hash).
  7. type $ grub-install /dev/hdaX where X is your Ubuntu root install.

The GUI Way: Using the Alternate/Install CD and Overwriting the Windows bootloader

  1. Boot your computer with the Ubuntu CD
  2. Go through the installation process until you reach "[!!!] Disk Partition"
  3. Select Manual Partition
  4. Mount your appropriate linux partions:
  • /
  • /boot
  • swap
  • ...
  1. DO NOT FORMAT THEM.
  2. Finish the manual partition
  3. Say "Yes" when it asks you to save the changes
  4. It will give you errors saying that "the system couldn't install ....." after that
  5. Ignore them, keep select "continue" until you get back to the Ubuntu installation menu
  6. Jump to "Install Grub ...."
  7. Once it is finished, just restart your computer

From: http://doc.gwos.org/index.php/Restore_Grub and http://ubuntuforums.org/showthread.php?t=76652

GRUB Resources