Fedora使用LivdCD修复grub2

转自 http://cryinstall.com/?p=121和 http://linuxandfriends.com/2011/11/12/how-to-reinstall-grub2-chroot-into-a-linux-partition/,部分内容原创

如果LiveCD不知为何物,请百度
如果知LiveCD不知如何制作,请百度
如果做好LiveCD不知如何用其引导,请百度
 
【为了照顾一些刚想玩fedora的奋斗青年,省去你的百度时间吧】
step1:http://fedoraproject.org/  下载600多M的livecd镜像文件,首页是32位,你可以点更多下载64位
step2:https://fedorahosted.org/liveusb-creator/ 下载liveusb的制作软件,官方的。
step3:准备一个U盘,(里面有数据也没关系,制作的时候不像pe,会把你格式化,他保留原有数据),
用那个软件选择刚才你下载好的ISO,然后选择你的U盘盘符,persistent storage 选择个100M(这个相当于
Livecd里的/home挂载点,除了这个之外的其他挂载点是不用写入的U盘的),点击creat就可以完成制作了。
step4:调整你的bios启动顺序或者现在笔记本都支持quick boot,选择U盘启动就可以了。
启动后会出现start fedora 16 ,按回车就可以进入了

【有些U盘用官方的windows版本liveusb creator制作之后会启动不了,

将U盘下/syslinux/syslinux.cfg文件修改,

将其中的UUID=XXXX-XXXX,X的数字各个U盘不同,改成LABEL=LIVE,

如果还不行换个U盘尝试。或者到

http://unetbootin.sourceforge.net/下载这个软件尝试】
【进入之后默认是英文,如果你英文不好请单击屏幕右上角的live用户名,选择system settings,然后
选择region and  language(单击即可),在出来的对话框选中 chinese。再去右上角单击用户名,log out,
注销之后会问你是否更改home下面的文件夹名字,我建议不要该成中文,因为这样你在shell里面比较麻烦】
用LiveCD启动之后,首先应该明确的是你的fedora装在哪个分区,现在的硬盘都应该是sata的吧,那么就对应
/dev/sdax,x是个数字,1~4表示主分区,5开始是逻辑分区。如果你在可伶的用着IDE硬盘,那么就对应/dev/hdax
打开你的磁盘实用工具,或者叫Disk unity,找到fedora安装所在分区,我的在sda10,所以下面就拿这个说明了。。
su
mount -t ext4 -o rw /dev/sda10   /media
把fedora的安装分区挂载到当前的LiveCD文件系统下,当然如果你比较偷懒的话,比如我:),直接在文件管理器里面双击
一下那个分区,然后就会在/media/_FEDORA_*** 下挂载了
原来安装在硬盘上的fedora只是把文件目录挂上来了,一点硬件资源也木有,啥事也干不了,只能用来copy/paste一下数据,
现在把当前系统的资源给他
su
mount -t proc none /media/proc
mount -o bind /dev /media/dev
mount -o bind /sys /media/sys
mount -t devpts devpts /media/dev/pts
特别看清楚上面的指令,千万别把 /dev 写成了/dev/,如果这样就会出现
/dev is not a block device了
挂完后用chroot命令切换到原来的fedora中去
 
su
chroot /media
grub2-install /dev/sda
当然上述指令是讲grub2安装到硬盘MBR上恢复引导,如果你想装在当前分区中让其他软件来引导就应该是
grub2-install /dev/sda10
OK,做下扫尾工作
 
exit
umount /media/proc
umount /media/dev/pts
umount /media/sys
umount /media/dev
umount /media
reboot
当然,上述修复的grub是原来的grub,opensuse没了,其实grub2很强大,能自动识别n多系统,只需重新生成配置
文件即可。
su
grub2-mkconfig  -o  /boot/grub2/grub.cfg
reboot
congratulations
今天在帮别人修复的时候,又遇到一些问题,写下来分享
首先:这台电脑的分区并不是我上面写的简单的一个 / 分区,用的LVM和一个boot分区(sda8),那么在挂载的时候就要分别挂载了。在LVM里有一个 root的逻辑卷组和一个swap卷组,位于/dev/mapper/vg_fedora_root,和/dev/mapper/vg_fedora_swap(这个的取名是自己定义的,如果采用系统自己默认的分区安装,不是手动的话,名字不同)
 
su
mount -o rw  /dev/mapper/vg_fedora_root   /media
mount -o rw /dev/sda8  /media/boot
然后挂载上述写的资源。
其次:在执行grub2-install 的时候,遇到错误
[root@Fedora sunhao]# grub2-install /dev/sda
/sbin/grub2-setup: warn: Your embedding area is unusually small.  core.img won't fit in it..
/sbin/grub2-setup: warn: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
/sbin/grub2-setup: error: will not proceed with blocklists.
网上查的是mbr和sda1之间的那块embedding area太小了,应该是默认的63,如果是32的话会出现这个问题,但是我执行fdisk  -lu,显示这电脑已经是63了,不明原因。
google了一把,没找到解决方案还是安装不上去,后来我在wiki上面,看到了这个用法,强制安装。
grub2-install  --force  /dev/sda

竟然可以装上去,并且成功启动~


英文版转载:

This guide teaches you how to install/re-install GRUB2 in Linux. GRUB2 is a boot loader that is used
to install Windows and Linux on the same PC.
What is chroot ?
chroot is a tool that allows you to run a command or interactive shell with a different root directory.
The Scenario



Partition table of my PC
The picture above shows my machine’s partition. As you can see, I have installed Ubuntu GRUB2 in
the MBR (Master Boot Record). In the first partition, I have Windows 7, in the next partition Ubuntu
11.10, then comes the Swap partition, and lastly in the fourth partition, I have Fedora 16.
Install GRUB2 in Boot Partition
As an example, I will show you how to install GRUB2 in the boot partition of Fedora which in my case
is/dev/sda4.
These are the steps to follow :
Step 1 : Boot into Ubuntu
Step 2 : Mount the partition containing Fedora 16 (/dev/sda4)
$ sudo mount -t ext4 -o rw /dev/sda4 /media
The above command will mount the /dev/sda4 partition into the /media directory in Ubuntu and will
give you read write access.
Step 3 : Next you have to mount the following paths in the respective locations in the /media namely
–/dev, /sys, proc, and devpts.
$ sudo mount -t proc none /media/proc
$ sudo mount -o bind /dev /media/dev
$ sudo mount -o bind /sys /media/sys
$ sudo mount -t devpts devpts /media/dev/pts
Step 4 : chroot into the Fedora partition
$ sudo chroot /media
Now you get access to the root shell of the Fedora partition. From now on, any command you execute
in this shell will be run in relation to the Fedora distro and not Ubuntu.
Step 5 : Install GRUB2 in the boot partition of Fedora
# grub2-install --force /dev/sda4
Note: You have to use the --force flag to force the installation of GRUB2 in the boot partition. Or else
it gives an error.
Step 6 : Lastly come out of the chrooted shell and un-mount the /media directory.
# exit
Back in Ubuntu environment, un-mount the previously mounted directories by running the following
series of commands.
$su
#umount /media/proc
#umount /media/dev/pts
#umount /media/sys
#umount /media/dev
#umount /media
Finally, GRUB2 has been installed in the boot partition of Fedora 16.
Note : The above procedure can be used to fix MBR as well. The only difference being, ins

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值