个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
安装Windows后恢复Ubuntu
 
使用 Ubuntu Alternate/Install CD
 
(未显示8个用户的29个中间版本)
第1行: 第1行:
{{Translation}}
+
{{Translation}}  
 
{{From|http://wiki.ubuntu.org.cn/UbuntuHelp:RecoveringUbuntuAfterInstallingWindows}}
 
{{From|http://wiki.ubuntu.org.cn/UbuntuHelp:RecoveringUbuntuAfterInstallingWindows}}
 
{{Translator|聂海波 }}
 
{{Translator|聂海波 }}
{{Languages|php5}}
+
{{Languages|UbuntuHelp:RecoveringUbuntuAfterInstallingWindows}}
 +
 
 +
== 使用Ubuntu Desktop/Live CD ==
 +
 
 +
请选择下列选项之一:
 +
 
 +
=== Using the Desktop/LiveCD while preserving Windows Bootloader  ===
 +
=== 使用LiveCD重建GRUB ===
 +
 
 +
不要忘记如下方法:在硬盘引导分区上,用GRUB替代MBR(主引导纪录)。这适用于大多数人,除非你有了另外一个可用的引导程序。
 +
 
 +
另一方面,如果你用Boot Magic or System Commander,你读到的命令将改写你所做的。
 +
 
 +
如果你已在引导分区安装GRUB替换了MBR,命令将会有所不同。下面是我的建议:
 +
 
 +
如何在Ghost后恢复Grub: (译者注:适用于重新安装windows而导致丢失GRUB,我用过使用Ghost软件和GHO镜像恢复windows系统,不会映像grub的。)
 +
 
 +
1.用Live CD引导系统,例如Ubuntu Live, Knoppix, Mepis, or similar.
 +
 
 +
2.打开终端。打开根终端(用在非Ubuntu光盘中用“su",在Ubuntu光盘中用"sudo -i)。密码是必须的。
 +
 
 +
3.输入"grub" 。
 +
 
 +
4.输入"find /boot/grub/stage1"。你会看到像"(hd0)" 的信息(我的是(hd0,3)")。在下面的操作中,使用你的计算机显示的信息。 (译者注:如果是boot单独分区的,需要改为"find /grub/stage1")
 +
 
 +
5.输入"root (hd0,3)"。(译注:以下信息以原作者的为例,自己当改成所看到的)
 +
 
 +
6.输入"setup (hd0,3)". 这是关键。如果你想将GRUB写入MBR,可以用其他的操作,如输入"(hd0)"。如果你想将它写入你的linux引导分区,可以在逗号后写入数,如"(hd0,3)"。
 +
 
 +
7.输入"quit".
 +
 
 +
8.重启系统。取走引导CD。
 +
 
 +
来自:http://ubuntuforums.org/showpost.php?p=121355&postcount=5
 +
 
 +
=== 使用Desktop/LiveCD ,改写Windows bootloader===
 +
 
 +
 
 +
用Live CD引导,打开终端。当需要root权限使用一些命令时,可以使用''sudo -i'' 来获得root命令行,用此可以正规地代替使用''sudo''。此时要特别小心,尤其是要注意打字错误。
 +
 
 +
我们要找到Ubuntu系统安在哪个分区。输入命令''fdisk -l''。将返回你所有分区列表,例如:
 +
 
 +
<pre><nowiki>$ sudo 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</nowiki></pre>
 +
 
 +
这里,我有三个Linux分区./dev/hda2 是我的根分区,/dev/hda1是我的/boot 分区,dev/hda6 是我的 /home分区.如果你只有一个,显然就是你的Ubuntu系统安装分区.你还有更多的分区,而你不知道哪个是你的Ubuntu系统安装分区,可以稍后再查找.首先,为你的分区创建一个挂载点,例如:
 +
 
 +
<code><nowiki>mkdir /mnt/root</nowiki></code>
 +
 
 +
然后挂载你的分区.如果你不知道哪一个是,就每一个都挂载一次,直到找到正确的为止.
 +
 
 +
<code><nowiki>mount -t ext3 /dev/hda2 /mnt/root</nowiki></code>
 +
 
 +
当然,用你的正确分区名称替换掉这里的/dev/hda2.可以用''ls /mnt/root''来核实是否是正确的,可能会显示如下信息:
 +
 
 +
<pre><nowiki>bin    dev      home        lib    mnt  root    srv  usr
 +
boot  etc      initrd      lib64  opt  sbin    sys  var
 +
cdrom  initrd.img  media  proc  selinux  tmp  vmlinuz</nowiki></pre>
 +
 
 +
如果不是像这样的,则说明没有挂载正确的分区.使用''umount /mnt/root'' 来卸载掉分区,再试试另一个.你可能需要挂载你的/boot分区,例如:
 +
 
 +
<code><nowiki>mount -t ext3 /dev/hda1 /mnt/root/boot</nowiki></code>
 +
 
 +
确信挂载正确,用''ls /mnt/root/boot''验证,会返回如下信息:
 +
 
 +
<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
 +
initrd.img-2.6.18-3-686  memtest86+.bin</nowiki></pre>
 +
 
 +
再次说明,如果仍然不符合,卸载掉并加载另一个分区.
 +
 
 +
现在都挂载了,我们要重新安装GRUB:
 +
 
 +
<code><nowiki>grub-install --root-directory=/mnt/root /dev/hda</nowiki></code>
 +
 
 +
如果你得到BIOS警告,试试:
 +
 
 +
<code><nowiki>grub-install --root-directory=/mnt/root /dev/hda -recheck</nowiki></code>
 +
 
 +
当然,用你自己想安装GRUB的位置替换/dev/hda.如果一切成功,将会看到如下信息:
 +
 
 +
<pre><nowiki>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</nowiki></pre>
 +
 
 +
现在你可以重启,GRUB菜单将会出现.如果有一个XFS文件系统的相关警告,可以忽略.
 +
 
 +
=== 不使用 Ubuntu Desktop/Live CD ===
 +
 
 +
你可能不使用Ubuntu Desktop/Live CD,而是从你的安装光盘来使用"grub".想要这样做,挂载你的分区(下面的例子假定root分区在hda1):
 +
 
 +
<pre><nowiki>sudo mkdir /mnt/linux
 +
sudo mount /dev/hda1 /mnt/linux
 +
</nowiki></pre>
 +
 
 +
接着改路径为你的安装sbin,并从那里运行grub
 +
 
 +
<pre><nowiki>cd /mnt/linux/sbin
 +
sudo ./grub
 +
</nowiki></pre>
 +
 
 +
== 使用非官方的 "Super Grub Disk" ==
 +
 
 +
*下载 [http://supergrub.forjamari.linex.org/ Super Grub Disk]
 +
* 刻录光盘 (建议)或拷入软盘
 +
* 启动
 +
* ''' 选择:语言 '''
 +
* ''' 选择: Linux '''
 +
* ''' 选择: 修复 Boot of Linux (GRUB) '''
 +
* ''' 选择你想恢复的Linux或Grub安装. '''
 +
* 你会看到信息: SGD 已安好!
 +
* 重启
 +
* 成功.
 +
 
 +
==发现并修理故障==
 +
 
 +
这部分内容将:
 +
*在Ubuntu安装后才安装Windows的双启动设置
 +
*Windows必须重新安装
 +
*Windows恢复技术牵扯到MBR
 +
*GRUB安装失败的其他情形
 +
 
 +
 
 +
前提:
 +
*你的Ubuntu分区仍然完整
 +
*你有一个LiveCD,如Ubuntu Desktop CD,或者其他替代品
 +
*你对用LiveCD足够熟悉,可以获得支持
 +
*你还记得你的安装分区(打印`/etc/fstab` 是个好方法,这样你可以使用fdisk -l /dev/hda)
 +
*如果使用非Ubuntu内核或是建立自己的内核,要知道核心工作的知识(特别是关于initrd)
 +
*你的内核版本;这取决于2.6.10-5-386
 +
 
 +
=== 准备你的工作环境 ===
 +
开始恢复程序,插入liveCD,重启计算机.直至你的LiveCD启动到看到界面.如果你的LiveCD没有立即出现控制台,就用终端.用Ubuntu LiveCD,点 应用程序-系统工具- 终端.
 +
 
 +
''注意'': 因为这是LiveCD环境, 任何对用户帐户或文件系统的改变不会保持.这意味着你可以设置一个临时的根密码,创建目录,而不会影响你的实际安装.
 +
 
 +
现在你要获得根权限.在Ubuntu下,可以用下面的命令:
 +
<pre><nowiki>sudo -i
 +
</nowiki></pre>
 +
 
 +
在Knoppix下,下面的命令就足够了,并不要密码:
 +
<pre><nowiki>su -
 +
</nowiki></pre>
 +
 
 +
现在,你有了根权限,挂载你有启动引导文件的分区.
 +
 
 +
你得访问`/sbin/`和/boot/` 目录.如果在`fstab`中有一个`/boot/`列表,须挂载两个分区.
 +
 
 +
开始为工作环境创建一个挂载点-得注意同时建立一个目录.
 +
<pre><nowiki>mkdir /mnt/work
 +
</nowiki></pre>
 +
 
 +
如果须挂载`/boot/`,使用下面的命令.
 +
<pre><nowiki>mkdir /mnt/work/boot
 +
</nowiki></pre>
 +
 
 +
现在可以装载文件系统数据.复查`fstab`,确信`/`和`/boot/`;就像`/dev/hda3` 和`/dev/hda4`,这里字母a和数字3与4可能不同.
 +
 
 +
'''注意''':`/dev/hda3` and `/dev/hda4`是假定的,必须换成你自己的.
 +
 
 +
键入以下命令来装载你的文件系统,一些GRUB信息是可能要用的.
 +
<pre><nowiki>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</nowiki></pre>
 +
 
 +
现在,你进入你的工作环境.下面命令得小心了.
 +
<pre><nowiki>chroot /mnt/work/ /bin/bash
 +
</nowiki></pre>
 +
 
 +
""警告"":从这时起,任何改变会影响到你的Ubuntu系统.你已离开LiveCD的安全模式.特别要注意.
 +
 
 +
====自动恢复 GRUB ====
 +
如果你有独立的/boot分区,用下面的命令:
 +
<pre><nowiki>sudo mount /dev/hda3 /boot/
 +
</nowiki></pre>
 +
 
 +
从这里起重新安装GRUB是比较容易的.仅需使用下列命令:
 +
<pre><nowiki>sudo /sbin/grub-install /dev/hda
 +
</nowiki></pre>
 +
 
 +
如果上述命令不能使用,很不幸,得手工配置GRUB(这并不难);如果成功,在最后一节会显示:"Configuring the GRUB Menu".
 +
 
 +
==== 手工恢复GRUB ====
 +
 
 +
[http://forum.ubuntu.org.cn/viewtopic.php?t=80901&sid=bdbea8cccaafe1bdbde209cfbfcb1584 如果您觉得下面写得又长又烦,可以看这里:简单配图实例]<br>
 +
 
 +
开始下一步前,弄明白GRUB如何定义分区是相当重要的.
 +
 
 +
对于GRUB,数字从0开始,字母明确的,也从0开始.
 +
 
 +
例如,/dev/hda1对于GRUB,是"hd0,0".例如/dev/hdb3是hd1,2. For example, `/dev/hda1` is "hd0,0" to GRUB. Similarly, `/dev/hdb3` is "hd1,2".
 +
 
 +
""注意"":"root"必须指向你的'/boot/'分区,如果你有的话.没有,则指向'/'分区.
 +
<pre>sudo /sbin/grub
 +
grub&gt; root (hd0,2)
 +
grub&gt; setup (hd0)
 +
grub&gt; quit
 +
</pre>
 +
 
 +
==== 配置GRUB菜单====
 +
'''注意''': 如果只是恢复MBR,这一步就没必要做.安装Windows并不会改变已存在的'menu.lst',因此一切都正常的话,也都会正常工作,只需要重启计算机.
 +
 
 +
用你喜爱的编辑器打开GRUB菜单文件'/boot/grub/menu.lst'.例如:
 +
<pre><nowiki>sudo nano /boot/grub/menu.lst
 +
</nowiki></pre>
 +
 +
'''注意''': 'menu.lst'文件用来控制操作系统在启动时GRUB的显示.本指南将只能解释如何让你的操作系统启动,它不会告诉你如何使你的bootloader漂亮。
 +
 
 +
一个menu.lst例子, 去除必要的备注, 如: 上面的例子是基于/dev/hda3和dev/hda4,并假定Windows位于/dev/hda1.
 +
<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
 +
fallback 1 #The entry which should be booted in the event of the first one failing
 +
 
 +
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
 +
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</nowiki></pre>
 +
 
 +
现在,保存并关闭这个文件,重启系统.
 +
 
 +
== 使用 Ubuntu Alternate/Install CD ==
 +
 
 +
这一节解释如何恢复GRUB(the GRand Unified Boot loader),使用Ubuntu alternate/install CD.
 +
 
 +
*进入BIOS设置从光驱启动.如果可以从CD启动,插入CD.退出BIOS(保存设置以确保可以从CD启动).
 +
*当Ubuntu闪屏出现boot命令行时,输入rescue,并回车.
 +
*选择语言,位置(国家),键盘布局,如同重新安装一样.
 +
*输入一个名字,或用默认的Ubuntu.
 +
*在这个阶段,提交选择哪个是你的根分区(有一个硬盘分区列表,所以你必须知道ubuntu在哪个分区) 。这将是
 +
<code><nowiki>dev/discs/disc0/partX</nowiki></code>, 这里<code><nowiki>X</nowiki></code> 是分区数字.
 +
*提交了一份命令提示符.
 +
*输入<code><nowiki>$ grub-install /dev/hdaX</nowiki></code>,X是你的Ubuntu root安装分区.
 +
 
 +
 
 +
=== 使用Alternate/Install CD改写Windows bootloader ===
 +
 
 +
 
 +
* 用Ubuntu CD启动计算机
 +
* 进行安装进程,直到出现 "[!!!] Disk Partition"
 +
*选择手动分区
 +
* 挂载正确linux分区:
 +
***/
 +
***/boot
 +
***swap
 +
***...
 +
* '''DO NOT FORMAT THEM.'''
 +
* 完成手工分区
 +
*问及是否保存改变时,选择"Yes"
 +
* 之后,系统会给出错误提示,"系统不能安装......"
 +
* 忽略,继续选择"continue" 直到获得Ubuntu 安装菜单
 +
* 进入"Install Grub ...."
 +
*完成后,重启计算机.
 +
 
 +
From: http://doc.gwos.org/index.php/Restore_Grub and http://ubuntuforums.org/showthread.php?t=76652
 +
 
 +
== GRUB资源==
 +
** [http://www.gnu.org/software/grub/manual/html_node/ GRUB Manual]
 +
** [http://www.gnu.org/software/grub GRUB homepage]
 +
** [http://autistici.org/grub/ Grub wiki]
 +
** [http://tldp.org/HOWTO/Linux+Win9x+Grub-HOWTO/index.html Linux+Win+Grub HowTo]
 +
** [http://supergrub.forjamari.linex.org/ Super Grub Disk. Ready to go cdrom or floppy that restores Grub on MBR automatically]
 +
** [http://promote-opensource.org/modules/mylinks/singlelink.php?cid=14&lid=94 Linux Recovery and Boot Disk Creation with Grub].
 +
** [http://www.skyjammer.com/files/knoppix/ Win32 Grub]
 +
** [http://www.ameritech.net/users/gholmer/booting.html Booting with GRUB]
 +
** [http://grub4dos.sourceforge.net/ WinGRUB]
 +
** [http://www.geocities.com/lode_leroy/grubinstall/ GRUB Installer for Windows]
 +
** [http://grub.linuxeden.com/ GRUB for DOS] - Bridging DOS/Windows to Unix/Linux
 +
 
 +
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
 +
 
 +
[[category:UbuntuHelp]]

2009年9月25日 (五) 21:58的最新版本


使用Ubuntu Desktop/Live CD

请选择下列选项之一:

Using the Desktop/LiveCD while preserving Windows Bootloader

使用LiveCD重建GRUB

不要忘记如下方法:在硬盘引导分区上,用GRUB替代MBR(主引导纪录)。这适用于大多数人,除非你有了另外一个可用的引导程序。

另一方面,如果你用Boot Magic or System Commander,你读到的命令将改写你所做的。

如果你已在引导分区安装GRUB替换了MBR,命令将会有所不同。下面是我的建议:

如何在Ghost后恢复Grub: (译者注:适用于重新安装windows而导致丢失GRUB,我用过使用Ghost软件和GHO镜像恢复windows系统,不会映像grub的。)

1.用Live CD引导系统,例如Ubuntu Live, Knoppix, Mepis, or similar.

2.打开终端。打开根终端(用在非Ubuntu光盘中用“su",在Ubuntu光盘中用"sudo -i)。密码是必须的。

3.输入"grub" 。

4.输入"find /boot/grub/stage1"。你会看到像"(hd0)" 的信息(我的是(hd0,3)")。在下面的操作中,使用你的计算机显示的信息。 (译者注:如果是boot单独分区的,需要改为"find /grub/stage1")

5.输入"root (hd0,3)"。(译注:以下信息以原作者的为例,自己当改成所看到的)

6.输入"setup (hd0,3)". 这是关键。如果你想将GRUB写入MBR,可以用其他的操作,如输入"(hd0)"。如果你想将它写入你的linux引导分区,可以在逗号后写入数,如"(hd0,3)"。

7.输入"quit".

8.重启系统。取走引导CD。

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

使用Desktop/LiveCD ,改写Windows bootloader

用Live CD引导,打开终端。当需要root权限使用一些命令时,可以使用sudo -i 来获得root命令行,用此可以正规地代替使用sudo。此时要特别小心,尤其是要注意打字错误。

我们要找到Ubuntu系统安在哪个分区。输入命令fdisk -l。将返回你所有分区列表,例如:

$ sudo 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

这里,我有三个Linux分区./dev/hda2 是我的根分区,/dev/hda1是我的/boot 分区,dev/hda6 是我的 /home分区.如果你只有一个,显然就是你的Ubuntu系统安装分区.你还有更多的分区,而你不知道哪个是你的Ubuntu系统安装分区,可以稍后再查找.首先,为你的分区创建一个挂载点,例如:

mkdir /mnt/root

然后挂载你的分区.如果你不知道哪一个是,就每一个都挂载一次,直到找到正确的为止.

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

当然,用你的正确分区名称替换掉这里的/dev/hda2.可以用ls /mnt/root来核实是否是正确的,可能会显示如下信息:

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

如果不是像这样的,则说明没有挂载正确的分区.使用umount /mnt/root 来卸载掉分区,再试试另一个.你可能需要挂载你的/boot分区,例如:

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

确信挂载正确,用ls /mnt/root/boot验证,会返回如下信息:

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

再次说明,如果仍然不符合,卸载掉并加载另一个分区.

现在都挂载了,我们要重新安装GRUB:

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

如果你得到BIOS警告,试试:

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

当然,用你自己想安装GRUB的位置替换/dev/hda.如果一切成功,将会看到如下信息:

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

现在你可以重启,GRUB菜单将会出现.如果有一个XFS文件系统的相关警告,可以忽略.

不使用 Ubuntu Desktop/Live CD

你可能不使用Ubuntu Desktop/Live CD,而是从你的安装光盘来使用"grub".想要这样做,挂载你的分区(下面的例子假定root分区在hda1):

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

接着改路径为你的安装sbin,并从那里运行grub

cd /mnt/linux/sbin
sudo ./grub

使用非官方的 "Super Grub Disk"

  • 下载 Super Grub Disk
  • 刻录光盘 (建议)或拷入软盘
  • 启动
  • 选择:语言
  • 选择: Linux
  • 选择: 修复 Boot of Linux (GRUB)
  • 选择你想恢复的Linux或Grub安装.
  • 你会看到信息: SGD 已安好!
  • 重启
  • 成功.

发现并修理故障

这部分内容将:

  • 在Ubuntu安装后才安装Windows的双启动设置
  • Windows必须重新安装
  • Windows恢复技术牵扯到MBR
  • GRUB安装失败的其他情形


前提:

  • 你的Ubuntu分区仍然完整
  • 你有一个LiveCD,如Ubuntu Desktop CD,或者其他替代品
  • 你对用LiveCD足够熟悉,可以获得支持
  • 你还记得你的安装分区(打印`/etc/fstab` 是个好方法,这样你可以使用fdisk -l /dev/hda)
  • 如果使用非Ubuntu内核或是建立自己的内核,要知道核心工作的知识(特别是关于initrd)
  • 你的内核版本;这取决于2.6.10-5-386

准备你的工作环境

开始恢复程序,插入liveCD,重启计算机.直至你的LiveCD启动到看到界面.如果你的LiveCD没有立即出现控制台,就用终端.用Ubuntu LiveCD,点 应用程序-系统工具- 终端.

注意: 因为这是LiveCD环境, 任何对用户帐户或文件系统的改变不会保持.这意味着你可以设置一个临时的根密码,创建目录,而不会影响你的实际安装.

现在你要获得根权限.在Ubuntu下,可以用下面的命令:

sudo -i

在Knoppix下,下面的命令就足够了,并不要密码:

su -

现在,你有了根权限,挂载你有启动引导文件的分区.

你得访问`/sbin/`和/boot/` 目录.如果在`fstab`中有一个`/boot/`列表,须挂载两个分区.

开始为工作环境创建一个挂载点-得注意同时建立一个目录.

mkdir /mnt/work

如果须挂载`/boot/`,使用下面的命令.

mkdir /mnt/work/boot

现在可以装载文件系统数据.复查`fstab`,确信`/`和`/boot/`;就像`/dev/hda3` 和`/dev/hda4`,这里字母a和数字3与4可能不同.

注意:`/dev/hda3` and `/dev/hda4`是假定的,必须换成你自己的.

键入以下命令来装载你的文件系统,一些GRUB信息是可能要用的.

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

现在,你进入你的工作环境.下面命令得小心了.

chroot /mnt/work/ /bin/bash

""警告"":从这时起,任何改变会影响到你的Ubuntu系统.你已离开LiveCD的安全模式.特别要注意.

自动恢复 GRUB

如果你有独立的/boot分区,用下面的命令:

sudo mount /dev/hda3 /boot/

从这里起重新安装GRUB是比较容易的.仅需使用下列命令:

sudo /sbin/grub-install /dev/hda

如果上述命令不能使用,很不幸,得手工配置GRUB(这并不难);如果成功,在最后一节会显示:"Configuring the GRUB Menu".

手工恢复GRUB

如果您觉得下面写得又长又烦,可以看这里:简单配图实例

开始下一步前,弄明白GRUB如何定义分区是相当重要的.

对于GRUB,数字从0开始,字母明确的,也从0开始.

例如,/dev/hda1对于GRUB,是"hd0,0".例如/dev/hdb3是hd1,2. For example, `/dev/hda1` is "hd0,0" to GRUB. Similarly, `/dev/hdb3` is "hd1,2".

""注意"":"root"必须指向你的'/boot/'分区,如果你有的话.没有,则指向'/'分区.

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

配置GRUB菜单

注意: 如果只是恢复MBR,这一步就没必要做.安装Windows并不会改变已存在的'menu.lst',因此一切都正常的话,也都会正常工作,只需要重启计算机.

用你喜爱的编辑器打开GRUB菜单文件'/boot/grub/menu.lst'.例如:

sudo nano /boot/grub/menu.lst

注意: 'menu.lst'文件用来控制操作系统在启动时GRUB的显示.本指南将只能解释如何让你的操作系统启动,它不会告诉你如何使你的bootloader漂亮。

一个menu.lst例子, 去除必要的备注, 如: 上面的例子是基于/dev/hda3和dev/hda4,并假定Windows位于/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

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
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

现在,保存并关闭这个文件,重启系统.

使用 Ubuntu Alternate/Install CD

这一节解释如何恢复GRUB(the GRand Unified Boot loader),使用Ubuntu alternate/install CD.

  • 进入BIOS设置从光驱启动.如果可以从CD启动,插入CD.退出BIOS(保存设置以确保可以从CD启动).
  • 当Ubuntu闪屏出现boot命令行时,输入rescue,并回车.
  • 选择语言,位置(国家),键盘布局,如同重新安装一样.
  • 输入一个名字,或用默认的Ubuntu.
  • 在这个阶段,提交选择哪个是你的根分区(有一个硬盘分区列表,所以你必须知道ubuntu在哪个分区) 。这将是

dev/discs/disc0/partX, 这里X 是分区数字.

  • 提交了一份命令提示符.
  • 输入$ grub-install /dev/hdaX,X是你的Ubuntu root安装分区.


使用Alternate/Install CD改写Windows bootloader

  • 用Ubuntu CD启动计算机
  • 进行安装进程,直到出现 "[!!!] Disk Partition"
  • 选择手动分区
  • 挂载正确linux分区:
      • /
      • /boot
      • swap
      • ...
  • DO NOT FORMAT THEM.
  • 完成手工分区
  • 问及是否保存改变时,选择"Yes"
  • 之后,系统会给出错误提示,"系统不能安装......"
  • 忽略,继续选择"continue" 直到获得Ubuntu 安装菜单
  • 进入"Install Grub ...."
  • 完成后,重启计算机.

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

GRUB资源