Chinaunix首页 | 论坛 | 博客
  • 博客访问: 24256
  • 博文数量: 9
  • 博客积分: 235
  • 博客等级: 二等列兵
  • 技术积分: 97
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-30 10:12
文章分类

全部博文(9)

文章存档

2012年(9)

我的朋友

分类: LINUX

2012-08-15 11:03:47

                    内核模块

·   模块是对小的内核的扩充 ,它可以按需装载或卸载

·   能够支持驱动器 ,文件系统 ,防火墙以及其他

·   放置在/lib/modules/$(uname -r)/

·   由kernel RPM包提供 ,由对应的内核版本编译成

·   可以添加第三方的模块

                    内核模块工具

·   lsmod提供罗列出所有已经装载的模块

·   modprobe能装载和卸载模块 modprobe -l |grep 8139

·   modinfo显示任何可用模块的信息

·   /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.img
initrd-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]# ll
total 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.el5
initrd-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

11829 blocks

##解压,看下解压后的文件
[root@yangcan init.org]# ll
total 6000
drwx------ 2 root root    4096 Aug 14 21:06 bin
drwx------ 3 root root    4096 Aug 14 21:06 dev
drwx------ 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.el5
drwx------ 3 root root    4096 Aug 14 21:06 lib
drwx------ 2 root root    4096 Aug 14 21:06 proc
lrwxrwxrwx 1 root root       3 Aug 14 21:06 sbin -> bin
drwx------ 2 root root    4096 Aug 14 21:06 sys
drwx------ 2 root root    4096 Aug 14 21:06 sys........

[root@yangcan init.org]# cd lib/
[root@yangcan lib]# ls
ata_piix.ko        ext3.ko      pvscsi.ko
dm-log.ko          firmware     scsi_mod.ko
dm-mem-cache.ko    jbd.ko       scsi_transport_spi.ko
dm-message.ko      libata.ko    sd_mod.ko
dm-mod.ko          mptbase.ko   uhci-hcd.ko
dm-raid45.ko       mptscsih.ko  vmxnet3.ko
dm-region_hash.ko  mptspi.ko    vmxnet.ko
ehci-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 8139cp
filename:       /lib/modules/2.6.18-164.el5/kernel/drivers/net/8139cp.ko
license:        GPL
version:        1.2
description:    RealTek RTL-8139C+ series 10/100 PCI Ethernet driver
author:         Jeff Garzik
srcversion:     3463E2A900E7509DB5D2836
alias:          pci:v00000357d0000000Asv*sd*bc*sc*i*
alias:          pci:v000010ECd00008139sv*sd*bc*sc*i*
depends:        mii
vermagic:       2.6.18-164.el5 SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1
parm:           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 --help
usage: mkinitrd [--version] [--help] [-v] [-f] [--preload ]
       [--force-ide-probe] [--force-scsi-probe | --omit-scsi-modules]
       [--image-version] [--force-raid-probe | --omit-raid-modules]
       [--with=] [--force-lvm-probe | --omit-lvm-modules]
       [--builtin=] [--net-dev=] [--with-fips]
       [--without-usb] [--without-multipath] [--without-dmraid]
       [--fstab=] [--nocompress]

       (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 init
drwxr-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.with8139too
11705 blocks
[root@yangcan initwith8139]# cd lib/
[root@yangcan lib]# ll
total 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.ko
drwx------ 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/init
83,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 <../ls
ls2.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.img
init.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.conf
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title 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.img

title with8139to
        root (hd0,0)
        kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/
        initrd /init.new.with9138too.img

REBOOT之后,查找加载的模块,有8139too.ko
[root@yangcan ~]# lsmod |grep 8139
8139too                28865  0
mii                     9281  2 pcnet32,8139too

阅读(934) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:boot分区格式化恢复

给主人留下些什么吧!~~