【问题标题】:Unable to insmod hello_world kernel module in debian 8无法在 debian 8 中安装 hello_world 内核模块
【发布时间】:2016-05-01 16:14:02
【问题描述】:

我不明白为什么 insmod 给出 Invalid parameters 错误(在 dmesg 中看不到任何内容):

$ sudo insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Invalid parameters

$ sudo insmod /hello.ko
insmod: ERROR: could not load module /hello.ko: No such file or directory

我的模块中没有参数。这只是你好世界的例子。

我的环境:

$ uname -r
3.16.0-4-amd64

我已经安装了所有可能的内核头文件包:

linux-headers-3.16.0-4-all
linux-headers-3.16.0-4-all-amd64
linux-headers-3.16.0-4-amd64
linux-headers-3.16.0-4-common
linux-headers-amd64 

我的代码:

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */

int init_module(void)
{
    printk(KERN_INFO "Hello world 1.\n");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye world 1.\n");
}

MODULE_LICENSE("GPL");

我使用以下Makefile

obj-m += hello.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

make 输出:

$ 制作

make -C /lib/modules/3.16.0-4-amd64/build M=/home/user/c.driver/driver-1 modules
make[1]: Entering directory '/usr/src/linux-headers-3.16.0-4-amd64'
Makefile:10: *** mixed implicit and normal rules: deprecated syntax
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-4-amd64'
  CC [M]  /home/user/c.driver/driver-1/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/user/c.driver/driver-1/hello.mod.o
  LD [M]  /home/user/c.driver/driver-1/hello.ko
make[1]: Leaving directory '/usr/src/linux-headers-3.16.0-4-amd64'

更新:与 14.04.1-Ubuntu 的结果相同

【问题讨论】:

  • 你试过 insmod hello.ko 而不是 insmod ./hello.ko 吗?
  • 通常在dmesg消息中解释了模块加载失败的原因。检查一下。
  • @Tsyvarev 我知道,但与内核模块无关。最后一个 - Parallels Linux shared folders filesystem driver 1.2.1 loaded。会不会是Parallels造成的? VM 正在 Parallels Desktop 下运行。
  • 猜猜你在内核中启用了 CONFIG_MODULES=y 吗?
  • 尝试 zcat /proc/config.gz | grep CONFIG_MODULES

标签: linux makefile kernel-module insmod


【解决方案1】:

也许是因为你忘记了:

module_init(init_module);                                                           
module_exit(cleanup_module);

我通常将 init_module() 和 cleanup_module() 声明为静态函数。 和伙伴代码是我的内核模块模板:

#include <linux/module.h>
#include <linux/kernel.h>

static int init_module(void)
{
   ... 
   return 0;
}

static void exit_module(void)
{
   ...
}

module_init(init_module);
module_exit(exit_module);
MODULE_LICENSE("GPL");

【讨论】:

    【解决方案2】:

    对我来说,问题在于该模块文件位于共享文件夹中(实际上,我的 Ubuntu 机器是 Parallels 上的虚拟机)。将模块复制到本地文件夹,然后重试。

    感谢@avasin。答案在 cmets 但不是很快就能找到,所以在这里添加它可能会帮助其他人。这让我呆了几个小时。

    【讨论】:

      猜你喜欢
      • 2019-06-23
      • 2012-03-10
      • 1970-01-01
      • 2011-12-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 1970-01-01
      • 2021-04-13
      相关资源
      最近更新 更多