• 幕客老师召集小伙伴
  • 运维高手36项修炼
  • python自动化运维项目实战
  • nginx从入门到实战
  • 阿里云与Centos7实战

Linux内核(为内核添加新模块)

注:使用和当前内核版本完全匹配内核源码包
1. 查看当前内核版本

[root@jeson ~]# uname -r 2.6.32-358.el6.x86_64 

2. 下载内核源码
ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server
kernel-2.6.32-358.el6.src.rpm

ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/
ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS/kernel-2.6.32-358.el6.src.rpm

3. 需要工具rpm-build,开发库,ncurses-devel

 

[root@jeson ~]# yum install -y redhat-rpm-config  patchutils xmlto asciidoc elfutils-libelf-devel zlib-devel binutils-devel newt-devel python-devel bison flex hmaccalc gcc popt-devel docbook-utils[root@jeson ~]# rpm -q rpm-build
rpm-build-4.8.0-32.el6.x86_64

 

4. 产生kernel源码
//释放src.rpm  

[root@jeson ~]# rpm -ivh kernel-2.6.32-358.el6.src.rpm[root@jeson ~]# ls rpmbuild/
SOURCES  SPECS
[root@jeson ~]# ls rpmbuild/SOURCES/

//将源码解压,并打补丁。

[root@jeson ~]# rpmbuild -bp --target=$(uname -m)~/rpmbuild/SPECS/kernel.spec   
[root@jeson ~]# ls rpmbuild/
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS
[root@jeson ~]# cd ~/rpmbuild/BUILD/kernel-2.6.32-358.el6/linux-2.6.32-358.el6.x86_64/


例1:让kernel支持jfs文件系统(模块 jfs.ko)
以下的操作在内核的源码目录
1.修改Makefile文件并修改如下行:
vim Makefile 
取EXTRAVERSION的值:
    uname -r
####################################
EXTRAVERSION = 2.6.32-358.el6.x86_64
###################################
 
2.编译配置文件
make oldconfig
3. 编译模块

 

[root@LiangPad linux-2.6.32-358.el6.x86_64]# make menuconfig<M>Reiserfs support                                                	[]Enable reiserfs debug mode (NEW)[]Statsin/proc/fs/reiserfs (NEW)[]ReiserFS extended attributes (NEW)<M> JFS filesystem support                            	[]   JFS POSIX AccessControlLists(NEW)[]   JFS SecurityLabels(NEW)[]   JFS debugging (NEW)[]   JFS statistics (NEW)

 

[root@LiangPad linux-2.6.32-358.el6.x86_64]# make fs/jfs/jfs.ko     //编译模块[root@LiangPad linux-2.6.32-358.el6.x86_64]# make fs/reiserfs/reiserfs.ko	//编译模块

4. 复制模块到当前内核模块目录/lib/modules

[root@LiangPad linux-2.6.32-358.el6.x86_64]# mkdir /lib/modules/$(uname -r)/kernel/fs/{reiserfs,jfs}[root@LiangPad linux-2.6.32-358.el6.x86_64]# cp fs/jfs/jfs.ko /lib/modules/2.6.32-358.el6.x86_64/kernel/fs/jfs/[root@LiangPad linux-2.6.32-358.el6.x86_64]# cp fs/reiserfs/reiserfs.ko /lib/modules/2.6.32-358.el6.x86_64/kernel/fs/reiserfs/

5. 重新生成模块的依赖关系

[root@LiangPad ~]# ls /lib/modules/2.6.32-358.el6.x86_64/
build              modules.ccwmap       modules.modesetting  modules.symbols.bin
extra             modules.dep          modules.networking   modules.usbmap
kernel            modules.dep.bin      modules.ofmap        source
[root@jeson 2.6.18-308.el5]# depmod -a   

 


========================================================
扩展知识:
创建jfs、reiserfs文件系统

安装依赖库
yum install e2fsprogs-libs e2fsprogs-devel libuuid-devel -y
1.安装创建jfs文件系统的软件[root@jeson ~]# tar xvf  jfsutils-1.1.15.tar.gz   [root@jeson ~]# cd jfsutils-1.1.15[root@jeson jfsutils-1.1.15]# ./configure && make && make install 2.准备分区或卷3.创建文件系统[root@jeson ~]# mkfs.jfs /dev/sda5[root@jeson ~]# mkreiserfs /dev/sda6[root@jeson ~]# mkdir /mnt/jfs[root@jeson ~]# mount /dev/sda5  /mnt/jfs[root@jeson ~]# lsmod |grep jfs
jfs                   1492281

管理模块
modinfo 查看模块的信息  modinfo jfs   modinfo -n jfs
lsmod   查看已加载的模块
modprobe jfs   手动加载模块
modprobe -r xfs 移出模块 
========================================================

错误1:
checking for uuid/uuid.h… no
configure: error: ‘Install e2fsprogs-libs e2fsprogs-devel or uuid-dev’

解决方法:
[root@jeson ~]# yum -y install libuuid-devel

错误2:
kernel/fs/jfs/jfs.ko): Required key not availabled 
dmesg命令后的报错:jfs: no symbol version for module_layout

解决方法:
将Module signature verification选项关闭,

Linux内核(为内核添加新模块)

Pingbacks已打开。

引用地址

暂无评论

发表评论