现在的位置: 首页 > 综合 > 正文

insmod: error inserting : -1 Invalid module format 解决办法

2014年02月17日 ⁄ 综合 ⁄ 共 6122字 ⁄ 字号 评论关闭

当最初开始LDD编程时,经常会碰到这种情况,下载编译的内核源代码和当前正在运行的内核不一样。

 

第一阶段

有时候你下载的内核版本相对正确,但却仍然不能insert成功,这有另一方面的东西要check:

1. gcc的版本,比较:

cat /proc/version和gcc -v

2. 内核config的比较,在关键的选项上不能相左

当前内核config:

/lib/modules/`uname -r`/build/.config

 

比如,在大内存机器上可能要打开PAE:CONFIG_X86_PAE=y

2.6.32-28-generic-pae #55-Ubuntu SMP Mon Jan 10 22:34:08

而默认的内核源代码是不会打开的,所以insert失败

PAE依赖于CONFIG_HIGHMEM64G=y,否则PAE选项是看不到的:

    High Memory Support (64GB)  --->                                            │ │ 

         -*- PAE (Physical Address Extension) Support       

 

同时可以把version signature设成一样:

CONFIG_VERSION_SIGNATURE="Ubuntu 2.6.32-28.55-generic-pae 2.6.32.27+drm33.12"

当运行内核中有检查的时候
CONFIG_CHECK_SIGNATURE=y

 

dkms需要装:

$ aptitude show dkms
Package: dkms
State: not installed
Version: 2.1.1.2-2ubuntu1
Priority: optional
Section: admin
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Uncompressed Size: 475k
Depends: module-init-tools, gcc, make | build-essential | dpkg-dev, patch
Recommends: fakeroot, lsb-release, menu | sudo, linux-headers-2.6-686 | linux-headers-2.6-amd64 |
            linux-headers-generic | linux-headers, linux-image
Description: Dynamic Kernel Module Support Framework
 DKMS is a framework designed to allow individual kernel modules to be upgraded without changing the
 whole kernel. It is also very easy to rebuild modules as you upgrade kernels.
Homepage: http://linux.dell.com/dkms

 

第二阶段

基本配置正确后,接下来是version和magic不匹配的问题:

[12151.939695] h: no symbol version for module_layout
[13544.669533] h: disagrees about version of symbol module_layout

以后一种更常见。

CONFIG_VERSION_SIGNATURE的设置丝毫不起作用,使用modinfo查看系统ko和自编ko:

 

$ sudo modinfo h.ko
filename:       h.ko
license:        Dual BSD/GPL
depends:       
vermagic:       2.6.32.41+drm33.18 SMP mod_unload modversions 686

系统ko

vermagic:       2.6.32-28-generic-pae SMP mod_unload modversions 586TSC

parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           eeprom_bad_csum_allow:Allow bad eeprom checksums (int)
parm:           use_io:Force use of i/o access mode (int)

其定义在Makefile文件中,

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 32
EXTRAVERSION = .41+drm33.18
NAME = Man-Eating Seals of Antiquity

需要将EXTRAVERSION替换:-28-generic-pae

modversions是通过enable该选项编译内核出来的:CONFIG_MODVERSIONS=y

 

而586TSC则是ARCH,是通过设置CONFIG_M586TSC(Pentium-Classic)出来的,而现在编译的内核是686(Pentium-Pro)。

所以解决办法:

1. 编辑Makefile文件使前面基本的版本号一样

2. enable CONFIG_MODVERSIONS

3. 选择同样的cpu类型

 

第三阶段

做完了这一切以后,还是不能插入:disagrees about version of symbol module_layout

这种情况是有可能的,不仅仅是大小版本的差异,而且你不能保证你的:

This indicates you have compiled the module against a different version of the kernel than is running. Note that even if the running kernel and kernel source have the same numerical value (e.g. both are 2.6.31-20-server), if the two use different configuration
options, you may see this error. Also check if there are multiple versions of this module on the machine and ensure you are loading the correct one.

 

只能采取终极办法了,自己从source里编一个,即:

apt-get install linux-source-2.6.32

cp /lib/modules/`uname -r`/build/.config .config  Or:

cp /boot/config-`uname -r` .config

 

make -j4

sudo make install

make modules

sudo make modules_install

$ cd /boot && sudo mkinitramfs -k -o initrd.img-2.6.32.41+drm33.18-pae 2.6.32.41+drm33.18-pae
Working files in /tmp/mkinitramfs_4KnPce and overlay in /tmp/mkinitramfs-OL_XRVNGw

 

/tmp/mkinitramfs_4KnPce$ ls
bin  conf  etc  init  lib  sbin  scripts

编辑grub.cfg加入新编译的内核

 

-EOF

当最初开始LDD编程时,经常会碰到这种情况,下载编译的内核源代码和当前正在运行的内核不一样。

 

第一阶段

有时候你下载的内核版本相对正确,但却仍然不能insert成功,这有另一方面的东西要check:

1. gcc的版本,比较:

cat /proc/version和gcc -v

2. 内核config的比较,在关键的选项上不能相左

当前内核config:

/lib/modules/`uname -r`/build/.config

 

比如,在大内存机器上可能要打开PAE:CONFIG_X86_PAE=y

2.6.32-28-generic-pae #55-Ubuntu SMP Mon Jan 10 22:34:08

而默认的内核源代码是不会打开的,所以insert失败

PAE依赖于CONFIG_HIGHMEM64G=y,否则PAE选项是看不到的:

    High Memory Support (64GB)  --->                                            │ │ 

         -*- PAE (Physical Address Extension) Support       

 

同时可以把version signature设成一样:

CONFIG_VERSION_SIGNATURE="Ubuntu 2.6.32-28.55-generic-pae 2.6.32.27+drm33.12"

当运行内核中有检查的时候
CONFIG_CHECK_SIGNATURE=y

 

dkms需要装:

$ aptitude show dkms
Package: dkms
State: not installed
Version: 2.1.1.2-2ubuntu1
Priority: optional
Section: admin
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Uncompressed Size: 475k
Depends: module-init-tools, gcc, make | build-essential | dpkg-dev, patch
Recommends: fakeroot, lsb-release, menu | sudo, linux-headers-2.6-686 | linux-headers-2.6-amd64 |
            linux-headers-generic | linux-headers, linux-image
Description: Dynamic Kernel Module Support Framework
 DKMS is a framework designed to allow individual kernel modules to be upgraded without changing the
 whole kernel. It is also very easy to rebuild modules as you upgrade kernels.
Homepage: http://linux.dell.com/dkms

 

第二阶段

基本配置正确后,接下来是version和magic不匹配的问题:

[12151.939695] h: no symbol version for module_layout
[13544.669533] h: disagrees about version of symbol module_layout

以后一种更常见。

CONFIG_VERSION_SIGNATURE的设置丝毫不起作用,使用modinfo查看系统ko和自编ko:

 

$ sudo modinfo h.ko
filename:       h.ko
license:        Dual BSD/GPL
depends:       
vermagic:       2.6.32.41+drm33.18 SMP mod_unload modversions 686

系统ko

vermagic:       2.6.32-28-generic-pae SMP mod_unload modversions 586TSC

parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           eeprom_bad_csum_allow:Allow bad eeprom checksums (int)
parm:           use_io:Force use of i/o access mode (int)

其定义在Makefile文件中,

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 32
EXTRAVERSION = .41+drm33.18
NAME = Man-Eating Seals of Antiquity

需要将EXTRAVERSION替换:-28-generic-pae

modversions是通过enable该选项编译内核出来的:CONFIG_MODVERSIONS=y

 

而586TSC则是ARCH,是通过设置CONFIG_M586TSC(Pentium-Classic)出来的,而现在编译的内核是686(Pentium-Pro)。

所以解决办法:

1. 编辑Makefile文件使前面基本的版本号一样

2. enable CONFIG_MODVERSIONS

3. 选择同样的cpu类型

 

第三阶段

做完了这一切以后,还是不能插入:disagrees about version of symbol module_layout

这种情况是有可能的,不仅仅是大小版本的差异,而且你不能保证你的:

This indicates you have compiled the module against a different version of the kernel than is running. Note that even if the running kernel and kernel source have the same numerical value (e.g. both are 2.6.31-20-server), if the two use different configuration
options, you may see this error. Also check if there are multiple versions of this module on the machine and ensure you are loading the correct one.

 

只能采取终极办法了,自己从source里编一个,即:

apt-get install linux-source-2.6.32

cp /lib/modules/`uname -r`/build/.config .config  Or:

cp /boot/config-`uname -r` .config

 

make -j4

sudo make install

make modules

sudo make modules_install

$ cd /boot && sudo mkinitramfs -k -o initrd.img-2.6.32.41+drm33.18-pae 2.6.32.41+drm33.18-pae
Working files in /tmp/mkinitramfs_4KnPce and overlay in /tmp/mkinitramfs-OL_XRVNGw

 

/tmp/mkinitramfs_4KnPce$ ls
bin  conf  etc  init  lib  sbin  scripts

编辑grub.cfg加入新编译的内核

 

-EOF

抱歉!评论已关闭.