手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux 内核编译详解

[日期:2012-03-11] 来源:Linux社区  作者:ylqmf [字体:大 中 小]

编译配置

在这一部分涉及几个重要模块的配置请,特别注意.一般用"make menuconfig"命令来配置内核.

输入以上命令后出现一个菜单界面,用户可以对需要的模块.下面着重讲几个重要的配置

1)文件系统

请务必要选中ext3文件系统,

  File systems--->

  [*] Ext3 journalling file system support

  [*] Ext3 Security Labels

  [*] JBD (ext3) debugging support

  以上三项一定要选上,而且要内建(即标*). 这个非常重要,在配置完后一定要检查一下.config文件有没有"CONFIG_EXT3_FS=y"这一项. 如果不是"CONFIG_EXT3_FS=y"而是"CONFIG_EXT3_FS=m",你在运行内核时就会遇上以下错误: pivotroot: pivot_root(/sysroot,/sysroot/initrd) failed

  

2)网卡驱动

  请务必把自己网卡对应的驱动编译进内核,比较普遍的网卡是realtek 8139,以下就是这种网卡的配置,以供参考

  Device Drivers--->

  Networking support--->

  Ethernet (10 or 100Mbit) --->

  <*> RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL)

  <*> RealTek RTL-8139 PCI Fast Ethernet Adapter support

3)声卡驱动

  也要选择自己声卡对应的驱动编译进内核,比较普遍的声卡是i810_audio,以下就是这种声卡的配置,以供参考

  Device Drivers --->

  Sound --->

  <*> Sound card support

  Advanced Linux Sound Architecture --->

  <*> Advanced Linux Sound Architecture

  <*> Sequencer support

  < > Sequencer dummy client

  <*> OSS Mixer API

  <*> OSS PCM (digital audio) API[*] OSS Sequencer API

  <*> RTC Timer support

  PCI devices --->

  <*> Intel i8x0/MX440, SiS 7012; Ali 5455; NForce Audio; AMD768/8111

  Open Sound System --->

  < > Open Sound System (DEPRECATED)

以上三项配置关系到新内核能否正常运行,请备加注意.其他的配置如果不是很了解,大可以按默认的选择.

 

#make dep (确保关键文件在正确的位置) 2.5.*-2.6.0都不需要了。其实2.4.*某些内核也不需要了。

                          

#make clean (确保所有有关文件都处于最新版本状态)

                          

#make zImage (编译压缩形式的内核)

                          

在需要内核支持较多的外设和功能时,内核可能变得很大,此时可以编译大内核:

                          

#make bzImage

                          

编译的时间与机器的硬件条件及内核的配置等因素有关,所获得的内核的位置在/usr/src/linux/arch/i386/boot目录下,当然这里假设用户的CPU是x86型的。

                          

如果选择了可加载模块,编译完内核后,要对选择的模块进行编译:

                          

#make modules (编译选择的模块)

                          

#make module_install (将编译后的模块转移到系统标准位置)

 

# make install

 

上面的命令"make install"将:

 (1)把压缩内核映象拷贝到/boot目录下, 并创建相应的System.map符号链接;

 (2)修改bootloader的配置文件;

 (3)调用mkinitrd程序创建内核的initrd映象. 对于GRUB而言, 将在/boot/grub/grub.conf配置文件增加如下类似的配置行:

 

      title Red Hat Linux (2.***)

      root(hd0, 1)

      kernel /boot/vmlinuz-2.*** ro root=LABEL=/

      initrd /boot/initrd-2.***.img

                          

模块在系统中的标准目录位于/lib/modules/x.y.z,后面的x.y.z是版本号,为安全起见,在运行#make  modules_install之前最好对/lib/modules进行备份。模块通常是带有扩展名.o的文件,使用命令#lsmod可以对当前内核的模块进行列表。

                          

我一般是make bzImage;make modules;make module_install; make install

                          

运行新内核之前,请检查一下/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 have a /boot partition.  This means that

#          all kernel and initrd paths are relative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00

#          initrd /initrd-version.img

#boot=/dev/hda

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Fedora Core (2.6.18.2)

        root (hd0,0)

        kernel /vmlinuz-2.6.18.2 ro root=/dev/VolGroup00/LogVol00 rhgb quiet

        initrd /initrd-2.6.18.2.img

title Fedora Core (2.6.18-1.2798.fc6)

        root (hd0,0)

        kernel /vmlinuz-2.6.18-1.2798.fc6 ro root=/dev/VolGroup00/LogVol00 rhgb quiet

        initrd /initrd-2.6.18-1.2798.fc6.img

现在重启机器,即可测试最新的内核。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款