免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 828 | 回复: 0
打印 上一主题 下一主题

删除Linux与恢复grub [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-30 20:41 |只看该作者 |倒序浏览

删除Linux与恢复grub,这是我等新手常遇到的两个问题,感觉Linux不好,想退出,就要删除 Linux,覆盖Grub;而装了Windows与Linux双系统的用户,又会在重装Windows时把Grub覆盖掉,需要恢复Grub。这是后路,我们在做事之前需要先考虑好的。
删除Linux,覆盖Grub,还原成XP自带的启动引导,这个很简单,只要你有Windows XP盘(非Ghost),用它启动,至选择安装位置的地方退出重启就可以。或者用它启动故障修复台,运行fixboot或者fixmbr都可以。
而恢复Grub,其实也很简单的:用Live CD(对于Ubuntu来说就是Desktop CD或者DVD)启动,打开终端(Applications──>Accessory──>Terminal),执行以下代码:
代码:
sudo grub                                
find /boot/grub/stage1
root (hdX,Y)
setup (hdX)
quit
注意:其中的X、Y是执行find /boot/grub/stage1命令后系统提示的。,比如:
代码:
grub> find /boot/grub/menu.lst
(hd0,7)
注意:这里的grub>是执行sudo grub命令后进入grub环境得到的提示符,不用输入。这时,X就是0,Y就是7。
下面详细解释一下这几条命令:
sudo grub 以root用户身份启动grub,否则会出错,错误见后文
find /boot/grub/stage1 寻找/boot所在分区,其实换用find /boot/grub/menu.lst也一样。
root (hdX,Y) 设置硬盘hdX的根文件系统(root Device),实际就是设置/boot所在的分区
setup (hdX) 自动安装GRUB到硬盘hdX。
quit 退出GRUB
root、setup命令后都有空格,如果没有会出错误。
如果不以root用户身份会出现什么样的错误呢?
引用:
ubuntu@ubuntu:~$grub
[ 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> find /boot/grub/stage1
Error 15: File not found
grub> find /boot/grub/menu.lst
Error 15: File not found
grub> root(hd0,7)
Error 27: Unrecognized command
grub> root (hd0,7)
Error 21: Selected disk does not exist
grub> setup (hd0)
Error 12: Invalid device requested
一个成功例子:
引用:
ubuntu@ubuntu:~$ sudo grub
[ 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> find /boot/grub/menu.lst
(hd0,7)
grub> root (hd0,7)
grub> 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)"... 15 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p (hd0,7)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
Done.
grub>quit

这是最简单的方法,也有其它几个寻找/boot分区的方法,但稍麻烦点:
在终端使用ls /dev/sd*和ls /hd*命令来查找系统的外部设置,用sudo mkdir命令来建立挂载目录,用sudo mount命令挂载,再用ls命令查看是否/boot所在的分区。
也可以用sudo fdisk -l来找到启动分区(这里不涉及将/boot单独分区的情况,因为那种我没有实验过,不太清楚),如:
引用:
ubuntu@ubuntu:~$ sudo fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2295 18434556 7 HPFS/NTFS
/dev/sda2 2296 19456 137845732+ f W95 Ext'd (LBA)
/dev/sda5 2296 4845 20482843+ 7 HPFS/NTFS
/dev/sda6 4846 8669 30716248+ 7 HPFS/NTFS
/dev/sda7 8670 16557 63360328+ 7 HPFS/NTFS
/dev/sda8 * 16558 17361 6458098+ 83 Linux
/dev/sda9 17362 19393 16322008+ 83 Linux
/dev/sda10 19394 19456 506016 82 Linux swap / Solaris
就知道启动分区是/dev/sda8
有人可能会有疑问,在Linux系统中是用sda8来表示这个启动分区,而GRUB中则是用(hd0,7)表示,这是因为在新版的Ubuntu中系统将串口硬盘和并口硬盘都识别为sd,a表示第一硬盘,8表示第4个逻辑分区(1──4被分配给主分区,扩展分区里的逻辑分区从5开始计算)。而 Grub中则是用统一用hd代表硬盘,硬盘号与分区号都是从0开始计算的。
这部分是凭记忆写的,可能不准确,请参考wiki。
PS:
看到有的帖子说Alterate CD可以在boot后输入linux rescue来启动救援盘,后面的操作则一样。我因手头没有Alterate CD无法验证。DVD虽说集成了Alterate CD与Desktop CD,但无法在以字符界面安装时启动救援盘。
感谢雕雕补充:
雕啸长空 写道:
补充一点,上面讲的是在/boot下面的东西都还完好的,但如果RP不行,/boot都玩完了,可以试一下下面的:
生成/etc/mtab
代码:
sudo grep -v rootfs /proc/mounts >sudo tee /etc/mtab
安装grub到mbr
代码:
grub-install --no-floppy /dev/hda
然后就自己搞定menu.lst了.
来源:
http://forum.ubuntu.org.cn/viewtopic.php?t=65991


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/20483/showart_453663.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP