淺談linux效能調優之二十:模組管理與核心編譯 淺談linux效能調優之十九:lvm進階使用http://www.bkjia.com/os/201307/232320.html 模組是具有獨立功能的程式,它可以被單獨編譯,但不能獨立運行。它在運行時被連結到核心作為核心的一部分在核心空間運行,這與運行在使用者空間的進程是不同的。模組通常由一組函數和資料結構組成,用來實現一種檔案系統、一個驅動程式或其他核心上層的功能。 總之,模組是一個為核心(從某種意義上來說,核心也是一個模組)或其他核心模組提供使用功能的代碼塊.在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_ipv4iptable_filter 2759 1 ip_tables 17733 1 iptable_filterip6t_REJECT 4562 2 nf_conntrack_ipv6 19655 2 xt_state 1458 4 nf_conntrack 79643 3 nf_conntrack_ipv4,nf_conntrack_ipv6,xt_stateip6table_filter 2855 1 ip6_tables 19392 1 ip6table_filteripv6 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=0timeout=5splashimage=(hd0,0)/grub/splash.xpm.gzhiddenmenutitle 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.imgtitle 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格式的隨身碟,在當前啟動的核心不識別,啟動新核心便可以自動掛載 出現的問題: 錯誤: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: # touchExplanation: 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 OSmaitains 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 touchcommand 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 dateExplanation: 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 hefollowing 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. ###################################### oscersong007@gmail.com 西郵-小宋 建議:在編譯核心時,要對每個模組的功能有一定的瞭解,否則對模組的選擇一定注意,盡量使用"M"選擇