浅谈linux性能调优之二十:模块管理与内核编译

    模块是具有独立功能的程序,它可以被单独编译,但不能独立运行。它在运行时被链接到内核作为内核的一部分在内核空间运行,这与运行在用户空间的进程是不同的。模块通常由一组函数和数据结构组成,用来实现一种文件系统、一个驱动程序或其他内核上层的功能。总之,模块是一个为内核(从某种意义上来说,内核也是一个模块)或其他内核模块提供使用功能的代码块.在linux下安装过驱动的管理员因该知道,下载好驱动程序,编译完成后,最后会执行modprobe modulename,从而加载此模块,支持对应的设别。
    
    可以使用命令lsmod查看系统已经加载的模块:
Module                  Size  Used by
模块名                模块大小        被使用的次数,被啥使用
nls_utf8                1389  2 
ipt_REJECT              2349  2 
nf_conntrack_ipv4       9440  2 
nf_defrag_ipv4          1449  1 nf_conntrack_ipv4
iptable_filter          2759  1 
ip_tables              17733  1 iptable_filter
ip6t_REJECT             4562  2 
nf_conntrack_ipv6      19655  2 
xt_state                1458  4 
nf_conntrack           79643  3 nf_conntrack_ipv4,nf_conntrack_ipv6,xt_state
ip6table_filter         2855  1 
ip6_tables             19392  1 ip6table_filter
ipv6                  321209  76 ip6t_REJECT,nf_conntrack_
uinput                  8182  0 
ppdev                   8695  0 
parport_pc             22944  0 
    可以看到有的模块没有被使用过,但是应经被加载,而ipv6相关的模块有几个,但是我们未使用ipv6这中IP地址管理方式,还占空间,这就需要我们来轻量化内核,通过配置文件可以完成的,但是在添加模块支持时,我们可能就没必要在网上找补丁了,还有一个重要的原因就是可能现在使用的内核存在bug,这里我说说内核编译步骤:

    从http://www.kernel.org上下载:linux-2.6.34.14.tar.xz    
    解压:
     mv linux-2.6.34.14.tar.xz /usr/src/kernels/
     xz -d linux-2.6.34.14.tar.xz 
     tar xf linux-2.6.34.14.tar
    除了安装常用编译工具,开发包再安装ncurses-devel

     cd linux-2.6.34.14
     make mrproper        #清除旧目标文件和配置
     make menuconfig    #配置内核选项
        这里我没选ipv6支持,添加了ntfs文件系统的支持
        注意:"*" 表示启动内核时直接加载的模块
             "M" 表示在需要该模块时动态加载,这种好处就是节省资源
             " " 空格表示不选
     make                #编译内核
     make modules        #编译内核模块
     make modules_install    #安装内核模块
     make install        #安装新内核

    验证:less /etc/grub.conf
#
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.34.14)
    root (hd0,0)
    kernel /vmlinuz-2.6.34.14 ro root=UUID=2858d858-b089-4d4a-a044-4b75325a35dd rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
    initrd /initramfs-2.6.34.14.img
title Red Hat Enterprise Linux (2.6.32-71.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-71.el6.x86_64 ro root=UUID=2858d858-b089-4d4a-a044-4b75325a35dd rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet
    initrd /initramfs-2.6.32-71.el6.x86_64.img
#
    格式化一个ntfs格式的U盘,在当前启动的内核不识别,启动新内核便可以自动挂载


    出现的问题:
        错误:make[2]: warning:  Clock skew detected.  Your build may be incomplete.
             make[2]: Warning: File `/usr/src/kernels/linux-2.6.34.14/Documentation/networking/Makefile' has modification time 1.4e+07 s in the future
    网上资料分析:
######################################
We may get warning of this type when:
1) You try to build after moving your data from one machine to another.
2) You try to build after restarting any old machine.
 
This is due to the fact that sometimes when a machine is restarted its time and date settings get affected. Also when you transfer data from one machine to another one may get such an error because of the time difference form machine to machine.
 
There are two ways to overcome this error:
A] Linux has a very handy ‘the touch command’.
How to Use: # touch
Explanation: The touch command changes the time stamp of the file with the ‘file name’ give as argument to the command. For every file the Linux OS
maitains some data like the files creation time, last modification time, etc. touch changes the last modification time of the command and sets it to the time the touch
command was executed. The very well known ‘make’ command works on a very similar principle.
This method is suitable only if yu haev transferred one or two files. But if there are many such files (and also if the machine time is not set to the present) then it would be better to use the following method.
[EDIT :] Okay here’s an update: You can use the touch command for any number of files in the following manner:
1. Just ‘cd’ into the directory where the files need a time-stamp update.
2. Next use the following command which will update the time-stamps of all the files in the directory:
# find . -exec touch {} \;
 
 
B] the ‘date’ command:
How to use: # sudo date
Explanation: The date command changes the time and date of the Linux system to the time and date given as an argument. The argument is formed int he
following way -
-> First two digits are the current month like 02 for February and 12 for December.
-> Next two digits are the date from 01 to 30 or 31.
-> Next two digits are the time digits. This is to be strictly given in the 24 hour format. Nevertheless, while displaying the system time ( which happens when the date command is executed without any arguments ) the time is displayed in 12 hour format or whatever format is set.
-> next two digits are for minutes range is from 00 to 59
->Next four digits are for the current year like 2013.
This way the system time will be set to the current time and your build will be now successful.

######################################
                                                                                                                      [email protected]
                                                                                                                               西邮-小宋
    建议:在编译内核时,要对每个模块的功能有一定的了解,否则对模块的选择一定注意,尽量使用"M"选择

你可能感兴趣的:(linux,性能优化,内核编译,模块管理)