Linux Grub的相关问题

Linux Grub的相关问题

我的电脑是双系统的,分别是:win7和Ubuntu12.04.5LTS

GRUB2 配置工具Grub Customizer 修改启动引导界面

作用:
可以修改开机引导项,删除,更改顺序等 。

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer

之后就可以在应用中心搜索到:
Grub Custmizer

参考链接:
1. Grub Customizer :GRUB2 配置工具 | BURG :修改启动引导界面
http://linux.cn/thread/7195/1/1/

win7和Ubuntu双系统开机出现grub>,该如何修复

由于Ubuntu系统重新安装了,导致引导文件menu.lst缺失,开机出现grub>,这次我用liveCD重新安装了grub,还是没解决问题,看来要进入系统修复了。

这里要分两步:
1. 首先进入Ubuntu系统
2. 修复grub缺失文件

进入Ubuntu系统

要想进入win7是比较简单的,只需下面的grub命令就可以了.

grub> rootnoverify (hd0,0)  #f由于我的win7安装在C盘
grub> chainloader +1
grub> makeactive  #C盘如果是活动分区的话这一步可以省略
grub> boot

对于Ubuntu来说,根据/boot目录有没有单独分区,分为两种不同情况
1, /boot和Linux的/根在同一个分区
这时可以用类似的如下grub命令

grub> root (hd0,5)  #包含/boot的分区
grub> kernel /boot/vmlinuz-version ro root=/dev/sda6         #/dev/sda6为  /根目录 所在的分区
#由于(hd0,y)从0,1,2,3,开始计数,而 sda[y]从1,2,3开始计数,所以一般这个数值比上面的大1
grub> initrd /boot/initrd-version.img
grub> boot

2, /boot独立一个分区,和Linux的根分区不是同一个分区
这时可以用类似的如下grub命令

grub> root (hd0,7) #/boot所在的分区
grub> kernel /vmlinuz-version ro root=/dev/sda10     #/dev/sda10为  /根目录 所在的分区
grub> initrd /initrd-version.img
grub> boot

我的Ubuntu是后来装的,新手,所以分区较乱,总共分了三个区swap, /boot(分区名为(hd0,7),/dev/sda8), /(分区名为(hd0,9), /dev/sda10).当然如果不知道,通过下面的方法会找到的.

你可以利用通过cat命令+TABTAB键来查看你的各个分区及分区里面文件,从而判断哪个是/boot所在的分区,哪个/所在的分区.
比如

grub> cat (hd0,TAB

会列出你的各个分区信息,如图
这里写图片描述
再通过

gurb> cat (hd0,7)/TAB键
grub> cat (hd0,9)/TAB

可以看到其中的两个linux分区里的文件,如图:
这里写图片描述
这时就能判断出/boot 所在分区为(hd0,7), / 所在分区为(dh0,9).

如何判断/boot和/的/dev/sday分区名呢,可以用下面的命令查看挂载信息(当然也可以用U盘制作的LiveCD,进入U盘里的Ubuntu系统通过 fdisk -l, cat /etc/fstab,df -lh 命令判断出分区信息).

grub> cat (hd0,9)/etc/fstab  #(hd0,9)为/所在分区名

这时就能判断我的/boot在/dev/sda8, / 在/dev/sda10

接下来,根据上面所说第二种情况,以用cat出的(hd0,7)中的vmlinuz和initrd文件名,就可以利用下面命令进入我的Ubuntu了

grub> root (hd0,7) #/boot所在分区
grub> kernel /mlinuz-3.13.0-52-generic ro root=/dev/hda10 (/ 所在分区, ro表示只读)
grub> initrd /initrd.img-3.13.0-52-generic
grub> boot

也可以写成

grub> kernel (hd0,7)/mlinuz-3.13.0-52-generic ro root=/dev/hda10 (/ 所在分区, ro表示只读)
grub> initrd (hd0,7)/initrd.img-3.13.0-52-generic
grub> boot

OK,成功进入我的Ubuntu系统

修复引导文件

执行命令

$ls -la /boot/grub/

发现我有grub.cfg文件,但是没有menu.lst文件(下面的命令执行中出现Could not find /boot/grub/menu.lst file)。这时你当然自己写一个menu.lst文件就可以了。

我是通过更新grub,再写入mbr实现的。

zsh@Ubuntu12:~$ sudo update-grub
[sudo] password for zsh: 
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... 

Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) y
Searching for splash image ... none found, skipping ...
Found kernel: /memtest86+.bin
Found kernel: /vmlinuz-3.13.0-52-generic.efi.signed
Found kernel: /vmlinuz-3.13.0-52-generic
Found kernel: /vmlinuz-3.13.0-32-generic
Found kernel: /memtest86+.bin
Updating /boot/grub/menu.lst ... done

zsh@Ubuntu12:~$ sudo grub-install /dev/sda
Searching for GRUB installation directory ... found: /boot/grub
Installing GRUB to /dev/sda as (hd0)...
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'.

(fd0)   /dev/fd0
(hd0)   /dev/sda
(hd1)   /dev/sdb

这样就好了,你可以根据自己的情况更改menu.lst里面的文件,加入win7引导项,设置等待时间等。

开机效果(按ESC进入选单界面):
这里写图片描述

参考链接
1. fedora和ubuntu共存问题,修改grub的menu.lst (很全面)
http://blog.csdn.net/yueyinggufan/article/details/4342396
2. GRUB入门教程
http://www.linuxeden.com/forum/thread-72651-1-1.html (楼)

win7里装了Ubuntu后开机出现grub rescure>, 用livecd修复grub2

用LiveCD修复Grub2的具体方法如下:
1. 用Ubuntu9.10 Grub2光盘启动系统;
2. 打开终端,输入终端命令:sudo fdisk -l (查看计算机分区列表)
请记录下来根分区 / 和 /boot 分区安装的位置(我的根分区位于/dev/sda6,/boot没有单独分区(若有则假设位于/dev/sda7)),

下面就以我的分区为例说明,请大家根据自己的磁盘分区情况进行相应修改;
3. 在终端输入命令:

sudo -i        (取得root特权)
mount /dev/sda6 /mnt
mount /dev/sda7 /mnt/boot  (如果/boot没有单独分区则不要执行这个命令)
grub-install --root-directory=/mnt/ /dev/sda   (注意此命令中root前面是两个减号横杠)

输入以后如果出现“Installation finished.No Error Reported.”字符的时候,就表示操作成功了。

参考链接:
1. 用livecd修复grub2
http://www.douban.com/note/93786640/
2. Ubuntu Grub2修复LiveCD实现方法详解
http://blog.sina.com.cn/s/blog_8020e4110101cc0r.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值