首页 文章

insmod无法插入一个非常简单的模块

提问于
浏览
5

我正在尝试编译并将模块插入到我的内核中,但我一直收到此错误:

insmod: error inserting 'hello.ko': -1 Invalid module format

我在这里按照本教程中描述的步骤进行操作:http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html . 一切似乎都有意义和有效 . 我得到了我的示例模块编译但是有一个警告可能是导致此事失败的重要原因 . 警告是这样的:

警告:缺少符号版本转储/usr/src/linux-3.0.0/Module.symvers;模块将没有依赖关系和modversions .

我坦率地不知道为什么Module.symvers文件不存在 . 我使用此命令下载源后, /usr/src/linux-3.0.0 目录及其所有内容都是由我创建的:

apt-get source linux-image - $(uname -r)

这实际上是我没有遵循的那个教程的唯一步骤,因为我找不到我的内核的确切来源(3.0.0-32-generic),并认为aptitude工具会对我进行排序 .

而且我顺便在64位机器上运行Ubuntu,这是uname -a输出:

Linux vega 3.0.0-32-generic#51-Ubuntu SMP Thu Mar 21 15:50:59 UTC 2013 x86_64 x86_64 x86_64 GNU / Linux

有关下一步尝试的建议吗?任何推荐的阅读?

PS1 . 经过一些研究后,我确认我正在运行3.0.0-32-generic . update-grub返回:

Found linux image: /boot/vmlinuz-3.0.0-32-generic

但是在发出sudo make oldconfig并检查生成的.config文件后,我得到了这个有趣的行:

CONFIG_VERSION_SIGNATURE="Ubuntu 3.0.0-32.51-generic 3.0.69"

这有资格作为错配吗?

PS2 . dmesg输出:

[    5.869900] ADDRCONF(NETDEV_UP): eth1: link is not ready
[    6.144304] EXT4-fs (dm-1): re-mounted. Opts: errors=remount-ro
[    6.368936] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
[    6.433919] vesafb: mode is 640x480x32, linelength=2560, pages=0
[    6.433921] vesafb: scrolling: redraw
[    6.433923] vesafb: Truecolor: size=8:8:8:8, shift=24:16:8:0
[    6.435424] vesafb: framebuffer at 0xb0000000, mapped to 0xffffc90012800000, using 1216k, total 1216k
[    6.435516] Console: switching to colour frame buffer device 80x30
[    6.443104] EXT4-fs (dm-2): mounted filesystem with ordered data mode. Opts: (null)
[    6.450198] fb0: VESA VGA frame buffer device
[    8.884523] e1000e: eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
[    8.885845] ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
[   12.611236] init: ssh main process (762) terminated with status 255
[   12.624381] init: failsafe main process (752) killed by TERM signal
[   12.634739] type=1400 audit(1373412287.107:8): apparmor="STATUS" operation="profile_load" name="/usr/sbin/tcpdump" pid=852 comm="apparmor_parser"
[   12.634873] type=1400 audit(1373412287.107:9): apparmor="STATUS" operation="profile_replace" name="/sbin/dhclient" pid=851 comm="apparmor_parser"
[   12.635180] type=1400 audit(1373412287.107:10): apparmor="STATUS" operation="profile_replace" name="/usr/lib/NetworkManager/nm-dhcp-client.action" pid=851 comm="apparmor_parser"
[   12.635403] type=1400 audit(1373412287.107:11): apparmor="STATUS" operation="profile_replace" name="/usr/lib/connman/scripts/dhclient-script" pid=851 comm="apparmor_parser"
[   19.390991] eth1: no IPv6 routers present
[  576.758697] hello: no symbol version for module_layout

1 回答

  • 7

    您当前的内核版本是3.0.0-32-generic转到 cd /lib/modules/3.0.0-32-gereric/ 目录并检查是否存在构建目录 . 如果存在,则可以使用以下命令直接编译模块

    make -C /lib/modules/3.0.0-32-generic/build M=$(PWD) modules
    

    如果您想用您下载的内核编译模块,请按照以下步骤操作:

    cd /usr/src/linux-3.0.0/
    
    make menuconfig
    
    make -j5
    
    make modules
    
    sudo make modules_install
    
    sudo make install
    
    sudo reboot
    

    然后使用linux-3.0.0内核启动系统,并使用以下命令编译模块:

    make -C /lib/modules/3.0.0/build M=$(PWD) modules
    

相关问题