insmod: error inserting : -1 Invalid module format 解決辦法

來源:互聯網
上載者:User

當最初開始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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.