📄 系统引导管理器grub学习笔记 linuxsir_org.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://www.linuxsir.org/main/?q=node/130 -->
<HTML lang=zh-hans xml:lang="zh-hans"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>系统引导管理器GRUB学习笔记 | LinuxSir.Org</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css media=all>@import url( misc/drupal.css );
</STYLE>
<STYLE type=text/css media=all>@import url( modules/taxonomy_context/taxonomy_context.css );
</STYLE>
<LINK media=screen
href="系统引导管理器GRUB学习笔记 LinuxSir_Org.files/menuExpandable3.css" type=text/css
rel=stylesheet>
<SCRIPT src="系统引导管理器GRUB学习笔记 LinuxSir_Org.files/menuExpandable3.js"
type=text/javascript></SCRIPT>
<LINK href="系统引导管理器GRUB学习笔记 LinuxSir_Org.files/common.css" type=text/css
rel=stylesheet>
<STYLE type=text/css media=all>@import url( themes/chameleon/marvin/style.css );
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY>
<DIV id=header><A title=Home href="http://www.linuxsir.org/main/"><IMG alt=Home
src="系统引导管理器GRUB学习笔记 LinuxSir_Org.files/logo.jpg"></A></DIV>
<DIV class=navlinks>
<DIV class=primary><A href="http://www.linuxsir.org/main/?q"><FONT
color=white>首页</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/34"><FONT
color=white>事件</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/"><FONT
color=white>文档</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/"><FONT
color=white>资源</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=search"><FONT color=white>搜索</FONT></A> |
<A href="http://www.linuxsir.org/bbs"><FONT color=white>论坛</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/38"><FONT
color=white>贡献者</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=node/3"><FONT color=white>关于</FONT></A> |
<A href="http://www.linuxsir.org/main/?q=user"><FONT
color=white>注册/登录</FONT></A></DIV></DIV>
<TABLE id=content>
<TBODY>
<TR>
<TD id=sidebar-left>
<DIV class="block block-block" id=block-block-1>
<H2 class=title>子站索引</H2>
<DIV class=content>
<UL>
<LI><A href="http://fedora.linuxsir.org/" target?_blank?>Fedora中文</A>
<LI><A href="http://debian.linuxsir.org/" target?_blank?>Debian中文</A>
<LI><A href="http://lfs.linuxsir.org/" target?_blank?>LFS 中文</A>
<LI><A href="http://slack.linuxsir.org/">Slackware</A>
<LI><A href="http://gentoo.linuxsir.org/">Gentoo中文</A>
<LI><A href="http://arch.linuxsir.org/">Arch 中文</A> </LI></UL></DIV></DIV>
<DIV class="block block-block" id=block-block-3>
<H2 class=title>重要资讯</H2>
<DIV class=content>
<UL>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/36">本站公告</A>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/34">新闻事件</A>
<LI><A href="http://www.linuxsir.org/bbs" target=_blank>本站论坛</A>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/38">贡 献 者</A>
</LI></UL></DIV></DIV>
<DIV class="block block-block" id=block-block-7>
<H2 class=title>项目索引</H2>
<DIV class=content>
<UL>
<LI><A href="http://www.fcitx.org/" target=_blank>小企鹅输入法</A>
<LI><A href="http://lumaqq.linuxsir.org/" target=_blank>LumaQQ</A>
<LI><A href="http://openq.linuxsir.org/" target=_blank>OpenQ</A>
<LI><A href="http://www.relaxbsd.org/" target=_blank>RelaxBSD</A>
</LI></UL></DIV></DIV>
<DIV class="block block-user" id=block-user-1>
<H2 class=title>站点导航</H2>
<DIV class=content>
<DIV class=menu>
<UL>
<LI class=leaf><A title=注册/登录
href="http://www.linuxsir.org/main/?q=user">注册/登录</A>
<LI class=collapsed><A
href="http://www.linuxsir.org/main/?q=aggregator">新闻聚合</A>
</LI></UL></DIV></DIV></DIV>
<DIV class="block block-aggregator" id=block-aggregator-feed-2>
<H2 class=title>LinuxSir.Org 论坛</H2>
<DIV class=content>
<DIV class=item-list>
<UL>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266922&goto=newpost">如何在FvwmButtons中使用系统托盘?</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266921&goto=newpost">FC5
root 的垃圾箱被彻底删掉了,怎么恢复?</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266920&goto=newpost">我想做一个mini
linux 该怎么下手呢~</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266919&goto=newpost">FC5体验之影音篇</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266918&goto=newpost">请教高手:FEDORA
4 安装问题</A> </LI></UL></DIV>
<DIV class=more-link><A title=查看此feed的最新消息
href="http://www.linuxsir.org/main/?q=aggregator/sources/2">更多</A></DIV></DIV></DIV>
<DIV class="block block-user" id=block-user-2>
<H2 class=title>最新注册</H2>
<DIV class=content>
<DIV class=item-list>
<UL>
<LI>horiwa
<LI>jiechu
<LI>emiss
<LI>ismart
<LI>mynamewsy</LI></UL></DIV></DIV></DIV>
<DIV class="block block-user" id=block-user-3>
<H2 class=title>当前在线</H2>
<DIV class=content>0 users 和 84 游客 在线</DIV></DIV></TD>
<TD id=main>
<DIV class=breadcrumb><A href="http://www.linuxsir.org/main/?q=">首页</A> »
<A href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A></DIV>
<H2>系统引导管理器GRUB学习笔记</H2><!-- begin content -->
<DIV class=node>
<DIV class=content>
<P><B>作者:</B>probing<BR><B>来自:</B>LinuxSir.Org<BR><B>点评:</B>本文是probing兄弟的GRUB的学习笔记,用他自己的话来说“本笔记并非原创,只是我个人的学习笔记!”,本文对GRUB技术实现和理论都有解说,也很精辟;但遗憾的是文档的结构和排版不太明晰,这为初学者在阅读上带来一定困难;在LinuxSir.Org
论坛整理出来的时候,本想按我的意图来进行结构调整,但最后发现没有办法调整;调整结构就意味着大面积重写,所以只好作罢;</P>
<P>声明:本文档归属 linuxsir.org -probing!转载请注明出处!更不能被用到商业用途上!</P>
<P>本笔记并非原创,只是我个人的学习笔记!很多的内容来自 linuxsir.org linuxfans.org linuxAID.com</P>
<P>非常感谢以上网站对我的学习提供的莫大的帮助,本着学习和分享的原则我贴出我的学习笔记,更希望兄弟们能给我指出其中错误的地方.谢谢!!!<BR>学习这部分知识,首先要学到问题的思路,其次你还要记住一些东西,是死记硬背下来!你会发现这点东东的确是很有用的!</P>
<P><FONT size=4><B><BR>一、 首先要了解的几个概念<BR></B></FONT></P>
<P>1、 启动管理器<BR>启动管理器是存储在磁盘开始扇区中的一段程序,例如,硬盘的MBR(Master Boot
Record),在系统完成启动测试后,如果系统是从MBR启动,则BIOS(Basic Input/Output
System)将控制传送给MBR。然后存储在MBR中的这段程序将运行。这段程序被称为启动管理器。它的任务就是将控制传送给操作系统,完成启动过程》有许多可用的启动管理器,包括GNU
GRUB (Grand Unified Boot Loader),Bootmanager, LILO (LInux LOader), NTLDR
(boot loader for Windows NT systems),等等等.</P>
<P>2、 什么是GRUB?<BR>grub 是一个多重启动管理器。grub是GRand Unified
Bootloader的缩写,它可以在多个操作系统共存时选择引导哪个系统。它可以引导的操作系统包括:Linux,FreeBSD,Solaris,NetBSD,BeOSi,OS/2,Windows95/98,Windows
NT,Windows2000,WinXP。它可以载入操作系统的内核和初始化操作系统(如Linux,FreeBSD),或者把引导权交给操作系统(如
Windows 98)来完成引导。</P>
<P>3、 GRUB的特点</P>
<P>1)特别适用于linux与其它操作系统共存情况。</P>
<P>支持大硬盘现在大多数Linux发行版本的lilo都有同样的一个问题:根分区(/boot分区)不能分在超过1024柱面的地方,一般是在8.4G左右的地方,否则lilo不能安装,或者安装后不能正确引导系统。而grub就不会出现这种情况,只要安装时你的大硬盘是在LBA模式下,grub就可以引导根分区在
8G以外的操作系统。</P>
<P>2)支持开机画面 </P>
<P>grub支持在引导开机的同时显示一个开机画面。对于玩家来说,这样可以制作自己的个性化开机画面;对于PC厂商,这样可以在开机时显示电脑的一些信息和厂商的标志等。grub支持640x480,800x600,1024x768各种模式的开机画面,而且可以自动侦测选择最佳模式,与Windows那
320x400的开机画面不可同日而语。</P>
<P>3)两种执行模式 </P>
<P>grub不但可以通过配置文件进行例行的引导,还可以在选择引导前动态改变引导时的参数,还可以动态加载各种设备。例如你在Linux下编译了一个新的核心,但不能确定它能不能工作,你就可以在引导时动态改变grub的参数,尝试装载这个新的核心进行使用。Grub的命令行有非常强大的功能,而且支持如
bash或doskey一样的历史功能,你可以用上下键来寻找以前的命令。</P>
<P>4)菜单式选择 </P>
<P>grub使用一个菜单来选择不同的系统进行引导。你还可以自己配置各种参数,如延迟时间,默认操作系统等。</P>
<P>5)分区大小改变后不必重新配置 </P>
<P>grub是通过文件系统直接把核心读取到内存,因此只要操作系统核心的路径没有改变,grub就可以引导系统。<BR>除此之外,Grub还有许多非常强大的功能。例如支持多种外部设备,动态装载操作系统内核,甚至可以通过网络装载操作系统核心。Grub支持多种文件系统,支持多种可执行文件格式,支持自动解压,可以引导不支持多重引导的操作系统,支持网络启动等。</P>
<P>6) MBR和第一扇区</P>
<P>你可以简单的理解为MBR是整个硬盘的物理第一位置,而第一扇区是硬盘的物理第二位置.</P>
<P>7) 一个GRUB配置文件</P>
<P>基于本例的分区如下:<BR>
<DIV class=codeblock><CODE>hda 15G<BR>hda1 8G / RED HAT LINUX8.0<BR>hda5
7G /home<BR>hdc 20G<BR>hdc1 6.4G WinXP<BR>hdc5 6.4G<BR>hdc6 6.4G<BR>hdc7
6.4G</CODE></DIV><BR>
<DIV class=codeblock><CODE>#fdisk -l<BR># Disk /dev/hdc: 255 heads, 63
sectors, 2434 cylinders<BR>Units = cylinders of 16065 * 512
bytes<BR>Device Boot Start End Blocks Id System<BR>/dev/hdc1 * 1 894
7181023+ b Win95 FAT32<BR>/dev/hdc2 895 2434 12370050 f Win95 Ext'd
(LBA)<BR>/dev/hdc5 895 1787 7172991 b Win95 FAT32<BR>/dev/hdc6 1788 2434
5196996 b Win95 FAT32<BR>Disk /dev/hda: 255 heads, 63 sectors, 1867
cylinders<BR>Units = cylinders of 16065 * 512 bytes<BR>Device Boot Start
End Blocks Id System<BR>/dev/hda1 * 1 1020 8193118+ 83 Linux<BR>/dev/hda2
1021 1802 6281415 83 Linux<BR>/dev/hda3 1803 1867 522112+ 82 Linux
swap</CODE></DIV>
<P></P>
<P>grub.conf,这个文件位于;/boot/grub/grub.conf<BR>
<DIV class=codeblock><CODE># grub.conf generated by anaconda<BR>#<BR>#
Note that you do not have to rerun grub after making changes to this
file<BR># NOTICE: You do not have a /boot partition. This means that<BR>#
all kernel and initrd paths are relative to /, eg.<BR># root (hd0,0)<BR>#
kernel /boot/vmlinuz-version ro root=/dev/hda1<BR># initrd
/boot/initrd-version.img<BR>#boot=/dev/hda<BR>default=0<BR>timeout=3<BR>splashimage=(hd0,0)/boot/grub/splash.xpm.gz<BR>title
Red Hat Linux (2.4.18-14)<BR>root (hd0,0)<BR>kernel
/boot/vmlinuz-2.4.18-14 ro root=LABEL=/<BR>initrd
/boot/initrd-2.4.18-14.img<BR>title Microsoft Windows XP<BR>map (hd0)
(hd1)<BR>map (hd1) (hd0)<BR>root (hd1,0)<BR>chainloader
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -