Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3401493
  • 博文数量: 534
  • 博客积分: 11595
  • 博客等级: 上将
  • 技术积分: 5785
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-22 17:00
文章分类

全部博文(534)

文章存档

2015年(4)

2014年(27)

2013年(15)

2012年(38)

2011年(36)

2010年(85)

2009年(63)

2008年(142)

2007年(124)

分类: LINUX

2007-09-28 16:49:17

五、2.4 下如何单独编译某个模块

有时候我们编译好了内核,模块文件也生成了。但在日后的使用过程中想增加某个模块应该怎么办呢?下面就以增加 reiserfs jfs xfs 模块为例进行说明。

当前的内核版本是 2.4.35.normal ,所以新生成的模块也将放在 /lib/modules/2.4.35.normal/fs/

1
执行 make dep 2>&1 |tee /tmp/make_dep.out

2
复制 Makefile Makefile.onlymodule

3
修改 Makefile.onlymodule EXTRAVERSION .onlymodule 。之所以这么做是因为不想覆盖当前内核的模块。
         
     
也就是把 Makefile.onlymodule SUBDIRS :SUBDIRS =fs/reiserfs fs/jfs fs/xfs
              
4
执行make -f Makefile.onlymodule modules 2>&1 |tee /tmp/make_only_modules.out 生成上面的模块

   
记得要加上 -f 参数,否则使用的还是 Makefile ,而不是 Makefile.onlymodule 文件
                                 
5
执行make -f Makefile.onlymodule modules_install 2>&1 |tee /tmp/make_only_modules_install.out 安装模块

6
下面把生成好的模块文件拷贝到当前内核的模块目录下

CODE:

[root@mail fs]# cd /lib/modules/2.4.35.onlymodule/kernel/fs
[root@mail fs]#
[root@mail fs]# ll
total 12
drwxr-xr-x    2 root     root         4096 Sep 19 01:15 jfs
drwxr-xr-x    2 root     root         4096 Sep 19 01:15 reiserfs
drwxr-xr-x    2 root     root         4096 Sep 19 01:15 xfs
[root@mail fs]#        
[root@mail fs]# uname -a
Linux mail.bob.com 2.4.35.normal #1 SMP Wed Sep 19 00:46:00 CST 2007 i686 i686 i386 GNU/Linux
[root@mail fs]#
[root@mail fs]# cp -a * /lib/modules/2.4.35.normal/kernel/fs/
[root@mail fs]#


可以看到上面的 /lib/modules/2.4.35.onlymodule/kernel/fs/ 下只有 jfs/reiserfs/xfs/ 三个目录,这就是因为 SUBDIRS 指定只生成这3个目录而已。

所以如果我们上面不修改 EXTRAVERSION 的话,则会把当前内核的模块目录(/lib/modules/2.4.35.normal/ 下的所有其他内容都删除,

再拷贝这3个目录 !!

而在 Kernel-HOWTO 中则没有修改 EXTRAVERSION 一步,直接修改 SUBDIRS ,结果就如同上面所说

7
这样我们就有了 reiserfsjfsxfs 文件系统的模块了。下面执行 depmod -a 生成新的 modules.dep 文件

:最好先备份原来的 /lib/modules/2.4.35.normal/modules.dep 文件,再执行 depmod

CODE:

[root@mail modules]# depmod -a
[root@mail modules]# ll /lib/modules/2.4.35.normal/modules.dep
-rw-r--r--    1 root     root         8363 Sep 19 01:18 /lib/modules/2.4.35.normal/modules.dep
[root@mail modules]#


8
在新的 modules.dep 中查找相应的行

CODE:

[root@mail modules]# grep -i 'reiserfs\|xfs\|jfs' /lib/modules/2.4.35.normal/modules.dep
/lib/modules/2.4.35.normal/kernel/fs/jfs/jfs.o:
/lib/modules/2.4.35.normal/kernel/fs/reiserfs/reiserfs.o:
/lib/modules/2.4.35.normal/kernel/fs/xfs/xfs.o:
[root@mail modules]#


可以看到已经有这些模块的行了

9
尝试加载这些模块

CODE:

[root@mail modules]# modprobe jfs
[root@mail modules]# modprobe reiserfs
[root@mail modules]# modprobe xfs
[root@mail modules]# lsmod |grep fs
xfs                   594884   0  (unused)
reiserfs              298800   0  (unused)
jfs                   192248   0  (unused)
[root@mail modules]#


可以看到成功加载了

10
下面把 /lib/modules/2.4.35.onlymodule 删除,因为已经用不到了。

CODE:

[root@mail modules]# rm -fr 2.4.35.onlymodule/
[root@mail modules]#

 

六、关于 “depmod: *** Unresolved symbols ” 的问题

不知道你是否注意到,前面有一个 System.map 文件,这个文件的具体作用在 Kernel-HOWOTO 中有讲,不过一般不用关心它

因为它是自动生成的。但是该文件的正确与否却会影响到模块的正常加载。下面以1个例子来说明

例如此前我们没有选择 ACPIP 支持,而现在我们想把该功能加到内核中,下面是 .config 文件中对应的部分

QUOTE:

# ACPI Support
#
CONFIG_ACPI=y
CONFIG_ACPI_BOOT=y
CONFIG_ACPI_BUS=y
CONFIG_ACPI_INTERPRETER=y
CONFIG_ACPI_EC=y
CONFIG_ACPI_POWER=y
CONFIG_ACPI_PCI=y
CONFIG_ACPI_MMCONFIG=y
CONFIG_ACPI_SLEEP=y
CONFIG_ACPI_SYSTEM=y
CONFIG_ACPI_AC=m
CONFIG_ACPI_BATTERY=m
CONFIG_ACPI_BUTTON=m
CONFIG_ACPI_FAN=m
CONFIG_ACPI_PROCESSOR=m
CONFIG_ACPI_THERMAL=m
CONFIG_ACPI_ASUS=m
CONFIG_ACPI_TOSHIBA=m


如果直接按照上面的方法编译模块(不执行 make bzImage )的再执行 depmod -a ,会出现下面的错误

CODE:

[root@mail 2.4.34.4]# depmod -a -n -F /boot/System.map-2.4.34.4 2.4.34.4  |more
depmod: /lib/modules/2.4.34.4/modules.dep.bak is not an ELF file
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/ac.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/asus_acpi.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/battery.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/button.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/fan.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/processor.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/thermal.o
depmod: *** Unresolved symbols in /lib/modules/2.4.34.4/kernel/drivers/acpi/toshiba_acpi.o


1
执行 make clean  bzImage

2
把新的 bzImage.configSystem.map 都拷贝到 /boot

3
现在重新执行 make -f Makefile.onlymodules modules

4
同样把我们需要的模块文件拷贝过去就可以。

5
再次执行 depmod ,这次不再出错了 !!!

6
这说明是由于此前没有执行 make bzImage 所致,导致 System.map 文件的内容不正确,

CODE:

[root@mail 2.4.34.4]# depmod -a -F /boot/System.map-2.4.34.4 2.4.34.4 -n 2>/dev/null |grep -i 'unresolved'
[root@mail 2.4.34.4]#


7
去掉 -n 再次执行,可以看到 modules.dep 生成了

CODE:

[root@mail 2.4.34.4]# ll modules.dep
-rw-r--r--    1 root     root         7513 Sep 20 00:22 modules.dep
[root@mail 2.4.34.4]#


8
检查 modules.dep 中是否含有 acpi 相关信息

CODE:

[root@mail 2.4.34.4]# grep -i acpi modules.dep
/lib/modules/2.4.34.4/kernel/drivers/acpi/ac.o:
/lib/modules/2.4.34.4/kernel/drivers/acpi/asus_acpi.o:
/lib/modules/2.4.34.4/kernel/drivers/acpi/battery.o:
/lib/modules/2.4.34.4/kernel/drivers/acpi/button.o:
/lib/modules/2.4.34.4/kernel/drivers/acpi/fan.o:
/lib/modules/2.4.34.4/kernel/drivers/acpi/processor.o:
/lib/modules/2.4.34.4/kernel/drivers/acpi/thermal.o:    /lib/modules/2.4.34.4/kernel/drivers/acpi/processor.o
/lib/modules/2.4.34.4/kernel/drivers/acpi/toshiba_acpi.o:
[root@mail 2.4.34.4]#


所以当出现 'Unresolved symbols' 的问题时,有可能和 System.map 文件版本有关

 

七、2.6 内核的编译


1
RPM 方式编译

这部分见

2
tarball 方式编译

个人感觉 2.6 的编译过程比 2.4 简单很多,有很多东西 make 都替你作了,就连修改 grub.conf 这样的东西也算在内。

而且 2.6 Makefile 中还有一个名为 help target ,执行 make help 可以看到该 Makeilfe 中可用的 target

而在 2.4 Makefile 中并没有该 target

CODE:

[root@mail linux-2.6.20.16]# grep help Makefile
# To see a list of typical targets execute "make help"
# Basic helpers built in scripts/
                         cscope TAGS tags help %docs check% \
# Additional helpers built in scripts/
help:
        @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
        @$(MAKE) $(build)=$(package-dir) help
        @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
        @$(if $(archhelp),$(archhelp),\
                echo '  No architecture specific help defined for $(ARCH)')
help:
[root@mail linux-2.6.20.16]#


下面是执行 make help 的输出

CODE:

[root@mail linux-2.6.9]# make help
Cleaning targets:
  clean           - remove most generated files but keep the config
  mrproper        - remove all generated files + config + various backup files

Configuration targets:
  oldconfig       - Update current config utilising a line-oriented program
  menuconfig      - Update current config utilising a menu based program
  xconfig         - Update current config utilising a QT based front-end
  gconfig         - Update current config utilising a GTK based front-end
  defconfig       - New config with default answer to all options
  allmodconfig    - New config selecting modules when possible
  allyesconfig    - New config where all options are accepted with yes
  allnoconfig     - New minimal config

Other generic targets:
  all             - Build all targets marked with [*]
* vmlinux         - Build the bare kernel
* modules         - Build all modules
  modules_install - Install all modules
  dir/            - Build all files in dir and below
  dir/file.[ois]  - Build specified target only
  rpm             - Build a kernel as an RPM package
  tags/TAGS       - Generate tags file for editors
  cscope          - Generate cscope index

Static analysers
  buildcheck      - List dangling references to vmlinux discarded sections
                    and init sections from non-init sections
  checkstack      - Generate a list of stack hogs
  namespacecheck  - Name space analysis on compiled kernel

Kernel packaging:
  rpm-pkg         - Build the kernel as an RPM package
  binrpm-pkg      - Build an rpm package containing the compiled kernel & modules
  deb-pkg         - Build the kernel as an deb package

Documentation targets:
  Linux kernel internal documentation in different formats:
  sgmldocs (SGML), psdocs (Postscript), pdfdocs (PDF)
  htmldocs (HTML), mandocs (man pages, use installmandocs to install)

Architecture specific targets (i386):
* bzImage       - Compressed kernel image (arch/i386/boot/bzImage)  
install       - Install kernel using
                   (your) ~/bin/installkernel or
                   (distribution) /sbin/installkernel or
                   install to $(INSTALL_PATH) and run lilo

  bzdisk       - Create a boot floppy in /dev/fd0
  fdimage      - Create a boot floppy image

  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build
  make O=dir [targets] Locate all output files in "dir", including .config
  make C=1   [targets] Check all c source with $CHECK (sparse)
  make C=2   [targets] Force check of all c source with $CHECK (sparse)

Execute "make" or "make all" to build all targets marked with [*]
For further info see the ./README file
[root@mail linux-2.6.9]#


例如 V 变量是用于控制是否启用 verbose 模式,默认是 0 (不启用)

O
变量控制 make 生成的文件放到那里,默认是当前目录

比较有用的有 clean mrproperoldconfigmenuconfigmodules_install

rpm 等几个

3
2.6 内核的编译过程

2.6
内核的比较简单,只有几个步骤而已

        a
make mrproper  clean ,同样需要先备份 .config 文件

        b
make oldconfig 或者 make menuconfig

        c
make

        d
make modules_install

        e
make install

其中 make 等同于 make dep bzImage modules ,而 make install 会做如下事情

        a
bzImageSystem.map 都拷贝到 /boot 下并自动改名为 vmlinz- System.map-

        b
自动生成 initrd ,而且是 cpio 格式的,不再是原来的 image 格式

        c
自动修改 grub.conf ,加上新的内核,但不会修改默认引导的内核。这点和 rpm 方式安装新内核不同。

阅读(1637) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~