歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 內核編譯及模塊相關命令使用

內核編譯及模塊相關命令使用

日期:2017/3/1 15:36:19   编辑:關於Linux
內核編譯及模塊相關命令使用 本文講解了怎樣進行內核編譯及模塊相關命令的使用方法。 一 Linux內核相關信息 [plain] #查看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>:制作成模塊 二 編譯配置 [plain] [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/ 三 編譯 [plain] [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) 四 編譯模塊 [plain] [root@serv01 linux-2.6.38]# make modules 五 安裝模塊 [plain] [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 六 安裝 [plain] [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命令增加交換分區 七 模塊相關命令使用 [sql] #查看當前系統加載的模塊 [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
Copyright © Linux教程網 All Rights Reserved