2008年4月2日
这个系统是Prayaya LiveSystem-710的精简版本,去掉了deb包管理和gnome,整个iso文件大小为 60M, 桌面采用fluxbox+rox-filer。可以刻成livecd也可以安装到u盘或者移动硬盘在不同的电脑上启动。功能模块是定制的软件包,以.ro为后缀名,可以在系统启动时自动加载也可以在系统运行过程中动态加载。
下载地址:
ftp://download.inlsd.org/prayaya-small/
1. 到
ftp://download.inlsd.org/prayaya-small/release/下载
usbinst-test-1.zip。
2. 解压到U盘根目录,注意解压出来是两个目录:
bootinst
prayaya-livesystem-usb
3. 到
ftp://download.inlsd.org/prayaya-small/iso/下载最新的iso文件,initrd.img和vmlinuz ,复制到prayaya-livesystem-usb目录。
4.到
ftp://download.inlsd.org/prayaya-small/ros下载firfox.ro,复制到prayaya-livesystem-usb下的ros目录。
5. 打开终端,到U盘bootinst目录,运行
#./bootinst.sh
6.重启,从U盘启动. 正常启动之后,请到ftp://download.inlsd.org/prayaya-small/ros
下载你需要的ro模块,放到U盘prayaya-livesystem-usb/ros 目录。
ps: 第5步是用grub4dos把U盘制作成可启动的,如果之前已经装过grub4dos直接参考bootinst目录里的menu.lst修改相关参数即可。
安装完成之后,日后如果iso有更新,直接下载替换即可。
Create the Project
Creating the project is as simple as can be. An Eclipse plugin is available making Android development a snap.
You'll need to have a development computer with the Eclipse IDE installed (see System and Software Requirements), and you'll need to install the Android Eclipse Plugin (ADT). Once you have those ready, come back here.
First, here's a high-level summary of how to build "Hello, World!":
- Create a new "Android Project" via the File > New > Project menu.
- Fill out the project details in the New Android Project dialog.
- Edit the auto-generated source code template to display some output.
That's it! Next, let's go through each step above in detail.
- Create a new Android Project
From Eclipse, select the File > New > Project menu item. If the Android Plugin for Eclipse has been successfully installed, the resulting dialog should have a folder labeled "Android" which should contain a single entry: "Android Project".

Once you've selected "Android Project", click the Next button.
- Fill out the project details
The next screen allows you to enter the relevant details for your project. Here's an example:

Here's what each field on this screen means:
| Project Name |
This is the name of the directory or folder on your computer that you want to contain the project. |
| Package Name |
This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.
The package name you use in your application must be unique across all packages installed on the system; for this reason, it's very important to use a standard domain-style package for your applications. In the example above, we used the package domain "com.android"; you should use a different one appropriate to your organization.
|
| Activity Name |
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. |
| Application Name |
This is the human-readable title for your application. |
The checkbox for toggling "Use default location" allows you to change the location on disk where the project's files will be generated and stored.
- Edit the auto-generated source code
After the plugin runs, you'll have a class named HelloAndroid that looks like this:
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
}
The next step is to start modifying it!
Construct the UI
Once you've got the project set up, the obvious next step is to get some text up there on the screen. Here's the finished product — next we'll dissect it line by line:
package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
In Android, user interfaces are composed of hierarchies of classes called Views. A View is simply a drawable object, such as a radio button, an animation, or (in our case) a text label. The specific name for the View subclass that handles text is simply TextView.
Here's how you construct a TextView:
TextView tv = new TextView(this);
The argument to TextView's constructor is an Android Context instance. The Context is simply a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. The Activity class inherits from Context. Since our HelloAndroid class is a subclass of Activity, it is also a Context, and so we can pass the 'this' reference to the TextView.
Once we've constructed the TextView, we need to tell it what to display:
tv.setText("Hello, Android");
Nothing too surprising there.
At this point, we've constructed a TextView and told it what text to display. The final step is to connect this TextView with the on-screen display, like so:
setContentView(tv);
The setContentView() method on Activity indicates to the system which View should be associated with the Activity's UI. If an Activity doesn't call this method, no UI is present at all and the system will display a blank screen. For our purposes, all we want is to display some text, so we pass it the TextView we just created.
There it is — "Hello, World" in Android! The next step, of course, is to see it running.
Run the Code: Hello, Android
The Eclipse plugin makes it very easy to run your applications. Begin by selecting the Run > Open Run Dialog menu entry; you should see a dialog like this:
Next, highlight the "Android Application" entry, and then click the icon in the top left corner (the one depicting a sheet of paper with a plus sign in the corner) or simply double-click the "Android Application" entry. You should have a new launcher entry named "New_configuration".
Change the name to something expressive, like "Hello, Android", and then pick your project by clicking the Browse button. (If you have more than one Android project open in Eclipse, be sure to pick the right one.) The plugin will automatically scan your project for Activity subclasses, and add each one it finds to the drop-down list under the "Activity:" label. Since your "Hello, Android" project only has one, it will be the default, and you can simply continue.
Press the "Apply" button. Here's an example:
That's it — you're done! Press the Run button, and the Android Emulator should start. Once it's booted up your application will appear. When all is said and done, you should see something like this:
That's "Hello, World" in Android. Pretty straightforward, eh? The next sections of the tutorial offer more detailed information that you may find valuable as you learn more about Android.
Upgrading the UI to an XML Layout
The "Hello, World" example you just completed uses what we call "programmatic" UI layout. This means that you construct and build your application's UI directly in source code. If you've done much UI programming, you're probably familiar with how brittle that approach can sometimes be: small changes in layout can result in big source-code headaches. It's also very easy to forget to properly connect Views together, which can result in errors in your layout and wasted time debugging your code.
That's why Android provides an alternate UI construction model: XML-based layout files. The easiest way to explain this concept is to show an example. Here's an XML layout file that is identical in behavior to the programmatically-constructed example you just completed:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello, Android"/>
The general structure of an Android XML layout file is simple. It's a tree of tags, where each tag is the name of a View class. In this example, it's a very simple tree of one element, a TextView. You can use the name of any class that extends View as a tag name in your XML layouts, including custom View classes you define in your own code. This structure makes it very easy to quickly build up UIs, using a much simpler structure and syntax than you would in source code. This model is inspired by the web development model, where you can separate the presentation of your application (its UI) from the application logic used to fetch and fill in data.
In this example, there are also four XML attributes. Here's a summary of what they mean:
| Attribute |
Meaning |
xmlns:android |
This is an XML namespace declaration that tells the Android tools that you are going to refer to common attributes defined in the Android namespace. The outermost tag in every Android layout file must have this attribute.
|
android:layout_width |
This attribute defines how much of the available width on the screen this View should consume. In this case, it's our only View so we want it to take up the entire screen, which is what a value of "fill_parent" means.
|
android:layout_height |
This is just like android:layout_width, except that it refers to available screen height. |
android:text |
This sets the text that the TextView should contain. In this example, it's our usual "Hello, Android" message. |
So, that's what the XML layout looks like, but where do you put it? Under the res/ directory in your project. The "res" is short for "resources" and that directory contains all the non-code assets that your application requires. This includes things like images, localized strings, and XML layout files.
The Eclipse plugin creates one of these XML files for you. In our example above, we simply never used it. In the Package Explorer, expand the folder res/layout, and edit the file main.xml. Replace its contents with the text above and save your changes.
Now open the file named R.java in your source code folder in the Package Explorer. You'll see that it now looks something like this:
public final class R {
public static final class attr {
};
public static final class drawable {
public static final int icon=0x7f020000;
};
public static final class layout {
public static final int main=0x7f030000;
};
public static final class string {
public static final int app_name=0x7f040000;
};
};
A project's R.java file is an index into all the resources defined in the file. You use this class in your source code as a sort of short-hand way to refer to resources you've included in your project. This is particularly powerful with the code-completion features of IDEs like Eclipse because it lets you quickly and interactively locate the specific reference you're looking for.
The important thing to notice for now is the inner class named "layout", and its member field "main". The Eclipse plugin noticed that you added a new XML layout file and then regenerated this R.java file. As you add other resources to your projects you'll see R.java change to keep up.
The last thing you need to do is modify your HelloAndroid source code to use the new XML version of your UI, instead of the hard-coded version. Here's what your new class will look like. As you can see, the source code becomes much simpler:
package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
}
}
When you make this change, don't just copy-and-paste it in. Try out the code-completion feature on that R class. You'll probably find that it helps a lot.
Now that you've made this change, go ahead and re-run your application — all you need to do is click the green Run arrow icon, or select Run > Run History > Hello, Android from the menu. You should see.... well, exactly the same thing you saw before! After all, the point was to show that the two different layout approaches produce identical results.
There's a lot more to creating these XML layouts, but that's as far as we'll go here. Read the Implementing a User Interface documentation for more information on the power of this approach.
Debugging Your Project
The Android Plugin for Eclipse also has excellent integration with the Eclipse debugger. To demonstrate this, let's introduce a bug into our code. Change your HelloAndroid source code to look like this:
package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Object o = null;
o.toString();
setContentView(R.layout.main);
}
}
This change simply introduces a NullPointerException into your code. If you run your application again, you'll eventually see this:
Press "Force Quit" to terminate the application and close the emulator window.
To find out more about the error, set a breakpoint in your source code on the line Object o = null; (double-click on the marker bar next to the source code line). Then select Run > Debug History > Hello, Android from the menu to enter debug mode. Your app will restart in the emulator, but this time it will suspend when it reaches the breakpoint you set. You can then step through the code in Eclipse's Debug Perspective, just as you would for any other application.
Creating the Project without Eclipse
If you don't use Eclipse (such as if you prefer another IDE, or simply use text editors and command line tools) then the Eclipse plugin can't help you. Don't worry though — you don't lose any functionality just because you don't use Eclipse.
The Android Plugin for Eclipse is really just a wrapper around a set of tools included with the Android SDK. (These tools, like the emulator, aapt, adb, ddms, and others are documented elsewhere.) Thus, it's possible to wrap those tools with another tool, such as an 'ant' build file.
The Android SDK includes a Python script named "activityCreator.py" that can be used to create all the source code and directory stubs for your project, as well as an ant-compatible build.xml file. This allows you to build your project from the command line, or integrate it with the IDE of your choice.
For example, to create a HelloAndroid project similar to the one we just created via Eclipse, you'd use this command:
activityCreator.py --out HelloAndroid com.android.hello.HelloAndroid
To build the project, you'd then run the command 'ant'. When that command successfully completes, you'll be left with a file named HelloAndroid.apk under the 'bin' directory. That .apk file is an Android Package, and can be installed and run in your emulator using the 'adb' tool.
For more information on how to use these tools, please read the documentation cited above.
2008年3月30日
一、内核简介
内核,是一个操作系统的核心。它负责管理系统的进程、内存、设备驱动程序、文件和网络系统,决定着系统的性能和稳定性。
Linux的一个重要的特点就是其源代码的公开性,所有的内核源程序都可以在/usr/src/linux下找到,大部分应用软件也都是遵循GPL而设计的,你都可以获取相应的源程序代码。全世界任何一个软件工程师都可以将自己认为优秀的代码加入到其中,由此引发的一个明显的好处就是Linux修补漏洞的快速以及对最新软件技术的利用。而Linux的内核则是这些特点的最直接的代表。
想象一下,拥有了内核的源程序对你来说意味着什么?首先,我们可以了解系统是如何工作的。通过通读源代码,我们就可以了解系统的工作原理,这在Windows下简直是天方夜谭。其次,我们可以针对自己的情况,量体裁衣,定制适合自己的系统,这样就需要重新编译内核。在Windows下是什么情况呢?相信很多人都被越来越庞大的Windows整得莫名其妙过。再次,我们可以对内核进行修改,以符合自己的需要。这意味着什么?没错,相当于自己开发了一个操作系统,但是大部分的工作已经做好了,你所要做的就是要增加并实现自己需要的功能。在Windows下,除非你是微软的核心技术人员,否则就不用痴心妄想了。
二、内核版本号
由于Linux的源程序是完全公开的,任何人只要遵循GPL,就可以对内核加以修改并发布给他人使用。Linux的开发采用的是集市模型(bazaar,与cathedral--教堂模型--对应),为了确保这些无序的开发过程能够有序地进行,Linux采用了双树系统。一个树是稳定树(stable tree),另一个树是非稳定树(unstable tree)或者开发树(development tree)。一些新特性、实验性改进等都将首先在开发树中进行。如果在开发树中所做的改进也可以应用于稳定树,那么在开发树中经过测试以后,在稳定树中将进行相同的改进。一旦开发树经过了足够的发展,开发树就会成为新的稳定树。开发数就体现在源程序的版本号中;源程序版本号的形式为x.y.z:对于稳定树来说,y是偶数;对于开发树来说,y比相应的稳定树大一(因此,是奇数)。到目前为止,稳定树的最高版本是2.4.18;开发树的最新版本是2.5.10。下载内核版本请访问
http://www.kernel.org。
三、为什么重新编译内核
Linux作为一个自由软件,在广大爱好者的支持下,内核版本不断更新。新的内核修订了旧内核的bug,并增加了许多新的特性。如果用户想要使用这些新特性,或想根据自己的系统度身定制一个更高效,更稳定的内核,就需要重新编译内核。
通常,更新的内核会支持更多的硬件,具备更好的进程管理能力,运行速度更快、 更稳定,并且一般会修复老版本中发现的许多漏洞等,经常性地选择升级更新的系统内核是Linux使用者的必要操作内容。
为了正确的合理地设置内核编译配置选项,从而只编译系统需要的功能的代码,一般主要有下面四个考虑:
l 自己定制编译的内核运行更快(具有更少的代码)
l 系统将拥有更多的内存(内核部分将不会被交换到虚拟内存中)
l 不需要的功能编译进入内核可能会增加被系统攻击者利用的漏洞
l 将某种功能编译为模块方式会比编译到内核内的方式速度要慢一些
四、内核编译模式
要增加对某部分功能的支持,比如网络之类,可以把相应部分编译到内核中(build-in),也可以把该部分编译成模块(module),动态调用。如果编译到内核中,在内核启动时就可以自动支持相应部分的功能,这样的优点是方便、速度快,机器一启动,你就可以使用这部分功能了;缺点是会使内核变得庞大起来,不管你是否需要这部分功能,它都会存在,这就是Windows惯用的招数,建议经常使用的部分直接编译到内核中,比如网卡。如果编译成模块,就会生成对应的.o文件,在使用的时候可以动态加载,优点是不会使内核过分庞大,缺点是你得自己来调用这些模块。
五、新版本内核的获取和更新
Linux内核版本发布的官方网站是
http://www.kernel.org。新版本的内核...问剑恢质荈ull Source版本,另外一种是patch文件,即补丁。完整的内核版本比较大,一般是tar.gz或者是.bz2文件,二者分别是使用gzip或者bzip2进行压缩的文件,使用时需要解压缩。patch文件则比较小,一般只有几十K到几百K,但是patch文件是针对于特定的版本的,你需要找到自己对应的版本才能使用。
编译内核需要root权限,以下操作都假定你是root用户。请把你需要升级的内核拷贝到/usr/src/下(下文中以2.4.18的内核的linux-2.4.18.tar.gz为例),命令为
#cp linux-2.4.18.tar.gz /usr/src
让我们先来查看一下当前/usr/src的内容,注意到有一个linux-2.4的符号链接,指向一个linux-2.4.7-10(以REDHAT7.2为例)的目录。这就是你所装linux的kernel源代码,删除这个链接。
现在解压我们下载的源程序文件。如果所下载的是.tar.gz(.tgz)文件,请使用下面的命令:
#tar -zxvf linux-2.4.18.tar.gz.tar.gz
如果你所下载的是.bz2文件,例如linux-2.4.0test8.tar.bz2,请使用下面的命令
#bzip2 -d linux-2.4.18.tar.bz2
#tar -xvf linux-2.4.18.tar
文件将解压到/usr/src/linux目录中,我们把它稍作修改:
#mv linux linux-2.4.18
#ln -s linux-2.4.18 linux
如果下载的是patch文件,就可以进行patch操作(下面假设patch-2.4.18已经位于/usr/src目录下了,否则你需要先把该文件拷贝到/usr/src下):
#patch -p0 < patch-2.4.18
六、内核编译
通常要运行的第一个命令是:
#cd /usr/src/linux
#make mrproper
该命令确保源代码目录下没有不正确的.o文件以及文件的互相依赖。由于我们使用刚下载的完整的源程序包进行编译,所以本步可以省略。而如果你多次使用了这些源程序编译内核,那么最好要先运行一下这个命令。
确保/usr/include/目录下的asm、linux和scsi等链接是指向要升级的内核源代码的。它们分别链向源代码目录下的真正的、该计算机体系结构(对于PC机来说,使用的体系结构是i386)所需要的真正的include子目录。如:asm指向/usr/src/linux/include/asm-i386等。若没有这些链接,就需要手工创建,按照下面的步骤进行:
# cd /usr/include/
# rm -r asm linux scsi
# ln -s /usr/src/linux/include/asm-i386 asm
# ln -s /usr/src/linux/include/linux linux
# ln -s /usr/src/linux/include/scsi scsi
这是配置非常重要的一部分。删除掉/usr/include下的asm、linux和scsi链接后,再创建新的链接指向新内核源代码目录下的同名的目录。这些头文件目录包含着保证内核在系统上正确编译所需要的重要的头文件。现在你应该明白为什么我们上面又在/usr/src下"多余"地创建了个名为linux的链接了吧?
接下来的内核配置过程比较烦琐,但是配置的适当与否与日后Linux的运行直接相关,有必要了解一下一些主要的且经常用到的选项的设置。
配置内核可以根据需要与爱好使用下面命令中的一个:
#make config(基于文本的最为传统的配置界面,不推荐使用)
#make menuconfig(基于文本选单的配置界面,字符终端下推荐使用)
#make xconfig(基于图形窗口模式的配置界面,Xwindow下推荐使用)
#make oldconfig(如果只想在原来内核配置的基础上修改一些小地方,会省去不少麻烦)
这三个命令中,make xconfig的界面最为友好,如果你可以使用Xwindow,那么就推荐你使用这个命令,界面如下:
如果你不能使用Xwindow,那么就使用make menuconfig好了。界面虽然比上面一个差点,总比make config的要好多了,下图为make menuconfig的界面:
选择相应的配置时,有三种选择,它们分别代表的含义如下:
Y--将该功能编译进内核
N--不将该功能编译进内核
M--将该功能编译成可以在需要时动态插入到内核中的模块
如果使用的是make xconfig,使用鼠标就可以选择对应的选项。如果使用的是make menuconfig,则需要使用空格键进行选取。你会发现在每一个选项前都有个括号, 但有的是中括号有的是尖括号,还有一种圆括号。用空格键选择时可以发现,中括号里要么是空,要么是"*",而尖括号里可以是空,"*"和"M"这表示前者对应的项要么不要,要么编译到内核里;后者则多一样选择,可以编译成模块。而圆括号的内容是要你在所提供的几个选项中选择一项。
在编译内核的过程中,最烦杂的事情就是这步配置工作了,很多新手都不清楚到底该如何选取这些选项。实际上在配置时,大部分选项可以使用其缺省值,只有小部分需要根据用户不同的需要选择。选择的原则是将与内核其它部分关系较远且不经常使用的部分功能代码编译成为可加载模块,有利于减小内核的长度,减小内核消耗的内存,简化该功能相应的环境改变时对内核的影响;不需要的功能就不要选;与内核关心紧密而且经常使用的部分功能代码直接编译到内核中。
至于选项,因为比较复杂,只是简单做一介绍,编译时应视具体情况,参考帮助的内容再加以选择。
1. Code maturity level options
代码成熟等级。此处只有一项:prompt for development and/or incomplete code/drivers,如果你要试验现在仍处于实验阶段的功能,比如khttpd、IPv6等,就必须把该项选择为Y了;否则可以把它选择为N。
2. Loadable module support
对模块的支持。这里面有三项:
Enable loadable module support:除非你准备把所有需要的内容都编译到内核里面,否则该项应该是必选的。
Set version inFORMation on all module symbols:可以不选它。
Kernel module loader:让内核在启动时有自己装入必需模块的能力,建议选上。
3. Processor type and features
CPU类型。内容蛮多的,不一一介绍了,有关的几个如下:
Processor family:根据你自己的情况选择CPU类型。
High Memory Support:大容量内存的支持。可以支持到4G、64G,一般可以不选。
Math emulation:协处理器仿真。协处理器是在386时代的宠儿,现在早已不用了。
MTTR support:MTTR支持。可不选。
Symmetric multi-processing support:对称多处理支持。除非你富到有多个CPU,否则就不用选了。
4. General setup
这里是对最普通的一些属性进行设置。这部分内容非常多,一般使用缺省设置就可以了。下面介绍一下经常使用的一些选项:
Networking support:网络支持。必须,没有网卡也建议你选上。
PCI support:PCI支持。如果使用了PCI的卡,当然必选。
PCI access mode:PCI存取模式。可供选择的有BIOS、Direct和Any,选Any吧。
Support for hot-pluggabel devices:热插拔设备支持。支持的不是太好,可不选。
PCMCIA/CardBus support:PCMCIA/CardBus支持。有PCMCIA就必选了。
System V IPC
BSD Process Accounting
Sysctl support:以上三项是有关进程处理/IPC调用的,主要就是System V和BSD两种风格。如果你不是使用BSD,就按照缺省吧。
Power Management support:电源管理支持。
Advanced Power Management BIOS support:高级电源管理BIOS支持。
5. Memory Technology Device(MTD)
MTD设备支持。可不选。
6. Parallel port support
并口支持。如果不打算使用串口,就别选了。
7. Plug and Play configuration
即插即用支持。虽然Linux对即插即用目前支持的不如Windows好,但是还是选上吧,这样你可以拔下鼠标之类的体验一下Linux下即插即用的感觉。
8. Block devices
块设备支持。这个就得针对自己的情况来选了,简单说明一下吧:
Normal PC floppy disk support:普通PC软盘支持。这个应该必选。
XT hard disk support:
Compaq SMART2 support:
Mulex DAC960/DAC1100 PCI RAID Controller support:RAID镜像用的。
Loopback device support:
Network block device support:网络块设备支持。如果想访问网上邻居的东西,就选上。
Logical volume manager(LVM)support:逻辑卷管理支持。
Multiple devices driver support:多设备驱动支持。
RAM disk support:RAM盘支持。
9. Networking options
网络选项。这里配置的是网络协议。内容太多了,不一一介绍了,自己看吧,如果你对网络协议有所了解的话,应该可以看懂的。如果懒得看,使用缺省选项(肯定要选中TCP/IP networking哦)就可以了。让我们看看,TCP/IP、ATM、IPX、DECnet、Appletalk……支持的协议好多哦,IPv6也支持了,Qos and/or fair queueing(服务质量公平调度)也支持了,还有kHTTPd,不过这些都还在实验阶段。
10. Telephony Support
电话支持。Linux下可以支持电话卡,这样你就可以在IP上使用普通的电话提供语音服务了。记住,电话卡可和modem没有任何关系哦。
11. ATA/IDE/MFM/RLL support
这个是有关各种接口的硬盘/光驱/磁带/软盘支持的,内容太多了,使用缺省的选项吧,如果你使用了比较特殊的设备,比如PCMCIA等,就到里面自己找相应的选项吧。
12. SCSI support
SCSI设备的支持。我没有SCSI的设备,所以根本就不用选,如果你用了SCSI的硬盘/光驱/磁带等设备,自己找好了。
13. Fusion MPT device support
需要Fusion MPT兼容PCI适配器,不用选。
14. I2O device support
需要I2O接口适配器支持,在智能Input/Output(I2O)体系接口中使用。
15. Network device support
网络设备支持。上面选好协议了,现在该选设备了,可想而知,内容肯定多得很。还好还好,里面大概分类了,有ARCnet设备、Ethernet(10 or 100 Mbit)、Ethernet(1000Mbit)、Wireless LAN(non-hamradio)、Token Ring device、Wan interfaces、PCMCIA network device support几大类。我用的是10/100M的以太网,看来只需要选则这个了。还是10/100M的以太网设备熟悉,内容虽然多,一眼就可以看到我所用的RealTeck RTL-8139 PCI Fast Ethernet Adapter support,为了免得麻烦,编译到内核里面好了,不选M了,选Y。耐心点,一般说来你都能找到自己用的网卡。如果没有,你只好自己到厂商那里去要驱动了。
16. Amateur Radio support
配置业余无线广播。
17. IrDA(infrared)support
红外线支持。
18. ISDN subsystem
如果你使用ISDN上网,这个就必不可少了。
19. Old CD-ROM drivers(not SCSI、not IDE)
做的可真周到,原来那些非SCSI/IDE口的光驱谁还在用啊,自己选吧,用IDE的CD-ROM不用选。
20. Character devices
字符设备。这个内容又太多了,先使用缺省设置,需要的话自己就修改。把大类介绍一下吧:
I2C support:I2C是Philips极力推动的微控制应用中使用的低速串行总线协议。如果你要选择下面的Video For Linux,该项必选。
Mice:鼠标。现在可以支持总线、串口、PS/2、C&T 82C710 mouse port、PC110 digitizer pad,自己根据需要选择。
Joysticks:手柄。即使在Linux下把手柄驱动起来意义也不是太大,游戏太少了。
Watchdog Cards:虽然称为Cards,这个可以用纯软件来实现,当然也有硬件的。如果你把这个选中,那么就会在你的/dev下创建一个名为watchdog的文件,它可以记录你的系统的运行情况,一直到系统重新启动的1分钟左右。有了这个文件,你就可以恢复系统到重启前的状态了。
Video For Linux:支持有关的音频/视频卡。
Ftape, the floppy tape device driver:
PCMCIA character device support:
21. File systems
文件系统。内容又太多了,老法子,在缺省选项的基础上进行修改。介绍以下几项:
Quota support:Quota可以限制每个用户可以使用的硬盘空间的上限,在多用户共同使用一台主机的情况中十分有效。
DOS FAT fs support:DOS FAT文件格式的支持,可以支持FAT16、FAT32。
ISO 9660 CD-ROM file system support:光盘使用的就是ISO 9660的文件格式。
NTFS file system support:ntfs是NT使用的文件格式。
/proc file system support:/proc文件系统是Linux提供给用户和系统进行交互的通道,建议选上,否则有些功能没法正确执行。
还有另外三个大类都规到这儿了:Network File Systems(网络文件系统)、Partition Types(分区类型)、Native Language Support(本地语言支持)。值得一提的是Network File Systems里面的两种:NFS和SMB分别是Linux和Windows相互以网络邻居的形式访问对方所使用的文件系统,根据需要加以选择。
22. Console drivers
控制台驱动。一般使用VGA text console就可以了,标准的80*25的文本控制台。
23. Sound
声卡驱动。如果你能在列表中找到声卡驱动那自然最好,否则就试试OSS了。
24. USB supprot
USB支持。很多USB设备,比如鼠标、调制解调器、打印机、扫描仪等,在Linux都可以得到支持,根据需要自行选择。
25. Kernel hacking
配置了这个,即使在系统崩溃时,你也可以进行一定的工作了。普通用户是用不着这个功能的。
配置完后,存盘退出,当然你也可以把现在的配置文件保存起来,这样下次再配置的时候就省力气了。
接下来是编译,输入以下命令。
#make dep
#make clean
#make bzImage或make zImage
#make modules
#make modules_install
#depmod -a
第一个命令make dep实际上读取配置过程生成的配置文件,来创建对应于配置的依赖关系树,从而决定哪些需要编译而那些不需要;第二命令make clean完成删除前面步骤留下的文件,以避免出现一些错误;make zImage和make bzImage则实现完全编译内核,二者生成的内核都是使用gzip压缩的,只要使用一个就够了,它们的区别在于使用make bzImage可以生成大一点的内核。建议大家使用make bzImage命令。
后面三个命令只有在你进行配置的过程中,在回答Enable loadable module support (CONFIG_MODULES)时选了"Yes"才是必要的,make modules和make modules_install分别生成相应的模块和把模块拷贝到需要的目录中。
严格说来,depmod -a命令和编译过程并没有关系,它是生成模块间的依赖关系,这样你启动新内核之后,使用modprobe命令加载模块时就能正确地定位模块。
更新
经过以上的步骤,我们终于得到了新版本的内核。为了能够使用新版本的内核,我们还需要做一些改动:
#cp /usr/src/linux/System.map /boot/System.map-2.4.18
#cp /usr/src/linux/arch/i386/bzImage /boot/vmlinuz-2.4.18
以上这两个文件是我们刚才编译时新生成的。下面修改/boot下的两个链接System.map和vmlinuz,使其指向新内核的文件:
#cd /boot;rm -f System.map vmlinuz
#ln -s vmlinuz-2.4.18 vmlinuz
#ln -s System.map-2.4.18 System.map
七、修改启动管理器
如果用LILO,修改/etc/lilo.conf,添加以下项:
image=/boot/vmlinuz-2.4.18
label=linux240
read-only
root=/dev/hda2
其中root=/dev/hda2一行要根据需要自行加以修改。
运行:
#/sbin/lilo -v
确认对/etc/lilo.conf的编辑无误,现在重新启动系统:
#shutdown -r now
如果是用Grub启动管理器,则添加如下几项即可。
title Red Hat Linux (2.4.18)
root (hd0,0)
kernel /vmlinuz-2.4.18 ro root=/dev/hda2
Grub不需再次调用命令,自动生效。
重启以后就可以用新内核了。
grub学习笔记
1 首先要了解的几个概念
1.1 启动管理器
启动管理器是存储在磁盘开始扇区中的一段程序,例如,硬盘的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),等等等.
1.2 什么是GRUB?
grub 是一个多重启动管理器。grub是GRand Unified Bootloader的缩写,它可以在多个操作系统共存时选择引导哪个系统。它可以引导的操作系统包括:
Linux,FreeBSD,Solaris,NetBSD,BeOSi,OS/2,Windows95/98,Windows NT,Windows2000,WinXP。它可以载入操作系统的内核和初始化操作系统(如Linux,FreeBSD),或者把引导权交给操作系统(如Windows 98)来完成引导。
1.3 GRUB的特点
特别适用于linux与其它操作系统共存情况。
支持大硬盘现在大多数Linux发行版本的lilo都有同样的一个问题:根分区(/boot分区)不能分在超过1024柱面的地方,一般是在8.4G左右的地方,否则lilo不能安装,或者安装后不能正确引导系统。而grub就不会出现这种情况,只要安装时你的大硬盘是在LBA模式下,grub就可以引导根分区在8G以外的操作系统。
支持开机画面 grub支持在引导开机的同时显示一个开机画面。对于玩家来说,这样可以制作自己的个性化开机画面;对于PC厂商,这样可以在开机时显示电脑的一些信息和厂商的标志等。grub支持640x480,800x600,1024x768各种模式的开机画面,而且可以自动侦测选择最佳模式,与Windows那320x400的开机画面不可同日而语。
两种执行模式 grub不但可以通过配置文件进行例行的引导,还可以在选择引导前动态改变引导时的参数,还可以动态加载各种设备。例如你在Linux下编译了一个新的核心,但不能确定它能不能工作,你就可以在引导时动态改变grub的参数,尝试装载这个新的核心进行使用。Grub的命令行有非常强大的功能,而且支持如bash或doskey一样的历史功能,你可以用上下键来寻找以前的命令。
菜单式选择 grub使用一个菜单来选择不同的系统进行引导。你还可以自己配置各种参数,如延迟时间,默认操作系统等。
分区大小改变后不必重新配置 grub是通过文件系统直接把核心读取到内存,因此只要操作系统核心的路径没有改变,grub就可以引导系统。
除此之外,Grub还有许多非常强大的功能。例如支持多种外部设备,动态装载操作系统内核,甚至可以通过网络装载操作系统核心。Grub支持多种文件系统,支持多种可执行文件格式,支持自动解压,可以引导不支持多重引导的操作系统,支持网络启动等。
1.4 MBR和第一扇区
你可以简单的理解为MBR是整个硬盘的物理第一位置,而第一扇区是硬盘的物理第二位置.
1.5 一个GRUB配置文件
基于本例的分区如下:
hda 15G
hda1 8G / RED HAT LINUX8.0
hda5 7G /home
hdc 20G
hdc1 6.4G WinXP
hdc5 6.4G
hdc6 6.4G
hdc7 6.4G
#fdisk -l
# Disk /dev/hdc: 255 heads, 63 sectors, 2434 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdc1 * 1 894 7181023+ b Win95 FAT32
/dev/hdc2 895 2434 12370050 f Win95 Ext'd (LBA)
/dev/hdc5 895 1787 7172991 b Win95 FAT32
/dev/hdc6 1788 2434 5196996 b Win95 FAT32
Disk /dev/hda: 255 heads, 63 sectors, 1867 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 1020 8193118+ 83 Linux
/dev/hda2 1021 1802 6281415 83 Linux
/dev/hda3 1803 1867 522112+ 82 Linux swap
grub.conf,这个文件位于;/boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/hda1
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=3
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-14)
root (hd0,0)
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/
initrd /boot/initrd-2.4.18-14.img
title Microsoft Windows XP
map (hd0) (hd1)
map (hd1) (hd0)
root (hd1,0)
chainloader (hd1,0)+1
makeactive
boot
2 解读grub.conf文件
我们将来看看grub.conf文件内语句,(注:...)内的东西是我们的解读内容.
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/hda1
# initrd /boot/initrd-version.img
#boot=/dev/hda (注:以上以符号井"#"开头的行表示被注释掉,没有任何意义)
default=0 (注:默认的操作系统就是由default控制的。default后加一个数字n,表明是第 n+1个。需要注意的是,GRUB中,计数是从0开始的,第一个硬盘是hd0,第一 个软驱是fd0,等等。所以,default 0 表示默认的操作系统在这儿是 Red Hat Linux (2.4.18-14)如果你修改成1就是WinXP了)
timeout=3 (注:timeout表示默认等待的时间,这儿是3秒钟。超过3秒,用户还没有作出选 择的话,系统将自动选择默认的操作系统;当然你可以改成任何你乐意的时间)
splashimage=(hd0,0)/boot/grub/splash.xpm.gz (注:指定开机画面文件splash.xpm.gz的位置)
title Red Hat Linux (2.4.18-14) (注:表示Red Hat Linux的菜单项)
root (hd0,0) (注:表示第一个硬盘第一个分区,这里的root和系 统内的root不是一码事!详细如下说明)
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ (注:指定内核的位置,详细说明如下 文)
initrd /boot/initrd-2.4.18-14.img (注:初始化)
title Microsoft Windows XP (注:表示Microsoft Windows XP的菜单项)
map (hd0) (hd1) (注:map是命令,详细如下)
map (hd1) (hd0)
root (hd1,0) (注:这是指第二个硬盘(从硬盘)上第一个分区)
chainloader (hd1,0)+1 (注:链式装入器,装入一个扇区的数据然后把引导 权交给它。详细说明如下)
makeactive
boot
(注:在 Linux 中,当谈到 "root" 文件系统时,通常是指主 Linux 分区。但是,GRUB 有它自己的 root 分区定义。GRUB 的 root 分区是保存 Linux 内核的分区。这可能是您的正式 root 文件系统,也可能不是。我们讨论的是 GRUB,需要指定 GRUB 的 root 分区。进入 root 分区时,GRUB 将把这个分区安装成只读型,这样就可以从该分区中装入 Linux 内核。GRUB 的一个很“酷”的功能是它可以读取本机的 FAT、FFS、minix、ext2 和 ReiserFS 分区.到目前为止,您可能会感到一点疑惑,因为 GRUB 所使用的硬盘/分区命名约定与 Linux 使用的命名约定不同。在Linux 中,第一个硬盘的第五个分区称作 "hda5"。而 GRUB 把这个分区称作 "(hd0,4)"。GRUB 对硬盘和分区的编号都是从 0 开始计算。另外,硬盘和分区都用逗号分隔,整个表达式用括号括起。现在,可以发现如果要引导 Linux 硬盘 hda5,应输入 "root (hd0,4)"。
知道了内核在哪儿,还要具体指出哪个文件是内核文件,这就是kernel的工作。
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/说明/boot/vmlinuz-2.4.18-14就是要载入的内核。后面的都是传递给内核的参数。root=LABEL=/就是linux的硬盘分区表示法,ro是readonly的意思。initrd用来初始的linux image,并设置相应的参数。
命令map:当你有两块硬盘,一个无法从第二块硬盘启动的操作系统,例如Windowsxp,就可以使用map命令.你能够将hd0映射为hd1,将hd1映射为hd0。换句话说,你可以虚拟的交换两个硬盘而启动所需要的操作系统 。命令形式如下:
grub> map (hd0) (hd1)
grub> map (hd1) (hd0)
GRUB 使用了“链式装入器”(chainloader)。链式装入器从分区 (hd1,0) 的引导记录中装入winxp自己的引导装入器,然后引导它。这就是这种技术叫做链式装入的原因 -- 它创建了一个从引导装入器到另一个的链。这种链式装入技术可以用于引导任何版本的 DOS 或 Windows。
GRUB的配置文件要简单就这么简单,如果你要更个性化一点,试一试把“color light-gray/blue ”加在default语句的下面,下一次启动GRUB时,看看有什么变化,再试一试“color light-blue/red",惊喜吗? 有趣吧! )
3 如何使用grub?
3.1 安装
你可以从
ftp://alpha.gnu.org/pub/gnu/grub 下载GRUB的源代码。
得到文件grub-0.5.96.1.tar.gz,所以这样做:
# tar -xvzf grub-0.5.96.1.tar.gz
这个命令将解开的文件和目录放在一个名为grub-0.5.96.1的目录中。现在运行如
下命令:
#cd grub-0.5.96.1
# ./configure
如果你想定制GRUB,使之包含流行的文件系统和对网卡的支持,或者删除你不需要的网卡,可以运行如下命令:
# ./configure --help
这个命令将输出所有的命令选项。现在可以使用—enable和—disable选项增加或
删除对特定网卡的支持。(注意:GRUB支持网络启动)
为了开始编译过程,键入如下命令:
# make
# make install
至此你已经为安装GRUB真正做好了准备。
将GRUB的相关文件保存在诸如/boot/grub的目录中是一个好主意。为此,按如下步骤:
1.默认状态下,GRUB所有文件将安装在/usr/share/grub/i386-pc(或者在
/usr/local/share/grub/i386-pc目录下,这只取决于你的shell变量的设置。)
2.建立一个叫做/boot/grub的目录,然后拷贝下列文件到这个目录:
stage1 stage2 * stage1 5
稍候将解释这些文件。同时也要把GRUB(可能在/usr/sbin或者/usr/local/sbin
目录下)拷贝到/boot/grub目录下。
安装GRUB可以分为三个单独的步骤:
1.将“stage1”安装到MBR中。
2.设置“stage2”的地址或者位置。
3.设置一个菜单或选项,用来决定启动哪一个操作系统。
使用下面的命令开始安装GRUB。
#cd /boot/grub
# ./grub
这个命令根据BIOS的设置检测硬件设备,同时产生一些输出信息。这会花较长的时间。
end_request: I/O error, dev 02:00 (floppy), sector 0
GRUB version 0.5.96.1 (640K lower / 3072K upper memory)
TAB键可列出可能的命令列表。其它情况下TAB会列出设备或文件名。类似下面的提示会出现:
grub>
现在,假设你将Linux安装在了第一块硬盘的第一个分区中或者/dev/hda1中。记住GRUB的命名规则,将上面的名字改为(hd0,0)。键入下面的命令:
grub> install (hd0,0)/boot/grub/stage1 (hd0) (hd0,0)/boot/grub/stage2
p (hd0,0)/boot/grub/menu.conf
现在分析一下这个命令的细节。
install
一个内置的命令,它告诉GRUB将(hd0,0)/boot/grub/stage1安装到hd0的主引导纪录中。
(hd0,0)/boot/grub/stage2
告诉GRUB stage2映象的位置。
p with the the following options: (hd0,0)/boot/grub/menu.conf
为菜单的显示设置配置文件。
下面是对这个命令用法的总结:
1.install
2.ource_of_stage1
3.where_to_install
4.source_of_stage2
5.p source_of_configuration_file
现在,你完成了硬盘上的基本安装工作。
在软盘上的安装:
为了在软盘上安装GRUB,你要会用“dd”命令,并且了解它是如何工作的。为了做一张GRUB启动盘,你要将stage1和stage2文件放到软盘的开始扇区中。
安装stage1到软盘上:
插入一张已格式化的软盘,键入命令:
# dd if=stage1 of=/dev/fd0 bs=512 count=1
命令的详细说明如下:
if=input file
i.e., stage1
of=output file
i.e., floppy drive (this may be different on your computer)
bs=bytes to read and write
Here it is 512 bytes.
count=how many times to perform this operation
每次拷贝“bs”数目的块到目标地址。
安装stage2到软盘
# dd if=stage2 of=/dev/fd0 bs=512 seek=1
这里的步骤同stage1的相同,除了一个seek选项外。Seek选项将调过一个“bs”。例如,在上面的命令中bs的值是512,这样seek=1意味着将跳过软盘上前512个字节 ,从513字节开始。这将使得第一步操作不会覆盖stage1的前512字节。
现在你完成了基本的软盘驱动器安装。
如果已经安装了grub要把grub重新安装到主引导扇区上,只需要简单打入makebootable命令就可以了。
3.2 配置grub
grub启动时会在/boot/grub/中寻找一个名字为menu.lst的配置文件,如果找不到此文件则不进入菜单模式而直接进入命令行模式。
现在,我们来看一下如何在启动后进入各种操作系统,如何建立menu.conf文件。我们就从GRUB支持的启动过程开始。可以有两种方法来完成启动过程:
·A.通过调用内核本地启动
·B.连续启动或者将控制转给另一个引导器
A模式启动过程
1.配置跟设备或者告诉GRUB你的根文件系统。
2.告诉GRUB你的内核影像的位置,然后将参数传送给内核。
3.重新启动,试一下。
为了启动Linux,将内核以bzImage的文件名放在/boot/目录中,跟文件系统是
/dev/hda1,或者GRUB中的(hd0,0)。启动过程如下:
1.root (hd0,0) [This sets the root partition]
2.kernel /boot/bzImage root=/dev/hda1 [This sets the kernel]
B模式启动过程(这种模式假设当前的分区中安装了另一个启动管理器,例如LILO
或者NTLDR):
1.设置根分区但不要安装它
2.激活这个分区
3.配置需要启动的分区的第一个扇区
4.重新启动,看一下效果。
我们在试试启动安装在/dev/hdc1或者(hd1,0)的widows。启动windows的过程如下:
1.rootnoverify (hd1,0)
2.makeactive
3.chainloader +1 [+1 sets the first sector of the current root
partition]
4.boot [transfers the control and quits GRUB]
menu.conf文件:它用于建立启动多操作系统时的菜单。建立menu.conf并不难。它使用简单的英语,就象你在这一节看到的那样。
所有的菜单项目都以没有逗号分隔的“title TITLENAME”开头。你可以随意设置
TITLENAME。
设置Linux启动菜单步骤如下:
1.设置标题
2.设置根分区
3.设置内核的相应参数
4.启动
一个菜单例子:
title Red Hat Linux (2.4.18-14)
root (hd0,0)
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/
initrd /boot/initrd-2.4.18-14.img
前面有#的行是一个注释。
建立启动Windows 或者 DOS的菜单:
title Windoze
rootnoverify (hd0,0)
makeactive
chainloader +1
boot
#----
又或者:
title Microsoft Windows XP
map (hd0) (hd1)
map (hd1) (hd0)
root (hd1,0)
chainloader (hd1,0)+1
makeactive
boot
----
注意:root和rootnoverify都是一样的,把rootnoverify改成root也行。不过经过实践来看。有时引导win时,系统安装好后,是rootnoverify (hdX.Y)这样形式的,这样会出现windows起不来,出现什么windows什么文件损坏的情况。这时,我们就要把在grub中,引导windows的那段中的rootnoverify改为root
root英文的意思就是根的意思,在这里是让linux知道自己所处的位置,也就是我们所安装linux的/根分区所在的位置 。
----
如果你安装了两个版本的Windows—一个是你自己用的,另一个给你的家人用的—这样第二个就无法安装,因为有提示说Windows已经安装了。
有一种简单的方法可以安装两个版本的Windows,即在启动时隐藏一个分区而使用另一个。你甚至可以为你的分区设置密码保护,这样可以避免别人错误的加载你的分区。下面介绍如何完成两个Windows的安装,hda1和hda2 或者 (hd0,0) 和(hd0,1),用到的命令有lock, password, hide 和 unhide。
建立windows 项目"My Entry":
title My Entry
lock
unhide (hd0,0)
hide (hd0,1)
rootnoverify (hd0,0)
makeactive
chainloader +1
boot
#----
为了更好的使用lock命令,你需要在配置文件开头使用password命令。Password命令的语法如下:password secret(“secret”就是密码)。任何时候你都可以通过按p键儿输入密码。
建立Windows 项目"Family Entry"
title Family Entry
unhide (hd0,1)
hide (hd0,0)
rootnoverify (hd0,1)
makeactive
chainloader +1
boot
任何人都可以启动这个项目,而无须输入密码。
这有一个使用password命令的有趣的窍门。为了在缺省菜单列表或配置文件中隐藏某些项目,你可以使用下面的命令加载一个定制的列表:
password secret
在这个命令中,“secret”是密码,而/boot/grub/secret-list.conf是密码文件。这样做之前,你要先进入到根目录或者给出全路径名。例如:
password secret (hd0,4)/boot/grub/secret-list.conf
还有一个更重要的命令是“map”。当你有两块硬盘,一个无法从第二块硬盘启动的操作系统,例如Windows,就可以使用map命令。例如,你能够将hd0映射为hd1,将hd1映射为hd0。换句话说,你可以虚拟的交换两个硬盘而启动所需要的操作系统。命令形式如下:
grub> map (hd0) (hd1)
grub> map (hd1) (hd0)
启动FreeBSD:
title FreeBSD 4.0
root (hd0,4,a)
kernel /boot/loader
boot
#----
这里我们调用了FreeBSD的启动管理器。Root (hd0,4,a)由四个参数,是因为
FreeBSD对一个单独分区进行了虚拟分割。我们称根分区为“a”。如果FreeBSD占
据了整个第二块硬盘,这里就应该是root (hd0,a)。这样,就不是调用内核而是调用FreeBSD的启动管理器,它要比调用内核更易使用。
(注意:推荐在使用OpenBSD和GNU/Hurd之前,要先试一下链式加载。)
现在你已经完成了基本的GRUB编译、安装和配置。你对GRUB了解的越多,就越会发现GRUB是一种控制启动的易用和高效的方法。
各种GRUB命令:
default xx
表明xx是缺省的启动项目
timeout yy
表明在yy秒后缺省启动项目将启动
fallback zz
在第一个启动项目失败后,过了timeout时间后,就将启动zz项目。
color
这个命令将生成彩色菜单。它的语法是:color normal current_selection。这两个域都可以有两个值,形如foreground/background。例如:
color green/black or light-gray/blue
你也可以使用相关的数字。
记住:所有的值都是从0开始,所以0是第一个
3.3 GRUB启动盘
要制作引导盘,需执行一些简单的步骤。首先,在新的软盘上创建 ext2 文件系统。然后,将其安装,并将一些 GRUB 文件复制到该文件系统,最后运行 "grub" 程序,它将负责设置软盘的引导扇区。
将一张空盘插入 1.44MB 软驱,输入:
# mke2fs /dev/fd0
创建了 ext2 文件系统后,需要安装该文件系统:
# mount /dev/fd0 /mnt/floppy
现在,需要创建一些目录,并将一些关键文件(原先安装 GRUB 时已安装了这些文件)复制到软盘:
# mkdir /mnt/floppy/boot
# mkdir /mnt/floppy/boot/grub
# cp /boot/grub/stage1 /mnt/floppy/boot/grub
# cp /boot/grub/stage2 /mnt/floppy/boot/grub
再有一个步骤,就能得到可用的引导盘。
在linux bash中,从 root 用户运行“grub”,该程序非常有趣并值得注意,因为它实际上是GRUB 引导装入器的半功能性版本。尽管 Linux 已经启动并正在运行,您仍可以运行 GRUB 并执行某些任务,而且其界面与使用 GRUB 引导盘或将 GRUB 安装到硬盘 MBR 时看到的界面(即GRUB控制台)完全相同。
在 grub> 提示符处,输入:
grub> root (fd0)
grub> setup (fd0)
grub> quit
现在,引导盘完成了。
如果要把GRUB装到硬盘上,也很容易。这个过程几乎与引导盘安装过程一样。首先,需要决定哪个硬盘分区将成为 root GRUB 分区。在这个分区上,创建 /boot/grub 目录,并将 stage1 和 stage2 文件复制到该目录中,可以通过重新引导系统并使用引导盘,或者使用驻留版本的 GRUB 来执行后一步操作。在这两种情况下,启动 GRUB,并用 root 命令指定 root 分区。例如,如果将 stage1 和 stage2 文件复制到 hda5 的 /boot/grub 目录中,应输入 "root (hd0,4)"。接着,决定在哪里安装 GRUB -- 在硬盘的 MBR,或者如果与 GRUB 一起使用另一个“主”引导装入器,则安装在特定分区的引导记录中。如果安装到 MBR,则可以指定整个磁盘而不必指定分区,如下(对于 hda):
grub> setup (hd0)
如果要将 GRUB 安装到 /dev/hda5 的引导记录中,应输入:
grub> setup (hd0,4)
现在,已安装 GRUB。引导系统时,应该立即以 GRUB 的控制台方式结束(如果安装到 MBR)。现在,应创建引导菜单,这样就不必在每次引导系统时都输入那些命令。
从软盘启动grub
制作启动盘后可以用软盘启动引导硬盘上的操作系统, 插入制作好的启动软盘,进入BIOS设定软盘启动。软盘启动成功后就会进入grub的命令行模式
grub>
要启动一个操作系统,首先指定引导哪个分区上的系统,例如要引导指第一个硬盘上的第一个分区的操作系统,先键入
grub>root (hd0,0)
接着如果要启动的是Windows系统,键入
grub>chainloader (hd0,0)+1
注意(hd0,0)要随着硬盘和分区的不同而改变数字。
如果要引导Linux或其他系统,应键入
grub>kernel (hd0,0)/boot/vmlinuz root=/dev/hda1
注意hda1参数也要随着硬盘和分区的不同而改变,如从第二个硬盘的第一个分区引导则用hdb1。
最后敲入boot就可以启动系统了。
在任何时候不能确定命令或者命令的参数都可以按Tab获得相关的帮助。用上下键可以获得命令的历史记录。其实这些命令就是menu.lst的启动描述,您也可以根据那些描述来自己键入启动命令,最后敲入boot就可以引导系统了。
4 GRUB的交互性
GRUB 最好的优点之一就是其强健的设计 -- 在不断使用它时请别忘了这点。如果更新内核或更改它在磁盘上的位置,不必重新安装 GRUB。事实上,如有必要,只要更新 menu.lst 文件即可,一切将保持正常。
只有少数情况下,才需要将 GRUB 引导装入器重新安装到引导记录。首先,如果更改 GRUB root 分区的分区类型(例如,从 ext2 改成 ReiserFS),则需要重新安装。或者,如果更新 /boot/grub 中的 stage1 和 stage2 文件,由于它们来自更新版本的 GRUB,很有可能要重新安装引导装入器。其它情况下,可以不必理睬!
GRUB的最大的特点就是交互性特别强。在开机时,按一下“c”,将进入GRUB 控制台。显示如下:
GRUB version 0.5.96.1 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub>
欢迎使用 GRUB 控制台。现在,再研究命令:
将通过GRUB 控制台绕过lilo来启动RedHat linux,
grub> root (h
现在,按一次 Tab 键。如果系统中有多个硬盘,GRUB 将显示可能完成的列表,从 "hd0" 开始。如果只有一个硬盘,GRUB 将插入 "hd0,"。如果有多个硬盘,继续进行,在 ("hd2") 中输入名称并在名称后紧跟着输入逗号,但不要按 Enter 键。部分完成的 root 命令看起来如下:
grub> root (hd0,
现在,继续操作,再按一次 Tab 键。GRUB 将显示特定硬盘上所有分区的列表,以及它们的文件系统类型。在我的系统中,按 Tab 键时得到以下列表:
grub> root (hd0, (tab,按tab一下键)
Possible partitions are:
Partition num: 0, Filesystem type is fat, partition type 0x6
Partition num: 2, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type unknown, partition type 0x7
Partition num: 5, Filesystem type is ext2fs, partition type 0x83
Partition num: 6, Filesystem type is fat, partition type 0xb
Partition num: 7, Filesystem type is fat, partition type 0xb
Partition num: 8, Filesystem type is ext2fs, partition type 0x83
Partition num: 9, Filesystem type unknown, partition type 0x82
如您所见,GRUB 的交互式硬盘和分区名称实现功能非常有条理。这些,只需要好好理解 GRUB 新奇的硬盘和分区命名语法,然后就可以继续操作了
grub> root (hd0,8)
现在已安装了 root 文件系统,到装入内核的时候了
grub> kernel /boot/vmlinuz-2.4.2 root=/dev/hda5 ro
[Linux-bzImage, setup=0x1200, size=0xe1a30]
您已经安装了 root 文件系统并装入了内核。现在,可以引导了。只要输入 "boot",Linux 引导过程就将开始。是不是很cool啊,GRUB的menu.lst更像一个linux下的脚本程序。
5 常见grub除错方法的思路
首先进去Linux的rescue模式!
用软盘或光盘启动,然后在启动的提示符输入:linux rescue
按照提示进入一个Shell状态,你可以到/mnt/下面看到一个sysimage这么目录,进去以后,就是你安装linux的/分区.
使用命令将根分区变为当前目录的根分区:chroot /mnt/sysimage
然后转到/sbin/这个目录中.
使用fdisk -l 显示当前分区情况,然后使用#grub-install /dev/hdx(x为你使用的是那块硬盘安装的,一般情况下是hda)
使用exit推出chroot,再使用exit退出linux rescue模式,系统将重新启动!取出光盘,应该可以看到grub安装好了.
在具体的环境中,编辑/boot/grub/grub.conf文件和menu.lst文件.