grub menu.list配置


grub menu.list配置
 
因重装系统,把GRUB引导菜单搞没了,一直不知道怎么找回来,今天看到贴子,试了下,成功了,主要步骤是下边兰字部分t
 
而恢复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,时连按两下Tab列出可用分区,自己确定是哪个分区。
如果是将/boot单独分区,详见说明。
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了.
 

相关内容

    暂无相关文章