【问题标题】:How to make my device driver load on system start-up?如何让我的设备驱动程序在系统启动时加载?
【发布时间】:2015-02-23 11:53:42
【问题描述】:

我的 hello world 设备:

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void) {
    printk(KERN_ALERT "hello world\n");
    return 0;
}

static void hello_exit(void) {
    printk(KERN_ALERT "goodbye world\n");
}

module_init(hello_init);
module_exit(hello_exit);

如何让我的驱动程序在启动时自动加载?

我可以使用insmod 手动成功加载它,但我希望它在重启后自动加载。我需要使用Kbuild 并在make menuconfig 中选择它,还是我们需要其他方式?

【问题讨论】:

    标签: linux-kernel linux-device-driver


    【解决方案1】:

    在基于 systemd 的系统上,有 /lib/systemd/system/systemd-modules-load.service 其中

    [...] reads files from the above directories
    which contain kernel modules to load during
    boot in a static list
    

    有关该 systemd 服务使用的目录列表,请参阅 here

    您可以简单地添加一个 .conf 文件,其中包含您要在启动时加载的模块的名称。该模块必须正确安装在/lib/modules 下,并且可以使用modprobe 加载。

    【讨论】:

      【解决方案2】:

      /lib/modules/&lt;kernel version&gt;中安装模块

      如果在 Debian/Ubuntu 系统上,将模块名称添加到 /etc/modules,如果在 RH/Fedora/CentOS 系统上,则将模块名称添加到 /etc/modules.conf

      【讨论】:

      • cat: /etc/modules: No such file or directory(Fedora 20, 64 位)
      • ls: cannot access /etc/modules.conf: No such file or directory
      • 奇怪!你可以尝试创建一个。或者我会删除这个答案
      • 尝试创建 /etc/modules.conf 并在其中添加您的模块名称。
      猜你喜欢
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      相关资源
      最近更新 更多