You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Yocto构建QEMU镜像时自动加载内核模块失败求助

解决Yocto自定义init下内核模块自动加载问题

核心原因

KERNEL_MODULE_AUTOLOAD 默认是给systemd生成 /etc/modules-load.d/*.conf 配置,但你的系统用的是自定义run-mgr init程序,这个程序不会识别systemd的模块加载配置格式,所以得手动把模块加载逻辑加到你的init启动流程里。

具体配置步骤

1. 在hello-mod配方中添加模块加载逻辑

修改hello-mod_0.1.bb,添加以下内容,把模块加载命令整合到系统启动脚本中:

# 如果你的系统有rc.local,直接追加加载命令
do_install_append() {
    # 确保rc.local存在并可执行
    install -d ${D}${sysconfdir}
    touch ${D}${sysconfdir}/rc.local
    chmod 0755 ${D}${sysconfdir}/rc.local
    # 写入模块加载命令,注意替换成你的模块实际路径
    echo "/sbin/insmod /lib/modules/${KERNEL_VERSION}/extra/hello.ko" >> ${D}${sysconfdir}/rc.local
}

如果你的自定义init不支持rc.local,也可以单独写个启动脚本:

# 添加自定义启动脚本
SRC_URI += "file://load-hello.sh"

do_install_append() {
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 ${WORKDIR}/load-hello.sh ${D}${sysconfdir}/init.d/
    # 假设init会执行rcS.d下的脚本,创建启动链接
    install -d ${D}${sysconfdir}/rcS.d
    ln -sf ../init.d/load-hello.sh ${D}${sysconfdir}/rcS.d/S99hello-mod
}

对应的load-hello.sh脚本内容(放在配方的files目录下):

#!/bin/sh
/sbin/insmod /lib/modules/$(uname -r)/extra/hello.ko

2. 配置自定义init执行加载逻辑

根据你的run-mgr init程序的规则,确保加载脚本或rc.local会在系统启动时被执行:

  • 如果是类SysV的init,确认rcS.d目录下的S开头脚本会被依次执行
  • 如果是自定义的init配置文件,直接把/sbin/insmod /lib/modules/$(uname -r)/extra/hello.ko这行命令加到启动配置里

3. 清理无效配置(可选)

既然不用systemd,KERNEL_MODULE_AUTOLOAD已经起不到作用,可以从配方里删掉,避免混淆:

# 移除这行无效配置
# KERNEL_MODULE_AUTOLOAD += "hello"

额外检查点

  • 确认镜像里有insmod命令,部分最小化镜像可能只有modprobe,可以改用modprobe hello(前提是/lib/modules/${KERNEL_VERSION}/modules.dep文件存在,模块依赖正确)
  • 启动后用dmesg | grep hello查看模块加载日志,排查是否有内核版本不匹配、依赖缺失等报错

内容的提问来源于stack exchange,提问作者goodman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 01:07:43