Linux系统内核文件模块的加载

本文发布时间: 2019-Mar-22
内核模块模块是对小的内核的扩充 ,它可以按需装载或卸载能够支持驱动器 ,文件系统 ,防火墙以及其他放置在/lib/modules/$(uname -r)/由kernel RPM包提供 ,由对应的内核版本编译成可以添加第三方的模块 内核模块工具lsmod提供罗列出所有已经装载的模块modprobe能装载和卸载模块 modprobe -l |grep 8139modinfo显示任何可用模块的信息/etc/modprobe.conf 用于模块的配置 o 当模块装载时向它传递参数 o 用别名代表模块名 o 当模块装载或卸载时执行命令 管理initrd镜像初始化内存磁盘提供了在引导过程的初期装载模块文件放置在/boot/initrd-$(uname -r).img有时因为以下的原因需要添加额外的模块 o 加入到系统的新硬件 比如. SCSI 控制器 o 需要新特性 比如支持USB设备. o 模块需要自动的在引导时装载.使用 mkinitrd加上 --with选项来重新编译使其具有额外的模块 mkinitrd--with=module_name /boot/initrd-$(uname-r).img $(uname-r)------------------实验1:先查看initrd里面的内容-----------------------1. 在/boot下cp initramfs...文件到/tmp文件下2. 用file查看initramfs文件的类型,发现是一个gzip文件[root@yangcan boot]# file initrd-2.6.18-164.el5.imginitrd-2.6.18-164.el5.img: gzip compressed data, from Unix, last modified: Tue Jul 24 13:02:15 2012, max compression[root@yangcan boot]# mkdir /tmp/init.org[root@yangcan boot]# cp initrd-2.6.18-164.el5.img /tmp/init.org/[root@yangcan init.org]# gunzip -S .img initrd-2.6.18-164.el5.img##解压initrd-2.6.18-164.el5.img 文件.[root@yangcan init.org]# lltotal 5932-rw------- 1 root root 6056448 Aug 14 21:04 initrd-2.6.18-164.el5[root@yangcan init.org]# file initrd-2.6.18-164.el5initrd-2.6.18-164.el5: ASCII cpio archive (SVR4 with no CRC)##initrd-2.6.18-164.el5 是一个cpio归档文件[root@yangcan init.org]# cpio -i <initrd-2.6.18-164.el511829 blocks##解压,看下解压后的文件[root@yangcan init.org]# lltotal 6000drwx------ 2 root root 4096 Aug 14 21:06 bindrwx------ 3 root root 4096 Aug 14 21:06 devdrwx------ 2 root root 4096 Aug 14 21:06 etc-rwx------ 1 root root 2703 Aug 14 21:06 init-rw------- 1 root root 6056448 Aug 14 21:04 initrd-2.6.18-164.el5drwx------ 3 root root 4096 Aug 14 21:06 libdrwx------ 2 root root 4096 Aug 14 21:06 proclrwxrwxrwx 1 root root 3 Aug 14 21:06 sbin -> bindrwx------ 2 root root 4096 Aug 14 21:06 sysdrwx------ 2 root root 4096 Aug 14 21:06 sys........[root@yangcan init.org]# cd lib/[root@yangcan lib]# lsata_piix.ko ext3.ko pvscsi.kodm-log.ko firmware scsi_mod.kodm-mem-cache.ko jbd.ko scsi_transport_spi.kodm-message.ko libata.ko sd_mod.kodm-mod.ko mptbase.ko uhci-hcd.kodm-raid45.ko mptscsih.ko vmxnet3.kodm-region_hash.ko mptspi.ko vmxnet.koehci-hcd.ko ohci-hcd.ko## 进入lib文件夹下,没有8139文件-----------2. modules使用的命令-----------------[root@yangcan ~]# lsmod |grep 8139##查找系统已装载的模块,没有[root@yangcan ~]# modprobe -l|grep 8139/lib/modules/2.6.18-164.el5/kernel/drivers/net/8139cp.ko/lib/modules/2.6.18-164.el5/kernel/drivers/net/8139too.ko[root@yangcan ~]# modinfo 8139cpfilename: /lib/modules/2.6.18-164.el5/kernel/drivers/net/8139cp.kolicense: GPLversion: 1.2description: RealTek RTL-8139C+ series 10/100 PCI Ethernet driverauthor: Jeff Garzik <[email protected]>srcversion: 3463E2A900E7509DB5D2836alias: pci:v00000357d0000000Asv*sd*bc*sc*i*alias: pci:v000010ECd00008139sv*sd*bc*sc*i*depends: miivermagic: 2.6.18-164.el5 SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1parm: debug:8139cp: bitmapped message enable number (int)parm: multicast_filter_limit:8139cp: maximum number of filtered multicast addresses (int)module_sig: 883f3504a8b7aed18758d6145e11233ba09a392da264e0a324904c2a8823152511c8f337b0a0af13ac7399a83a5d437a8517378b395765a27f8------------------实验3:把额外的模块加载到initrd-----------------------##看下mkinitrd工具的使用帮助[root@yangcan ~]# mkinitrd --helpusage: mkinitrd [--version] [--help] [-v] [-f] [--preload <module>] [--force-ide-probe] [--force-scsi-probe | --omit-scsi-modules] [--image-version] [--force-raid-probe | --omit-raid-modules] [--with=<module>] [--force-lvm-probe | --omit-lvm-modules] [--builtin=<module>] [--net-dev=<interface>] [--with-fips] [--without-usb] [--without-multipath] [--without-dmraid] [--fstab=<fstab>] [--nocompress] <initrd-image> <kernel-version> (ex: mkinitrd /boot/initrd-2.2.5-15.img 2.2.5-15)##把8139too编译到initrd-2.6.18-164.el5.with8139too.img[root@yangcan ~]# mkinitrd --with 8139too /boot/initrd-2.6.18-164.el5.with8139too.img $(uname -r)[root@yangcan ~]# ll /boot/|grep ini-rw------- 1 root root 2644091 Jul 24 13:02 initrd-2.6.18-164.el5.img-rw------- 1 root root 2617233 Aug 14 21:17 initrd-2.6.18-164.el5.with8139too.img--------------------实验4 验证8139too模块有没有添加到initrd-2.6.18-164.el5.with8139too.img--------------------[root@yangcan ~]# cp /boot/initrd-2.6.18-164.el5.with8139too.img /tmp[root@yangcan tmp]# ll |grep initdrwxr-xr-x 9 root root 4096 Aug 14 21:11 init.org-rw------- 1 root root 2617233 Aug 14 21:18 initrd-2.6.18-164.el5.with8139too.img[root@yangcan tmp]# mkdir initwith8139[root@yangcan tmp]# cd initwith8139/[root@yangcan initwith8139]#[root@yangcan initwith8139]#[root@yangcan initwith8139]# gunzip -S .img ../initrd-2.6.18-164.el5.with8139too.img[root@yangcan initwith8139]# cpio -i <../initrd-2.6.18-164.el5.with8139too11705 blocks[root@yangcan initwith8139]# cd lib/[root@yangcan lib]# lltotal 1332-rw------- 1 root root 36624 Aug 14 21:20 8139too.ko-rw------- 1 root root 30644 Aug 14 21:20 ata_piix.ko-rw------- 1 root root 17908 Aug 14 21:20 dm-log.ko-rw------- 1 root root 11188 Aug 14 21:20 dm-mem-cache.ko-rw------- 1 root root 8808 Aug 14 21:20 dm-message.ko-rw------- 1 root root 75384 Aug 14 21:20 dm-mod.ko-rw------- 1 root root 74020 Aug 14 21:20 dm-raid45.ko-rw------- 1 root root 18512 Aug 14 21:20 dm-region_hash.ko-rw------- 1 root root 38980 Aug 14 21:20 ehci-hcd.ko-rw------- 1 root root 146792 Aug 14 21:20 ext3.kodrwx------ 2 root root 4096 Aug 14 21:20 firmware-rw------- 1 root root 72180 Aug 14 21:20 jbd.ko-rw------- 1 root root 189932 Aug 14 21:20 libata.ko-rw------- 1 root root 10964 Aug 14 21:20 mii.ko-rw------- 1 root root 96456 Aug 14 21:20 mptbase.ko-rw------- 1 root root 43256 Aug 14 21:20 mptscsih.ko-rw------- 1 root root 27656 Aug 14 21:20 mptspi.ko-rw------- 1 root root 29016 Aug 14 21:20 ohci-hcd.ko-rw------- 1 root root 177032 Aug 14 21:20 scsi_mod.ko-rw------- 1 root root 31564 Aug 14 21:20 scsi_transport_spi.ko-rw------- 1 root root 30412 Aug 14 21:20 sd_mod.ko-rw------- 1 root root 30024 Aug 14 21:20 uhci-hcd.ko对比一下init文件[root@yangcan ~]# diff /tmp/init.org/init /tmp/initwith8139/init83,88c83,86< echo "Loading vmxnet3.ko module"< insmod /lib/vmxnet3.ko< echo "Loading pvscsi.ko module"< insmod /lib/pvscsi.ko< echo "Loading vmxnet.ko module"< insmod /lib/vmxnet.ko---> echo "Loading mii.ko module"> insmod /lib/mii.ko> echo "Loading 8139too.ko module"> insmod /lib/8139too.ko验证新的initrd-2.6.18-164.el5.with8139too.img已经加入了8139too模块---------------实验5:反向打包-----------------------修改/tmp/initwith8139/init的文件,加入echo "################8139too.ko###############"重新打包成initrd-2.6.18-164.el5.with8139too.img[root@yangcan initwith8139]# find .>../ls2.txt[root@yangcan initwith8139]#[root@yangcan initwith8139]#[root@yangcan initwith8139]# vi ../ls2.txt[root@yangcan initwith8139]# cpio -o -H newc <../lsls2.txt ls.txt[root@yangcan initwith8139]# cpio -o -H newc <../ls2.txt >../init.new.with9138too[root@yangcan tmp]# gzip -9 -S .img init.new.with9138too[root@yangcan tmp]# file init.new.with9138too.imginit.new.with9138too.img: gzip compressed data, was "init.new.with9138too", from Unix, last modified: Tue Aug 14 23:43:08 2012, max compression----------------实验6 验证反向打包的initrd-------------------[root@yangcan tmp]# cp init.new.with9138too.img /boot/修改grub.conf[root@yangcan ~]# vi /boot/grub/grub.confdefault=1timeout=5splashimage=(hd0,0)/grub/splash.xpm.gzhiddenmenutitle Red Hat Enterprise Linux Server (2.6.18-164.el5) root (hd0,0) kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.18-164.el5.imgtitle with8139to root (hd0,0) kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/ initrd /init.new.with9138too.imgREBOOT之后,查找加载的模块,有8139too.ko[root@yangcan ~]# lsmod |grep 81398139too 28865 0mii 9281 2 pcnet32,8139too


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:11pm
栏目列表