[分享]Linux与Windows双系统下的Grub引导管理器安装——boot.ini与menu.lst的例解
-
- 帖子: 515
- 注册时间: 2006-05-20 10:38
关于分区和安装的一篇英文习作
一篇英文小作文,不用汉语,很难把一些细节说清楚,把它当成一些tips好了,请拍砖,:)
How to Install Linux into Your Computer
By Yue Xiaoyong
Although Linux is free, safe and flexible without virus and Trojan, you haven't wanted to try it because you hear that Linux is difficult to install even if it will damage your data in hard disk. If this is your excuse to refuse Linux, please give me 15 minutes to tell you how to install Linux into your computer correctly. The install of Linux is not difficult if you follow me. For getting Linux installation cdrom, you can download the cdrom image of the newest updated Ubuntu from http://cdimage.ubuntu.com and burn it; Ubuntu is the most popular Linux distribution at present. The important steps in installation are partition and GRUB.
Firstly, you need to plan and prepare your hard disk partition carefully. Yeah, plan not just try. Linux usually need three or four partitions. One is / (root), system and program files are put in it. Another is /home, users save their data in it. The last is swap partition, used to exchange data to hard disk when your physical memory is not enough. Additionally, you can create the /boot partition that is used to boot your system. It is not necessary; if you don't create it, it doesn't matter. I suggest these Linux partition should be created under the Linux environment. For entering Linux before installation, you can boot Linux live CD such as Ubuntu desktop after appointing cdrom to first boot in BIOS. When you are under Linux, using #fdisk /dev/hda in terminal create partitions.
Now there are some GUI (graphic user interface) software to divide partition, but #fdisk /dev/hda still is the safest way. For example, the install program on Ubuntu desktop is beautiful but not dependable. Some programs like PQmagic or Paragon are powerful, which claim they can repartition without damaging your data in hard disk. If you don't use them, it would be best. Please remember: the most dangerous action among operations is repartition. Of course, you can try them if you don't care your data.
After repartition, you can start your installation truly. As I said, you can boot Linux with cdrom like Ubuntu desktop or Ubuntu alternative. Ubuntu is the excellent distribution in the world of Linux, which supports two different kinds of installation. They are Ubuntu desktop and Ubuntu alternative. Ubuntu alternative is a classical and conversational way. Ubuntu desktop is more simple and fast than Ubuntu alternative, but it is not reliable as Ubuntu alternative. So I suggest you to use the latter. The process is automatic. You will be asked to choose language, keyboard and time zone etc. Installation is very simple and clear; you needn’t to stare the screen. When the question where you want to install Linux appears, be careful; just choosing the correct partition that you had prepared.
But the procedure won't end till you install GRUB. GRUB is the program to load Linux into memory; you can simply name it as loader. When your computer is turned on, it will start system self-examine from BIOS. After self-examine, GRUB will load Linux. Then booting begins. However, there is a little trouble to set up GRUB. The point is choosing the place for GRUB. Generally, it is easier to put GRUB into MBR, which means master boot record, located in the first sector of the hard disk. But when you want to keep your Windows on the same computer, maybe it will lead some difficulties; especially your computer has the function to recovery the Windows in one keystroke. You also can put GRUB into your Linux root partition (/) or boot partition (/boot), the precondition is this partition must be the prime partition (not the extend partition) and this prime partition must be active. So, planing your disk partitions carefully is very important.
It isn't limited to put GRUB into extend partition for Linux. The trouble is GRUB can't be started automatically after system self-examine. Fortunately, you are able to use grub4dos to resolve it. Grub4dos is used to load GRUB in the Windows boot procedure without altering MBR. It is an extremely useful program written by Chinese programmers. Using grub4dos, you can keep your Windows with Linux peacefully at the same computer.
Look! You have installed Linux into your computer after set up GRUB. It is simple and easy, isn't it? You will get the perfect Linux as accurate as you can to follow the steps I told you. Now, it is time to experience your Linux. You will find: Linux make your life simpler, and its installation is not complex.
How to Install Linux into Your Computer
By Yue Xiaoyong
Although Linux is free, safe and flexible without virus and Trojan, you haven't wanted to try it because you hear that Linux is difficult to install even if it will damage your data in hard disk. If this is your excuse to refuse Linux, please give me 15 minutes to tell you how to install Linux into your computer correctly. The install of Linux is not difficult if you follow me. For getting Linux installation cdrom, you can download the cdrom image of the newest updated Ubuntu from http://cdimage.ubuntu.com and burn it; Ubuntu is the most popular Linux distribution at present. The important steps in installation are partition and GRUB.
Firstly, you need to plan and prepare your hard disk partition carefully. Yeah, plan not just try. Linux usually need three or four partitions. One is / (root), system and program files are put in it. Another is /home, users save their data in it. The last is swap partition, used to exchange data to hard disk when your physical memory is not enough. Additionally, you can create the /boot partition that is used to boot your system. It is not necessary; if you don't create it, it doesn't matter. I suggest these Linux partition should be created under the Linux environment. For entering Linux before installation, you can boot Linux live CD such as Ubuntu desktop after appointing cdrom to first boot in BIOS. When you are under Linux, using #fdisk /dev/hda in terminal create partitions.
Now there are some GUI (graphic user interface) software to divide partition, but #fdisk /dev/hda still is the safest way. For example, the install program on Ubuntu desktop is beautiful but not dependable. Some programs like PQmagic or Paragon are powerful, which claim they can repartition without damaging your data in hard disk. If you don't use them, it would be best. Please remember: the most dangerous action among operations is repartition. Of course, you can try them if you don't care your data.
After repartition, you can start your installation truly. As I said, you can boot Linux with cdrom like Ubuntu desktop or Ubuntu alternative. Ubuntu is the excellent distribution in the world of Linux, which supports two different kinds of installation. They are Ubuntu desktop and Ubuntu alternative. Ubuntu alternative is a classical and conversational way. Ubuntu desktop is more simple and fast than Ubuntu alternative, but it is not reliable as Ubuntu alternative. So I suggest you to use the latter. The process is automatic. You will be asked to choose language, keyboard and time zone etc. Installation is very simple and clear; you needn’t to stare the screen. When the question where you want to install Linux appears, be careful; just choosing the correct partition that you had prepared.
But the procedure won't end till you install GRUB. GRUB is the program to load Linux into memory; you can simply name it as loader. When your computer is turned on, it will start system self-examine from BIOS. After self-examine, GRUB will load Linux. Then booting begins. However, there is a little trouble to set up GRUB. The point is choosing the place for GRUB. Generally, it is easier to put GRUB into MBR, which means master boot record, located in the first sector of the hard disk. But when you want to keep your Windows on the same computer, maybe it will lead some difficulties; especially your computer has the function to recovery the Windows in one keystroke. You also can put GRUB into your Linux root partition (/) or boot partition (/boot), the precondition is this partition must be the prime partition (not the extend partition) and this prime partition must be active. So, planing your disk partitions carefully is very important.
It isn't limited to put GRUB into extend partition for Linux. The trouble is GRUB can't be started automatically after system self-examine. Fortunately, you are able to use grub4dos to resolve it. Grub4dos is used to load GRUB in the Windows boot procedure without altering MBR. It is an extremely useful program written by Chinese programmers. Using grub4dos, you can keep your Windows with Linux peacefully at the same computer.
Look! You have installed Linux into your computer after set up GRUB. It is simple and easy, isn't it? You will get the perfect Linux as accurate as you can to follow the steps I told you. Now, it is time to experience your Linux. You will find: Linux make your life simpler, and its installation is not complex.
-
- 帖子: 23
- 注册时间: 2007-09-15 12:10
-
- 帖子: 515
- 注册时间: 2006-05-20 10:38
-
- 帖子: 3
- 注册时间: 2007-11-10 19:57
首先强烈感谢lz。
我的机器装了linux,就启动不了windows。用fdisk/mbr恢复windows后,又找不到grub界面,进不了linux。重装grub后,又进不了windows。
如此循环往复。
我的问题转了好几个论坛,问了高手,折腾了两三个星期都没解决。
用lz介绍的grub4dos终于解决了。
但是还有一个问题,用lz在顶楼介绍的方法不行啊,
我已经把grub装在linux的根分区了(不像过去那样装在mbr上了)
然后用那2条语句创建linux.lnx,
然后在windows改boot。ini。
但是启动后,选择该菜单,报错——
下列文件丢失,windows无法启动,<windows root >\system32\hal.dll。
而我在c盘下也找不到创建的这个linux.lnx文件呀。
到底怎么回事呢?
我的机器装了linux,就启动不了windows。用fdisk/mbr恢复windows后,又找不到grub界面,进不了linux。重装grub后,又进不了windows。
如此循环往复。
我的问题转了好几个论坛,问了高手,折腾了两三个星期都没解决。
用lz介绍的grub4dos终于解决了。
但是还有一个问题,用lz在顶楼介绍的方法不行啊,
我已经把grub装在linux的根分区了(不像过去那样装在mbr上了)
然后用那2条语句创建linux.lnx,
然后在windows改boot。ini。
但是启动后,选择该菜单,报错——
下列文件丢失,windows无法启动,<windows root >\system32\hal.dll。
而我在c盘下也找不到创建的这个linux.lnx文件呀。
到底怎么回事呢?
-
- 帖子: 515
- 注册时间: 2006-05-20 10:38
If your partition is not fat32 file system, usually you can't have a power of write in it under linux. Of course, you don't have to write it to your C: partition if it isn't fat32. Just write it on any fat32/16 partition such as usb flashdisk. However, you must recognize the correct device name of this specic partition. If the type of your harddisk is IDE, the first usb flash disk partition usually is /dev/sda1; if the type of your harddisk is SATA, the first harddisk partition is /dev/sdb1, it means the name of first usb flash disk partition will be changed. You can check it from the kernel output, just input "$ sudo dmesg | tail" under terminal after pluging the flash disk into your computer.# mount -t vfat /dev/hda1 /mnt
# dd if=/dev/hdaX of=/mnt/linux.lnx bs=512 count=1
这2句代码是把Linux分区的512启动信息复制到C盘下的一个文件。但我的C盘是NTFS的,又没有软驱。能不能做一个变动:
把这512字节复制生成的文件放到一个FAT32分区中,到了windows再把这个文件复制到C:\下?
Maybe you should check if there is some wrong in your operation, especially the device name and type of your partition which you prepare to output linux.lnx in it. Is it /dev/hd1? Is it fat32? Maybe they are not the same in your computer.我已经把grub装在linux的根分区了(不像过去那样装在mbr上了)
然后用那2条语句创建linux.lnx,
然后在windows改boot。ini。
但是启动后,选择该菜单,报错——
下列文件丢失,windows无法启动,<windows root >\system32\hal.dll。
而我在c盘下也找不到创建的这个linux.lnx文件呀。
到底怎么回事呢?
Or you can just follow the steps in the 57th floor. It is really simple. Now I always use this method in stead of using linux.lnx.
I am sorry I have to use my poor English because I can't input Chinese character now.
上次由 xiaoyong 在 2008-02-15 15:03,总共编辑 1 次。
-
- 帖子: 2
- 注册时间: 2008-07-03 14:17
先装Ubuntu Server系统再装Windows xp不能找到Ubuntu启动项
请高手指点,可以用rescue mode 修复吗
-
- 帖子: 2
- 注册时间: 2008-07-03 14:17
Re: [分享]Linux与Windows双系统下的Grub引导管理器安装——boot.ini与menu.lst的例解
xiaoyong 写了:一直没有对本文再做修改,但在跟帖里还是有一些相关补充,今天整理一下,一并链接在这里,方便查阅(论坛的气氛还是很好的,感谢大家的关注):
1、关于引导序列的最为简明的评述,见32楼jacky-q,viewtopic.php?t=17047&postdays=0&postor ... =30#155597;
2、关于使用gurb4dos的简明步驟,见57楼我的回复,viewtopic.php?p=364013#361187;
3、建立和删除分区的推荐方式,见40楼我的回复,viewtopic.php?t=17047&postdays=0&postor ... =30#180472;
4、grub4nt的简单介绍,它是grub4dos的一部分,见45楼我的说明,viewtopic.php?t=17047&postdays=0&postor ... =30#206447;
5、关于Grub的原初安装,见36楼我的回复,viewtopic.php?t=17047&postdays=0&postor ... =30#162155;
6、如何把Grub安装到MBR上,见9楼我的回复,viewtopic.php?p=90681#90681;
7、关于硬盘分区和MBR的恢复(擦除Grub),见27楼我的回复,viewtopic.php?p=154501#154501;
8、就引导序列的讨论与网友xcity的讨论,见28楼至40楼,viewtopic.php?p=154501#154587;
9、我为什么写这篇文章,见60楼我的回复,viewtopic.php?p=364013#364013;
10、关于分区和安装的一些小提示,见63楼我的习作(英文,),viewtopic.php?t=17047&postdays=0&postor ... =60#368239。
2007年7月19日
添加一个附件,其中为本文的PDF和ODT格式的打印版本,方便大家下载阅读。
2007年4月29日
Linux与Windows双系统下的Grub引导管理器安装
——boot.ini与menu.lst的例解
大多数人日常工作所用的系统是Windows,如果想尝试或者转向Linux,那么进行Windows与Linux共存的双系统安装是个不错的主意。但双系统的安装较之单系统,在磁盘分区和引导管理器两个方面增加了复杂性,本文对双系统下引导管理器的安装来加以介绍。
笔者假定你已经有了一个可以正常运行的Win2k/XP系统,并且已经为Linux准备好了硬盘分区:Windows位于第一块硬盘的第一个分区,在Linux下表示为hda1,在Grub下表示为(hd0,0),而Linux位于hdaX,用Grub表示为(hd0, X-1)。——Linux下的硬盘分区计数是从hda1开始的,而Grub的硬盘分区计数是从(hd0,0)开始的,所以hdaX就是(hd0,X-1)。这里X如果在1-4之内,说明Linux分区是主分区,如果X大于4,说明Linux分区是逻辑分区,本文并不限定Linux必须位于主分区,它在逻辑分区一样是可以引导的。
首先说明本文的思路,笔者推荐由Windows到Linux的引导序列,即首先引导Windows的ntloader,然后通过ntloader加载Linux分区的Grub引导扇区,最后通过Grub引导Linux系统。本文涉及到的引导管理器包括ntloader和Grub,ntloader是Windows系统自带的,在安装Win2k/XP后就已经安装了,Windows 2000以及Windows Xp就是由ntloader加载的。Grub是Linux系统下很强大的引导管理器,在常见的Linux版本里都是有的,一般是自动安装的。
下面具体说明安装序列:
一、在已经准备好的Linux分区上安装Grub
这个过程通常是由Linux系统的安装程序自动进行的,当安装程序进行到引导管理器的安装,并就Grub的安装给出一些提示时,要当心了:我们选择Grub,而不是lilo,并且Grub要安装在该Linux分区,不要安装到硬盘主引导记录MBR(master boot record)上。安装程序询问Grub的安装位置时,应该是上文提到的hdaX或者(hd0,X-1),如果你写成hda或者(hd0),就会安装到MBR上。
之所以强调Grub安装到Linux分区,而不是MBR,因为本文是双系统安装,要顾忌到与Windows系统的兼容性(“兼容”在这里并不准确,实际是共生的意思)。我们的原则,就是把对已经安装的Windows系统的修改限制到最小的必要的程度,不去进行并非必要的修改,以此保障Linux与Windows两个系统的和平共处。“简洁即美”,“简单”也会更安全。
如果安装到MBR,也是可以的,但可能会有下面的问题:
1、如果所安装的Windows系统修改了MBR的默认设置,那么再把Grub安装到MBR,就对MBR的内容进行了修改,可能会导致Windows不能正常启动。通常的Windows安装并不会改动MBR的内容,但如果你安装了一些引导管理程序,它们往往是通过MBR进行设置的。时下很流行的一些“一键恢复”程序,有些也是通过MBR设置的;
2、日后重装Windows系统时,MBR里的Grub会被擦除,这会造成Linux系统不能引导。虽然这个问题也是可以解决的,但笔者更欣赏一劳永逸的安装方式,Grub安装到Linux分区下,可以避免日后的麻烦;
3、在一些个别情形下,Grub不能正常引导系统。这个现象并不常见,但仍有可能发生,要知道Grub目前仍然是版本前的软件,而将Grub装到MBR里,就会把问题弄得更复杂。
当你所安装的Linux系统不能指定将Grub安装到Linux的所在分区时,我们的选择是:
暂将Grub安装到MBR,如果Linux系统能被Grub加以引导,进入Linux系统后,我们再手工将Grub装入Linux分区,然后恢复MBR;或者在安装程序内暂时不进行Grub的安装,退出安装程序后手工安装Grub。
恢复MBR需要用DOS、win98/me的启动软盘引导系统,以/mbr参数执行引导软盘上的磁盘分区程序fdisk.exe,即在DOS命令行(plain dos)下执行A:\>fdisk /mbr。如果机器没有软驱,那么就需要用光盘或者U盘来引导机器进入DOS;在Windows 2k/XP下,一个叫Vfloppy的软件可以用软盘镜像文件来实现对软盘的虚拟引导,如果你的机器没有USB接口(或没有可以引导DOS的U盘),也没有光驱和软驱,可以一试。
我曾经用Xubuntu的LiveCD在一台设置了“一键恢复”的TCL电脑安装时,安装程序没有给出任何选择,自动将Grub安装到了MBR上,结果不能进入任何系统。最后还是用DOS下的A:\ > fdisk /mbr恢复了MBR,能够正常引导Windows后,手工将Grub装到了Linux下的根分区,然后通过ntloader加载Grub,才实现了对Linux的引导。
手工安装Grub的简便方法是用一张带有Grub的Linux LiveCD(比如常见的Knoppix、Morphix、Ubuntu,都是可以的),启动系统,在Linux的安装程序内如果能进入shell也是可以的,总之就是为了执行Linux指令,在终端下执行以下指令:
# grub
grub > root (hd0,X-1)
grub > setup (hd0,X-1)
grub > quit
以上指令首先定位Grub所需的/boot目录在分区(hd0,X-1),然后将Grub的引导代码写入(hd0,X-1)分区的第一个扇区,所以你首先应该确保(hd0,X-1)分区内的/boot/grub目录下已经有stage1、stage2、*_stage*等文件,这些文件可以通过释放Grub的打包文件来获得,或者直接从LiveCD光盘内的/boot/grub目录复制。
如果LiveCD带有grub-install脚本,也可以直接执行
# mount /dev/hdaX /mnt
# grub-install --root-directory=/mnt /dev/hdaX
以上指令首先将带有Grub目录/boot/grub的/hdaX挂载到/mnt,然后将Grub安装到/hdaX。
二、将Grub装配到ntloader内
Grub已经安装到了Linux分区内,但它还不能引导系统,我们需要把它和ntloader联接起来,由ntloader对Grub加以引导。这是通过把hdaX分区内的Grub引导扇区转换为文件,并装配到Windows的ntloader内来实施的。
仍然用LiveCD启动Linux系统(因为你所安装的Linux系统目前还是不能引导的),或者在安装程序可以进入shell的情况下,执行以下指令:
# mount -t vfat /dev/hda1 /mnt
# dd if=/dev/hdaX of=/mnt/linux.lnx bs=512 count=1
以上两条指令将Windows的启动分区(本文中为hda1)挂载到/mnt下,然后把Linux分区(hdaX)的第一个扇区(大小为512字节)复制为Windows启动分区根目录下名为linux.lnx的文件。
注意:如果你的Windows启动分区(即Windows下的C盘)不是fat32文件系统,而是ntfs文件系统,你需要在软驱内放入格式化的DOS软盘,并将第一条指令替换为:
# mount -t msdos /dev/fd0 /mnt
因为ntfs文件系统不经过特殊处理,在Linux下是不可写的,即使你将指令中的vfat替换为ntfs,实现了挂载,也是一样,所以我们在这里把linux.lnx写入DOS格式的软盘,然后通过软盘在Windows下把linux.lnx放入C盘。
接着是在Windows下编辑C盘根目录下的boot.ini文件,boot.ini通常是隐藏、只读的系统文件,所以需要把它的“隐藏”、“只读”属性去掉,才可以编辑。在“我的电脑”工具菜单“文件夹选项”下的“查看”栏中取消“隐藏受保护的操作系统文件”和“隐藏已知文件类型的扩展名”,并选择“显示所有文件和文件夹”,就可以看到C盘根目录下的boot.ini文件了。在boot.ini内的[operating systems]栏增添一行:
c:\linux.lnx=”Grub Menu”
并将[boot loader]栏内的“timeout=0”,改为“timeout=5”,这样引导Windows时将会显示带有“Grub Menu”字样的操作系统选择菜单,并持续5秒钟,如果选择Grub Menu,就会进入Grub菜单。
三、设置menu.lst文件
menu.lst是对Grub进行设置的一个文本文件,可以用文本编辑器加以编辑,位于/boot/grub目录内。我们在前面虽然已经把Grub安装到了Linux根分区上,但如果没有生成menu.lst文件并对它加以设置,Grub是没有任何作用的。对menu.lst文件进行设置是个复杂的工作,特别是有关kernel和initrd的各种特殊参数,幸而系统安装的menu.lst文件内通常有详尽的注释。并且你的Grub如果是由安装程序自动设置的,那么通常menu.lst已经被设置好了,我们仅仅根据自己的需要进行一些修改和调整,而不必重写menu.lst。即使你的menu.lst不是由安装程序生成的,也不必担心,还可以参考、分析安装光盘或者LiveCD上的menu.lst文件来对Linux分区内的menu.lst加以设置。
如果Grub已经由安装程序装到了MBR,并且能够引导所安装的Linux,那么自动生成的Linux系统根分区下的/boot/grub/menu.lst就已经被配置好了,我们只须把Grub重新安装到Linux系统根分区,恢复Windows下的原初MBR,按照上文的方法把Linux系统根分区的Grub引导代码装载到ntloader就可以了。因为Grub的安装位置不是在menu.lst文件内指定,而是在linux shell中执行grub,进入Grub命令行后,应用Grub的内部指令root和setup来指定,或者在可执行的shell脚本文件grub-install中,以参数的形式指定设备文件(如/dev/hda或/dev/hdaX)。
假使所安装的Linux系统没有使用Grub,而是使用lilo作为引导管理器,只要lilo能够实现引导,我们就可以借鉴linux系统内的/etc/lilo.conf文件来对menu.lst加以设置。Lilo.conf是lilo的配置文件,其格式虽然与menu.lst不同,但关键部分是相同的,如指定kernel和initrd的位置,向内核传递引导参数,指定缺省引导的系统和延时时长,在lilo.conf中内核参数是在APPEND后,我们可以将lilo.conf中的参数移植到menu.lst中。
四、Menu.lst的一个实例:
以下作为实例的menu.lst是我在windows 2000系统中安装的grub4nt的配置文件,所以可以看到(hd0,0)既是Windows的引导分区,又是Grub文件及一些linux内核文件的所在分区。虽然Grub4nt不能在menu.lst中应用savedefault命令外(可能因为grub4nt不支持在fat32文件系统上的写操作),其他设置与标准的Gnu Grub并无不同,大家可以通过这个实例来具体了解配置文件menu.lst。
default 0
timeout 5
foreground = 333333
background = eeeeee
color light-gray/blue black/light-gray
gfxmenu (hd0,0)/boot/morphix/message
title ubuntu linux
kernel (hd0,2)/vmlinuz ro root=/dev/hda3
title ubuntu linux (rescue mode)
kernel (hd0,2)/vmlinuz ro single root=/dev/hda3
title Other operating systems:
root
title PUD LiveHD
kernel (hd0,0)/boot/pud/linux lang=us ramdisk_size=100000 init=/etc/init apm=power-off vga=791 nomce initrd=miniroot.gz quiet BOOT_IMAGE=knoppix
initrd (hd0,0)/boot/pud/miniroot.gz
title Windows
root (hd0,0) 或者 rootnoverify (hd0,0)
makeactive
chainloader +1
title submenu -> Morphix LiveHD
configfile (hd0,1)/boot/grub/menu.lst
这里不对menu.lst做全面解释了,只结合实例,介绍几个重点环节,完整说明请阅读网上Grub的使用手册。
Default 0
default用来设置缺省引导系统,数字序列从0开始,本例会在menu.lst内自动寻找以title开始的词条,并引导第一个title词条,你可以根据自己的需要改成其他数字,如1(第二个title词条);
timeout 5
timeout用来设置Grub引导的延时时长,本例中为5秒钟,系统在等待5秒后用户如果没有手动选择要引导的系统,Grub就会自动引导由default指定的系统;
title ubuntu linux
title用来指示Grub所引导系统的设置的开始,title后面的文字在Grub菜单中会被作为系统的名称显示出来,本例中Grub引导菜单会显示ubuntu linux、ubuntu linux (rescue mode)、other operating systems、PUD LiveHD、Windows、submenu -> Morphix六个词条,其中第三个词条并非一个真实的系统,仅起指示的作用,故其root部分为空;
kernel (hd0,2)/vmlinuz ro root=/dev/hda3
kernel用来指示linux系统的内核文件的所在位置及引导参数,(hd0,2)/vmlinuz指内核为hda3(第一块硬盘第三个主分区)内根目录下的vmlinuz文件,根文件系统(/)位于hda3,注意:指示内核文件所用路径中的分区必须用Grub的表示法,不能用linux的表示法, 而根文件系统的位置必须用linux下的设备文件名来表示(本例中为/dev/hda3)。有时,vmlinuz并不是真实的内核文件,而是内核文件的一个链结文件(link file),但这不影响Grub的引导,它能根据链结文件找到真实的内核并加以引导,这在内核文件带有很长的版本号时会非常有用,简化了内核文件名的拼写,减少了拼写错误的出错几率;
kernel的这种设置是最为简单的方式,也是比较通用的设置方式,使用安装过的内核直接引导已安装的根文件系统(即linux系统),而不需进行initrd的设置;在不清楚内核的特殊设置参数时,可以用这种设置来尝试引导系统。如果在以上设置中加上single,即改为kernel (hd0,2)/vmlinuz ro root=/dev/hda3 single,则系统引导后会进入单用户(root用户)的文本模式,即救援模式(rescue mode),在系统升级、维护或查找、排除故障时会比较有用;
initrd (hd0,0)/boot/pud/miniroot.gz
initrd用来指示initrd文件(即初始内存磁盘文件,linux系统中常用的引导技术)的位置,关于硬盘分区的表示方法与kernel的要求相同,必须用(hd0,0)这种Grub的表示方法;
root (hd0,0)
root用来定位分区,本例中为hda1,Windows系统的所在分区。如果在kernel和initrd之前使用它,可以用来简化文件位置的表述,比如
kernel (hd0,2)/vmlinuz ro root=/dev/hda3
可以写成
root (hd0,2)
kernel /vmlinuz ro root=/dev/hda3
而initrd也可如是模仿;
makeactive
makeactive用来激活root所定位的分区,它只能用于主分区,不能用于扩展分区上的逻辑分区,虽然可以用这种技术来引导Grub安装在了主分区的linux系统但有比较大的局限性,所以通常是用来引导Windows系统;
chainloader +1
chainloader +1用来对makeactive所激活的主分区加以引导,同上:它只能引导主分区,所以通常是用来引导Windows系统,而linux系统可以安装在扩展分区上的逻辑分区,通常是使用kernel和initrd这种功能更为强大、灵活的引导方式;
configfile (hd0,1)/boot/grub/menu.lst
configfile用来将其他的menu.lst菜单引入Grub菜单,在同一机器上安装了多个linux系统、存在多个menu.lst文件时,这个语句非常有用,它可以简化menu.lst文件的设置,不必重抄那些复杂的引导参数,只须把别的系统的menu.lst文件加以引用就可以了,在Grub引导时选择这个子菜单,就会进入所引用的menu.lst的引导菜单。
本例中的PUD LiveHD是将PUD(一种中文繁体Debian LiveCD版本)光盘上的内容复制到hda1(在本例中为Windows的C:盘) 中,然后使用grub4nt对其加以引导,这样就实现了LiveCD到硬盘的移植,我称之为LiveHD;而Morphix LiveHD则是将Morphix(一种模块化的Debian LiveCD)光盘上的内容复制到一个单独的ext2/3分区,本例中为(hd0,1),即hda2,实现LiveHD的引导。很有趣的是,PUD只能放入fat32分区,Morphix只能放入ext2分区,反之则不能引导,这应该是不同版本的LiveCD的内核所支持文件系统的不同所致。
注:Grub4nt是Grub在windows 2k/XP下的扩展,建基于Grub for DOS,/boot/grub目录放在fat/fat32文件系统内,可以在ntloader内通过一个小文件grldr实现Grub的引导,而无须写入MBR,它是中国人的作品,作为一种新颖别致的引导方式,向世界上的linux爱好者展示了中国人的智慧,本文会在后面专门予以介绍。
五、boot.ini文件的调整
boot.ini是一个文本文件,可以用文本编辑器打开,它是win 2k/XP下ntloader的设置文件,下面是我的机器上的boot.ini实例:
[boot loader]
timeout=0
default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
[operating systems]
c:\ubuntu.lnx=Xubuntu Linux
c:\morphix.lnx=Morphix LiveHD
c:\grldr=Grub Menu
multi(0)disk(0)rdisk(0)partition(1)\WINNT="Win2k" /fastdetect
我们逐行来对它加以解释。
[boot loader]一节用来指定缺省引导的系统及其等待时间,本例中缺省引导第一块IDE硬盘的第一个分区(表示为multi(0)disk(0)rdisk(0)partition(1),而如果你的windows Xp系统在硬盘的第二个分区,则表示为multi(0)disk(0)rdisk(0)partition(2)\WINDOWS,这种表示法不同于linux,它不区别主分区和逻辑分区,而依据分区在磁盘上的顺序从数字1开始计数)内的windows 2000系统,没有延时,立即引导。
若把Timeout的值从0改为5,则延时5秒,供用户选择boot菜单;改为-1,则系统不进行自动引导,始终等待着用户的键盘输入来进行选择。
[operating systems]一节用来描述boot菜单中要引导的不同系统,“=”后面的字符是boot菜单的显示内容,而“=”前面的部分是ntloader实际引导的内容,multi(0)disk(0)rdisk(0)partition(1)\WINNT指ntloader所要引导的windows系统位于第一块硬盘的第一个分区内的\winnt目录,c:\ubuntu.lnx和c:\morphix.lnx则是应用dd命令在linux下将grub在根分区内的引导扇区转换生成的文件,而c:\grldr是grub4nt的引导文件,用来实现grub在ntloader的引导。
[operating systems]内的不同词条的顺序是可以调整的,例如我们可以将c:\grldr=Grub Menu从本节第三行改为第一行,这样Grub Menu就会在boot菜单的第一行显示。
而缺省引导的系统也是可以改变的,例如我们可以将[boot loader]内的multi(0)disk(0)rdisk(0)partition(1)\WINNT改为c:\grldr,这样缺省引导的就是grub4nt的Grub菜单,而不是windows 2000了。这里要注意:c:\grldr放入[boot loader]一节时,正确的写法应该是
default=c:\grldr
一定不要将“=Grub Menu”带上,否则boot菜单的显示效果将不是我们所想要的,切记!
六、grub4nt的使用
将grub加载到ntloader里的方法,除了上文第二部分所介绍的将Linux根分区内的Grub引导扇区转换为ntloader可以引导的文件,还有另外一种方法,就是使用grub4nt。grub4nt通过grldr这个小文件,使ntloader直接加载Windows系统C:盘下的\boot\grub\menu.lst(新版本的grub4nt会寻找根目录的\menu.lst)。
在windows下的boot.ini文件内[operating systems]一节增添一行如下:
c:\grldr=grub4nt
对grub4nt的menu.lst设置,既可以把Linux系统根分区内的/boot/grub/menu.lst直接移植过来(GNU Grub下的savedefault在grub4nt下不能使用,会导致grub4nt的出错),也可以在grub4nt的menu.lst文件内通过configfile直接引入Linux系统根分区内的/boot/grub/menu.lst菜单,而后者不失为一种简单安全的方法,省掉了对内核引导参数的复杂设置。
即在grub4nt的menu.lst文件内这样设置:
title GNU Grub menu
configfile (hda0,X)/boot/grub/menu.lst
七、总结
本文对Windows与Linux并存于同一机器时引导管理器的安装给出了描述,可以看出,笔者推荐的是以Windows 2k/XP下的ntloader为主引导器,通过ntloader来加载Grub,最后由Grub实现Linux的引导。这样一种引导序列的特点是,对Windows的引导几乎没有加以改动,仅仅在其中插入了对Grub的加载。当然,相反的序列也是可以的,即首先引导Grub(可以将Grub装入MBR或者处于激活状态的主分区),由Grub来加载ntloader(通过chainloader +1命令),然后实现对Windows的引导。但后者可能会引发其他的问题。
无论如何,本文中Linux的引导都是通过Grub进行的,不管是将Grub装入Linux根分区、由ntloader加载Linux根分区的Grub引导扇区,还是通过grub4nt的grldr、由ntloader加载grldr来实现对Grub的引导。其实,Grub的引导扇区文件和grldr只是对Grub加载的不同实现方式罢了。
-
- 帖子: 33
- 注册时间: 2007-12-10 1:28
-
- 帖子: 41
- 注册时间: 2010-04-07 17:22
Re: [分享]Linux与Windows双系统下的Grub引导管理器安装——boot.ini与menu.lst的例解
好贴!!
mark,慢慢看~~~
mark,慢慢看~~~