14.8. 在 RHEL 的镜像模式中集成第三方驱动程序
为确保驱动程序在更新之间保留,请在容器构建过程中直接包含您的第三方内核模块。这样,网络和安全驱动程序在镜像更新、升级和重启时仍然可用。
要使用默认 RHEL 内核中包含的文件系统、网络或安全模块,您可以使用 RHEL 工作流的镜像模式。与传统的软件包模式不同,其中使用 dnf 在实时系统上安装驱动程序,镜像模式会将文件系统视为不可变。
要包含您的自定义驱动程序,您可以使用多阶段构建。使用 rhel-bootc 镜像作为构建器阶段,安装第三方内核模块并编译您的源代码。这样可保证驱动程序与生成的可引导镜像中的内核兼容。
先决条件
-
您可以将
.ko文件嵌套在 RPM 中,以便在容器构建过程中自动使用depmod来处理依赖项映射。
流程
在构建主机上,编译驱动程序并构建 RPM 软件包。
验证 spec 并构建软件包:
$ cat SPECS/hello.spec构建驱动程序 RPM:
$ rpmbuild -ba SPECS/hello.spec
创建
Containerfile将驱动程序附加到操作系统镜像中。使用rhel-bootc基础镜像。以下是一个示例:# Copy the pre-built RPM into the build context COPY rpms/hello-<version>-<release>.el10.<arch>.rpm /tmp/或者,您可以从网络位置获取它。
# Install the RPM. # The %post scripts in the RPM triggers 'depmod' automatically inside the image. RUN dnf install -y /tmp/hello-<version>-<release>.el10.<arch>.rpm && \ dnf clean all && \ rm /tmp/hello-<version>-<release>.el10.<arch>.rpm- 构建并运行容器镜像。请参阅构建容器。
验证
重启系统:
$ sudo reboot确认系统中的内核模块可用:
$ sudo uname -r <kernel_version> $ sudo ls -l /lib/modules/<kernel_version>/extra/ total 12 -rwxr-xr-x. 1 root root 8512 Jan 1 1970 hello.ko确保在完成镜像前计算模块依赖项,否则
modprobe可能会在第一次引导时失败。$ sudo depmod -a <kernel-version>确认您可以载入该模块:
$ sudo modprobe /lib/modules/<kernel_version>/extra/hello.ko $ sudo lsmod | grep hello hello 12288 0 $ sudo rmmod hello $ sudo dmesg ..snip.. [ 84.738633] hello: loading out-of-tree module taints kernel. [ 84.738684] hello: module verification failed: signature and/or required key missing -tainting kernel. [ 84.740548] Hello, world! [ 138.206978] Goodbye!