原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://shanks.blog.51cto.com/3899909/1387489

fullnat开源已经有一阵子了,内核版本为2.6.32-220.23.1.e16,项目地址http://kb.linuxvirtualserver.org/wiki/IPVS_FULLNAT_and_SYNPROXY。本屌编译测试环境如下:

centos6.3 64位

编译过程参照官方做法,只是融入后续的打rpm包的部分。过程如下:

一、下载相关代码:

   下载 kernel-2.6.32-220.23.1.el6.src.rpmlinux-2.6.32-220.23.1.el6.x86_64.lvs.src.tar.gz

lvs-fullnat-synproxy.tar.gz

二、编译内核

1、安装kernel-2.6.32-220.23.1.el6.src.rpm

1
rpm -ivh kernel-2.6.32-220.23.1.el6.src.rpm

2、生成内核源码

   默认的,你会在root家目录下看到rpmbuild目

1
2
cd ~ /rpmbuild/SPECS
rpmbuild -bp kernel.spec

3、对生成的内核源码打patch默认的

1
2
3
4
5
6
7
8
9
10
#在/usr/local/src下解压linux-2.6.32-220.23.1.el6.x86_64.lvs.src.tar.gz
tar zxf linux-2.6.32-220.23.1.el6.x86_64.lvs.src. tar .gz
#打patch
cd ~ /rpmbuild/BUILD/kernel-2 .6.32-220.23.1.el6 /linux-2 .6.32-220.23.1.el6.x86_64/
cp /usr/local/src/linux-2 .6.32-220.23.1.el6.x86_64.lvs /lvs-2 .6.32-220.23.1.el6.patch .
#淘宝将IP_VS改成了22,测试时遇到些麻烦,因此改为20了。
#vim .config
CONFIG_IP_VS_TAB_BITS=20
#你可以修改Makefile把内核的名称做下标记(line:4)
EXTRAVERSION = .FNAT.shanks.e27.x86_64

4、make

1
2
3
make -j16
make modules_install
make install ;

5、配置grub.conf

1
2
#vim /boot/grub/grub.conf
default=0

三、reboot

   reboot之后uname -r看下是不是你想要的内核。

四、打内核rpm包

1、安装kernel-2.6.32-220.23.1.el6.src.rpm

1
rpm -ivh /usr/local/src/kernel-2 .6.32-220.23.1.el6.src.rpm

2、生成内核源码目录

1
rpmbuild -bp ~ /rpmbuild/SPECS/kernel .spec

3、复制出一份内核源码目录

1
2
cd ~ /rpmbuild/BUILD/kernel-2 .6.32-220.23.1.el6/
cp -a linux-2.6.32-220.23.1.el6.x86_64/ linux-2.6.32-220.23.1.el6.x86_64_new

4、为内核打fullnat的patch

1
2
3
cd linux-2.6.32-220.23.1.el6.x86_64_new/
patch -p1 < /usr/local/src/lvs-2 .6.32-220.23.1.el6.patch
cp .config ~ /rpmbuild/SOURCES/config-x86_64-generic

5、删除原来内核源码目录中的.config文件。

1
2
cd ~ /rpmbuild/BUILD/kernel-2 .6.32-220.23.1.el6 /linux-2 .6.32-220.23.1.el6.x86_64
rm -rf .config

   不删的话,会在最后打rpm时遇到报错

wKioL1NM8jWhm-LPAAK42XDh8KU043.jpg

6、打自己的patch

1
2
cd ~ /rpmbuild/BUILD/kernel-2 .6.32-220.23.1.el6/
diff -uNr linux-2.6.32-220.23.1.el6.x86_64 linux-2.6.32-220.23.1.el6.x86_64_new/ > ../.. /SOURCES/lvs-2 .6.32-220.23.1.el6.patch

7、编辑kernel.spec

1
2
3
4
5
6
7
8
9
vim ~ /rpmbuild/SPECS/kernel .spec
line:9    打上个版本号
     %define dist .e27
line:22    打上个名称的标记
     %define distro_build fnat.shanks
line:605    标记下自己的patch
     Patch999999: lvs-2.6.32-220.23.1.el6.patch
line:915    让自己的patch生效
     ApplyOptionalPatch lvs-2.6.32-220.23.1.el6.patch

8、打rpm

1
rpmbuild -bb --with baseonly --with firmware --without debuginfo --target=x86_64 SPECS /kernel .spec
1
2
3
4
5
6
7
8
9
10
11
12
在这里如果遇到这样的报错:
+ cp /root/rpmbuild/SOURCES/Module .kabi_x86_64 /root/rpmbuild/BUILDROOT/kernel-2 .6.32-fnat.shanks.e27.x86_64 /Module .kabi
+ /root/rpmbuild/SOURCES/check-kabi -k /root/rpmbuild/BUILDROOT/kernel-2 .6.32-fnat.shanks.e27.x86_64 /Module .kabi -s Module.symvers
*** ERROR - ABI BREAKAGE WAS DETECTED ***
The following symbols have been changed (this will cause an ABI breakage):
register_ip_vs_scheduler
unregister_ip_vs_scheduler
+ exit 1
error: Bad exit status from /var/tmp/rpm-tmp .0Wfj33 (%build)
RPM build errors:
     Bad exit status from /var/tmp/rpm-tmp .0Wfj33 (%build)
可以在rpmbuild的时候加上--without kabichk


参考:https://fedoraproject.org/wiki/Building_a_custom_kernel/zh-cn

   http://wiki.centos.org/HowTos/Custom_Kernel

Logo

更多推荐