内核编译及模块相关命令使用

        本文讲解了怎样进行内核编译及模块相关命令的使用方法。


一 Linux内核相关信息

 

#查看Linux系统
[root@serv01 ~]# uname
Linux
#查看所有信息
[root@serv01 ~]# uname -a
Linux serv01.host.com2.6.32-131.0.15.el6.x86_64 #1 SMP Tue May 10 15:42:40
EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
#内核信息
[root@serv01 ~]# uname -r
2.6.32-131.0.15.el6.x86_64
 
 
#/boot目录下
/boot
#驱动
initrd-2.6.32-131.0.15.el6.x86_64kdump.img
#内核
vmlinuz-2.6.32-131.0.15.el6.x86_64
 
#桌面版的内核存放位置
[root@larrywen boot]# cd/usr/src/kernels/2.6.32-131.0.15.el6.x86_64/
[root@larrywen 2.6.32-131.0.15.el6.x86_64]#ls
arch  crypto   firmware  include ipc     lib       Makefile.common  Module.symvers  samples security  System.map  usr
block drivers  fs        init    kernel  Makefile  mm               net             scripts  sound    tools       virt
 
#解压内核到/usr/src下
[root@serv01 ~]# tar -xvf linux-2.6.38.tar.gz-C /usr/src/
[root@serv01 ~]# cd /usr/src/linux-2.6.38/
[root@serv01 linux-2.6.38]# pwd
/usr/src/linux-2.6.38
 
#已经安装好的版本有配置文件
[root@larrywen ule-sa2]# cd/usr/src/kernels/2.6.32-131.0.15.el6.x86_64/
[root@larrywen 2.6.32-131.0.15.el6.x86_64]#ls .config
.config
 
#查看配置文件
[root@serv01 linux-2.6.38]# vim/boot/config-2.6.32-131.0.15.el6.x86_64
 
#源码不区分32位和64位
 
#查看make帮助
#需要在linux-2.6.38目录下
[root@serv01 linux-2.6.38]# make help
clean 清除,保留配置文件
mrproper 清除,不保留配置文件,更彻底
 
make menuconfig:图形界面
make xconfig:图形界面,需要安装QT
#<*>:制作成内核
#<M>:制作成模块

 

 

二 编译配置

 

[root@serv01 linux-2.6.38]# make menuconfig
 HOSTCC  scripts/basic/fixdep
 HOSTCC  scripts/basic/docproc
 HOSTCC  scripts/kconfig/conf.o
 HOSTCC scripts/kconfig/kxgettext.o
 ***Unable to find the ncurses libraries or the
 ***required header files.
 ***'make menuconfig' requires the ncurses libraries.
 ***
 ***Install ncurses (ncurses-devel) and try again.
 ***
make[1]: ***[scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
[root@serv01 linux-2.6.38]# yum install"ncurses-devel" -y
 
#OCFS:Oracle Class FileSystem
 
 
#配置后生成.config文件
[root@serv01 linux-2.6.38]# ls .config
[root@serv01 linux-2.6.38]# vim Makefile
 
[root@serv01 linux-2.6.38]# lsarch/x86/boot/ -d
arch/x86/boot/

 

 

三 编译

 

[root@serv01 linux-2.6.38]# make bzImage
Root device is (8, 2)
Setup is 14908 bytes (padded to 15360bytes).
System is 3704 kB
CRC 7521c374
Kernel: arch/x86/boot/bzImage is ready  (#1)

 

 

四 编译模块

 

[root@serv01 linux-2.6.38]# make modules

 

 

五 安装模块

 

[root@serv01 linux-2.6.38]# makemoudule_install
#make moudule_install拷贝到该目录
[root@serv01 linux-2.6.38]# ls/lib/modules/2.6.32-131.0.15.el6.x86_64/kernel/
 
[root@serv01 linux-2.6.38]# ls/lib/modules/2.6.38/kernel
#出现这个错误是因为交换分区过小
 
/bin/sh: line 1: 10010 Killed                  /sbin/depmod -ae -F System.map2.6.38
make: *** [_modinst_post] Error 137

 

六 安装

 

[root@serv01 linux-2.6.38]# make install
#可以比较下已有版本和编译的版本的不同,(编译版本:没选防火墙)
[root@serv01 linux-2.6.38]# ls/lib/modules/2.6.38/kernel/net/
802   9p   bluetooth  can  dccp          ieee802154  ipv6 llc       phonet  rfkill sctp    wimax     xfrm
8021q atm  bridge     core dns_resolver  ipv4        key  mac80211  rds     sched  sunrpc  wireless
[root@serv01 linux-2.6.38]# ls/lib/modules/2.6.32-131.0.15.el6.x86_64/kernel/net/
802   9p   bluetooth  can  dccp        ipv4  key mac80211   phonet  rfkill sctp    wimax     xfrm
8021q atm  bridge     core ieee802154  ipv6  llc netfilter  rds     sched  sunrpc  wireless
 
[root@serv01 linux-2.6.38]# ls /lib/modules/2.6.38/kernel/fs/ntfs/ntfs.ko
 
[root@serv01 linux-2.6.38]# ls/boot/grub/grub.conf
/boot/grub/grub.conf
[root@serv01 linux-2.6.38]# cat/boot/grub/grub.conf
# grub.conf generated by anaconda
# #
# # Note that you do not have to rerun grubafter making changes to this file
# # NOTICE: You have a /boot partition.  Thismeans that
# #         all kernel and initrd paths are relative to /boot/, eg.
# #         root (hd0,0)
# #         kernel /vmlinuz-version ro root=/dev/sda2
# #         initrd /initrd-[generic-]version.img
# #boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux(2.6.32-131.0.15.el6.x86_64)
       root(hd0,0)
             kernel/vmlinuz-2.6.32-131.0.15.el6.x86_64 ro
             root=UUID=110fab7c-85c4-4bae-9114-98bc2ada24d8rd_NO_LUKS
             rd_NO_LVM rd_NO_MD rd_NO_DMLANG=en_US.UTF-8
             SYSFONT=latarcyrheb-sun16KEYBOARDTYPE=pc KEYTABLE=us
             crashkernel=auto rhgb quiet
                    initrd/initramfs-2.6.32-131.0.15.el6.x86_64.img
 
[root@serv01 linux-2.6.38]# cat/boot/grub/grub.conf
#/boot目录下新生成的文件
 
initramfs-2.6.38.img
vmlinuz-2.6.38
 
#会在这个文件中新加一个内核信息
[root@serv01 linux-2.6.38]# cat/boot/grub/grub.conf
 
#出现错误一般是交换分区过小,我们可以增加交换分区。如何增加交换分区,请参考此文:系统运维技巧(三)——利用dd命令增加交换分区

 

 

七 模块相关命令使用

 

#查看当前系统加载的模块
[root@serv01 linux-2.6.38]# lsmod
#手工加载模块
[root@serv01 linux-2.6.38]# cd/lib/modules/2.6.38
[root@serv01 linux-2.6.38]# cd kernel/ns
[root@serv01 linux-2.6.38]# insmod/lib/modules/2.6.38/kernel/fs/fat/fat.ko
[root@serv01 linux-2.6.38]# lsmod |grep fat
[root@serv01 linux-2.6.38]# insmod/lib/modules/2.6.38/kernel/fs/fat/vfat.ko
[root@serv01 linux-2.6.38]# lsmod |grep fat
#卸载模块,可以跟模块名,也可以跟全路径
[root@serv01 linux-2.6.38]# rmmod fat
ERROR:Module fat is in use by vfat
[root@serv01 linux-2.6.38]# rmmod vfat
[root@serv01 linux-2.6.38]# lsmod |grep fat
#模块之间有依赖,先加这个不能加上
[root@serv01 linux-2.6.38]# insmod/lib/modules/2.6.38/kernel/fs/fat/vfat.ko
 
#自动处理依赖关系,不需要加全路径
[root@serv01 linux-2.6.38]# modprobe vfat
[root@serv01 linux-2.6.38]# lsmod |grep fat
 
#-r参数,表示remove
[root@serv01 linux-2.6.38]# modprobe -r fat
[root@serv01 linux-2.6.38]# modprobe -rvfat
 
#记录模块依赖
[root@serv01 linux-2.6.38]# vim/lib/modules/2.6.32-131.0.15.el6.x86_64/modules.dep
 
[root@larrywen pdf]# pwd
/opt/soft/ule-sa2/pdf
[root@larrywen pdf]# ls ule-kerenl.pdf
ule-kerenl.pdf
[root@larrywen pdf]# ls ule-module.pdf
ule-module.pdf
 
#查看模块信息
[root@serv01 linux-2.6.38]# modinfo vfat
filename:      /lib/modules/2.6.32-131.0.15.el6.x86_64/kernel/fs/fat/vfat.ko
author:         Gordon Chaffee
description:    VFAT filesystem support
license:        GPL
srcversion:     ACCC2F7E9526F402F526976
depends:        fat
vermagic:       2.6.32-131.0.15.el6.x86_64 SMPmod_unload modversions

 


我的邮箱wgbno27@163.com  新浪微博@Wentasy27
  微信公众平台:JustOracle(微信号:justoracle)
  数据库技术交流群:336882565(加群时验证 From CSDN XXX)
  Oracle交流讨论组https://groups.google.com/d/forum/justoracle
  By Larry Wen


katoon Sina CSDN
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客]
posted @ 2013-08-06 18:28  pangbangb  阅读(640)  评论(0编辑  收藏  举报