【问题标题】:insmod failing to insert a really simple moduleinsmod 未能插入一个非常简单的模块
【发布时间】:2013-07-07 19:30:52
【问题描述】:

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

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 不见了;模块将没有依赖项和修改版本。

坦率地说,我不知道为什么 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

【问题讨论】:

  • 就在你运行 insmod 之后 dmesg 所说的内容,例如最后 10 行?
  • 我刚刚更新了问题以粘贴更多 dmesg 输出的行,但我相信只有最后一个是相关的。
  • 该链接中的问题显然是内核的头文件和源文件之间不匹配。就我而言,问题似乎是我有错误的来源。但我不知道如何获得正确的,也不想重新编译内核。
  • 在我看来,您所需要的只是内核头文件。要在 Ubuntu 上运行,请遵循 apt-get install linux-headers-$(uname -r)

标签: ubuntu linux-kernel kernel-module


【解决方案1】:

您当前的内核版本是 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

【讨论】:

  • 谢谢,我会接受您的回答,因为它是唯一提供的答案!不过我没有走你的步骤。相反,我只是编译了一个新内核并在新内核上运行 insmod。它起作用了,但我也注意到,即使我确实有源代码,它们也没有被编译,所以这可能是我的问题。
  • 非常有帮助!我重新启动,insmod 在 5 分钟前工作的代码上给了我这个错误。我签入/lib/modules,果然有第二个目录,版本号更高。我将我的 make 文件切换为使用该版本,然后一切又开始工作了。
猜你喜欢
  • 2015-01-15
  • 2013-03-28
  • 1970-01-01
  • 2018-01-05
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多