Chinaunix首页 | 论坛 | 博客
  • 博客访问: 749982
  • 博文数量: 434
  • 博客积分: 11187
  • 博客等级: 上将
  • 技术积分: 5221
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 01:00
文章分类

全部博文(434)

文章存档

2016年(2)

2013年(1)

2012年(115)

2011年(195)

2010年(32)

2009年(89)

分类: LINUX

2010-02-03 17:19:08

linux 内核编译
一、准备阶段
1、kernel-2.6.32.6:
wget
2、iptables-1.4.6:
wget
wget
3、netfilter-layer7:
wget %20kernel%20version/2.22/netfilter-layer7-v2.22.tar.gz?use_mirror=cdnetworks-kr-2
帮助文件:
非常不错的帮助文档,如果安装前详细阅读,安装过程中能减少很多错误,因为没有事先看,害得我重编译了好多次;
4、l7-protocols-2009-05-28:
wget %20definitions/2009-05-28/l7-protocols-2009-05-28.tar.gz?use_mirror=cdnetworks-kr-1
5、将上述文件下载至/usr/src 下,解压:
tar -jxvf iptables-1.4.6.tar.bz2  && tar -zxvf l7-protocols-2009-05-28.tar.gz && tar -zxvf netfilter-layer7-v2.22.tar.gz && \
tar -jxvf linux-2.6.32.6.tar.bz2 && bunzip2 patch-iptables-1.4.5-1.4.6.bz2

二、开始编译
1、切换到 l7-protocols-2009-05-28 目录,执行 make install
#cd l7-protocols-2009-05-28
#cat Makefile
all:
        @echo Nothing to compile, just run \'make install\'
        @echo \(This simply copies this directory into $(PREFIX)/etc/l7-protocols \)
install:
        mkdir -p $(PREFIX)/etc/l7-protocols
        cp -R * $(PREFIX)/etc/l7-protocols

#make install

2、切换至 linux-2.6.32.6 目录,编译 kernel
#cd linux-2.6.32.6

#利用发行版本提供的.config 来配置, 这样方便点;
#cp /boot/config-2.6.18-128.el5  .config

#patch -p1   How to patch a source tree
  Suppose you have a patch called happy.patch. To apply it, go into the root directory of the
  source tree you want to patch and run "patch -p1 < happy.patch"

#make mrproper
#make menuconfig #需要 gcc 和 ncurses-devel 的支持,如果没有安装,yum 安装;

Load an Alternate Configuration Fileà载入刚才复制过来的.config,然后执行下面操作:
make menuconfig-->Networking support-->Networking options-->Network packet filtering framework (Netfilter)
勾选需要的模块,然后退出,保存至.config。
备注:
     内核配置有两种方法,一种是直接置入内核 * ;另一种是编成模块 M ;两种方法各有优点;直接编入内核的,
比如设备的启动,不再需要加载模块的这一过程了;而编译成模块,则需要加载设备的内核支持的模块;但直接把
所有的东西都编入内核也不是可行的,内核体积会变大,系统负载也会过重。我们编内核时最好把极为重要的编入
内核;其它的如果您不明白的,最好用默认。
 如果不勾选“Netfilter connection tracking support”   ,那么“”layer7” match support”将不会在这里显示出来,
务必将“Netfilter connection tracking support”打上对勾。

# make && make modules_install && make install
# vi /boot/grub/grub.conf       #以新内核启动系统,重启系统;

###############################################################################
备注:
make install 时报警告:
WARNING: No module dm-mem-cache found for kernel 2.6.32.6, continuing anyway
WARNING: No module dm-message found for kernel 2.6.32.6, continuing anyway
WARNING: No module dm-raid45 found for kernel 2.6.32.6, continuing anyway

解决办法:
一、是当使用mkinitrd时,使用”–without-dmraid”这个参数。然后再运行mkinitrd命令。
# mkinitrd /boot/initrd-2.6.32.6.img 2.6.32.6 --without-dmraid
执行完mkinitrd后,就要在启动菜单中增加编译好的内核信息,以便启动时可以选择内核版本。
# cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.32.6
# cp System.map /boot/System.map-2.6.32.6
打开/etc/grub.conf文件,增加以下内容到文件结尾。
title CentOS (2.6.32.6)
        root (hd0,0)
        kernel /vmlinuz-2.6.32.6 ro root=LABEL=/
        initrd /initrd-2.6.32.6.img
保存,重启,进行grub的启动菜单中,选择”CentOS(2.6.32.6)”,即可使用编译好的内核

二、是在使用mkinitrd之前,先创建一个noraid文件。创建方法如下:
# echo "DMRAID=no" > /etc/sysconfig/mkinitrd/noraid
# chmod 755 /etc/sysconfig/mkinitrd/noraid
然后再运行make install命令。

三、新内核启动系统是报错:
could not find filesystem '/dev/root'
终于找到了 这个网页,从里面找到了Solution,问题出在了CONFIG_SYSFS_DEPRECATED_V2这个选项上了.
解决办法如下编辑内核源码包里面的.config文件.
CONFIG_SYSFS_DEPRECATED_V2=y #默认该选项为not set,被注释掉的.
然后再编译一遍内核就都OK了.


###############################################################################


3、切换至 iptables-1.4.6 目录,编译 iptables
通过rpm -qa|grep iptables 查找系统已经安装的iptables rpm包
通过rpm -e 删除iptables rpm包

layer7 官方帮助:
    
  iptables 1.4.1.1 and newer
  Copy libxt_layer7.c and libxt_layer7.man (from the subdirectory of the "Layer 7 patches"
  package that the README points you to) to the extensions/ directory of your iptables source.
  Then:
     "./configure --with-ksource=/path/to/patched/kernel_source" (use the full path)
     "make"
     (as root) "make install"

#cd iptables-1.4.6
#cp /usr/src/netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/*  /usr/src/iptables-1.4.6/extensions/
#./configure --with-kernel=/usr/src/linux-2.6.32.6 --with-ksource=/usr/src/linux-2.6.32.6  --enable-static --enable-shared && make && make install && reboot
备注:
 如果不将/usr/src/netfilter-layer7-v2.22/iptables-1.4.1.1-for-kernel-2.6.20forward/下的 libxt_layer7.c、       libxt_layer7.man
拷贝至/usr/src/iptables-1.4.32.6/extensions/下,编译时将出现大量错误提示,编译失败,另外执行 iptables 规则时将出
现以下错误提示:
 iptables v1.4.6: Couldn't load match `layer7':/usr/local/libexec/xtables/libipt_layer7.so: cannot open shared object file:
 No such file or directory
 Try `iptables -h' or 'iptables --help' for more information.
###############################################################################
 备注:
报kernel: can't load conntrack support for proto=2错误:由于/lib/kernel/net/ipv4/netfilter/下面缺少一个缺少 nf_conntrack_ipv4.ko 造成的
 iptables 编译安装前,删除系统里面RPM的iptables :
 find / -name iptables|xargs rm -rf
 
 grep CONNTRACK /boot/config-$(uname -r)
# CONFIG_NF_CONNTRACK_IPV4 is not set

编译内核时 make menuconfig 后,需要修改.config文件:
CONFIG_SYSFS_DEPRECATED_V2=y
CONFIG_NF_CONNTRACK_IPV4=y
###############################################################################
阅读(1724) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~