﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-Think and Grow rich－－－－－－－－－－－－－－－－－－－－－－－-文章分类-Linux Technology 讨论</title><link>http://www.cnitblog.com/watermelonbig/category/821.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Sep 2011 15:07:06 GMT</lastBuildDate><pubDate>Tue, 27 Sep 2011 15:07:06 GMT</pubDate><ttl>60</ttl><item><title>全面接触GRUB</title><link>http://www.cnitblog.com/watermelonbig/articles/3256.html</link><dc:creator>大西瓜</dc:creator><author>大西瓜</author><pubDate>Wed, 12 Oct 2005 01:05:00 GMT</pubDate><guid>http://www.cnitblog.com/watermelonbig/articles/3256.html</guid><wfw:comment>http://www.cnitblog.com/watermelonbig/comments/3256.html</wfw:comment><comments>http://www.cnitblog.com/watermelonbig/articles/3256.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/watermelonbig/comments/commentRss/3256.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/watermelonbig/services/trackbacks/3256.html</trackback:ping><description><![CDATA[全面接触GRUB<br>
<br>
<br>
我们把这个目录称作image directory：/usr/share/grub/i386-redhat<br>
<br>
我们把这个目录称作boot directory：/boot/grub/<br>
<br>
<br>
一、创建一个GRUB启动软盘方法：<br>
<br>
#cd /usr/share/grub/i386-redhat<br>
<br>
#dd if=stage1 of=/dev/fd0 bs=512 count=1<br>
<br>
#dd if=stage2 of=/dev/fd0 bs=512 seek=1<br>
<br>
该启动软盘将把系统引导进入一个grub命令提示符的界面；这种方法制作的启动软盘不具有可读的文件系统格式，不能挂接。<br>
<br>
二、本地安装GRUB的方法：<br>
<br>
首先准备一张GRUB启动软盘并软盘启动，<br>
<br>
grub&gt; root (hd0,0)&nbsp;&nbsp; &nbsp;指定boot所在分区，如果不能确认boot在哪个分区可以使用find进行查找，<br>
<br>
grub&gt; find /boot/grub/stage1&nbsp;&nbsp; &nbsp;如果boot是单独一个分区则应该去掉路径/boot<br>
<br>
grub&gt; setup (hd0)&nbsp;&nbsp; &nbsp;将GRUB安装在MBR，如果希望安装在某个分区始端则，<br>
<br>
grub&gt; setup (hd0,?)&nbsp;&nbsp; &nbsp;GRUB将作为辅助引导程序使用<br>
<br>
<br>
三、使用grub-install安装GRUB的方法：<br>
<br>
#grub-install /dev/hda<br>
<br>
#grub-install --root-directory=/boot /dev/hda&nbsp;&nbsp; &nbsp;当/boot被单独列为一个分区时，有必要指出<br>
<br>
#grub-install --root-directory=/media/floppy fd0&nbsp;&nbsp; &nbsp;需要事先准备好一张软盘，格式化为ext2，挂接好。这个命令创建了一张GRUB启动盘，该盘具有ext2文件系统。<br>
<br>
grub-install是一个shell脚本，在其识别系统中的硬件设备时存在发生错误的风险，不建议使用这种方式安装GRUB。<br>
<br>
<br>
四、GRUB直接装载系统的步骤：<br>
<br>
1、Set the GRUB's root device with the command 'root' . For example, root (hd0,0)<br>
<br>
2、Load the kernel image with the command 'kernel' . For example, kernel /vmlinuz-version ro root=/dev/sda2<br>
<br>
3、Load the initrd image with the command 'initrd' . For example, initrd /initrd-version<br>
<br>
4、Run the command 'boot'<br>
<br>
注：initrd 是inittal ramdisk的缩写，这个命令作用是'Load an initial ramdisk for a
Linux format boot image and set the appropriate parameters in the Linux
setup area in memory.'<br>
<br>
<br>
五、GRUB间接装载其它系统的步骤(如windows)：<br>
<br>
原理是GRUB先调用另外一个引导软件，这个引导软件应该已经被装在某一个分区的“boot sector”<br>
<br>
1、grub&gt; rootnoverify (hd0,0)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'Set GRUB's root device without mounting'<br>
<br>
2、grub&gt; makeactive<br>
<br>
3、grub&gt; chainloader +1<br>
<br>
&nbsp;&nbsp; &nbsp;"+1" , GRUB将读取指定分区的第一个sector中数据。<br>
<br>
4、grub&gt; boot<br>
<br>
<br>
六、GRUB的安全性：<br>
<br>
GRUB可以支持明文密码和md5加密的密码。<br>
<br>
使用明文密码方法&nbsp;&nbsp; &nbsp;password PASSWORD<br>
<br>
使用md5加密密码方法&nbsp;&nbsp; &nbsp;password --md5 PASSWORD<br>
<br>
生成md5算法密码的方法&nbsp;&nbsp; &nbsp;grub&gt; md5crypt&nbsp;&nbsp; &nbsp;[回车]<br>
<br>
编辑/boot/grub/grub.conf，使用password,lock命令实现几种加密方法如下：<br>
<br>
1) 单纯对GRUB界面加密，而不对被引导的系统加密<br>
<br>
在timeout一行下面加一行： password --md5 PASSWORD<br>
<br>
2) 对GRUB界面加密，同时对被引导的系统加密<br>
<br>
在timeout一行下面加一行： password --md5 PASSWORD<br>
<br>
在title一行下面加一行： lock<br>
<br>
3) 同时存在多个被引导系统，针对特定的系统实例分别加密(未对GRUB操作界面加密)<br>
<br>
在title一行下面加一行： lock<br>
<br>
在lock一行下面紧贴着再加一行： password --md5 PASSWORD<br>
<br>
注：lock不能单独使用<br>
<br>
<br>
七、GRUB image 文件：<br>
<br>
stage1,stage2是最重要的两个映像文件；<br>
<br>
stage1 的全部工作就是装载stage2(或者stage1.5)。PC的启动扇区(boot sector)大小是512字节，stage1的大小也是512字节，所以stage1可以被恰好嵌入在boot sector中。<br>
<br>
stage1 以扇区列表格式(block list format)将stage2的地址信息存储起来。<br>
stage1 encodes the location of stage2(or stage1.5) in a block list format.stage1 can not understant any filesystem structure.<br>
<br>
stage2 是GRUB的核心映像文件。它负责除启动自己以外的其它所有工作。stage2有文件系统格式无关性。<br>
<br>
stage1.5 是一个桥文件。stage1.5有一系列文件，每个都只支持某一个类型的文件系统。stage1不支持任何类型的文件系统。stage1装载stage1.5, stage1.5装载stage2。<br>
<br>
<br>
八、什么是block list format<br>
<br>
这是用于寻址定位一些未存放在任何文件系统中的文件的方法。比如chainloader。<br>
<br>
它的格式是&nbsp;&nbsp; &nbsp;[起点]+长度[,[起点]+长度]....&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;'0+100,200+1,300+300' 这代表GRUB将读取block0--blcok99, block200, block300--block599 。<br>
<br>
<br>
<img src ="http://www.cnitblog.com/watermelonbig/aggbug/3256.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/watermelonbig/" target="_blank">大西瓜</a> 2005-10-12 09:05 <a href="http://www.cnitblog.com/watermelonbig/articles/3256.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>