首页 > 其他分享 >使用rpmbuild构建内核驱动rpm包

使用rpmbuild构建内核驱动rpm包

时间:2024-01-19 21:02:42浏览次数:26  
标签:07.719 root rpmbuild 内核 megaraid sas 03.00 rpm

在安装centos7.9到dell r750xs服务器时,发现读不到磁盘,猜想可能是磁盘阵列卡驱动问题。
到dell驱动下载页找到megaraid_sas驱动,发现只有源码和预编译的3.10.0-1160内核版本驱动,
与安装盘的3.10.0-693不一致,所以需要自己根据源码构建,本文将以megaraid_sas为例

准备构建环境

yum groupinstall "Development Tools"

检查安装后的kernel-headers和kernel-devel版本,需要跟当前内核匹配,通常会随着上面的安装被安装成最新版本

[root@centos ~]# uname -r
3.10.0-693.el7.x86_64
[root@centos ~]# rpm -qa|grep -E  'kernel-(headers|devel)'
kernel-headers-3.10.0-693.el7.x86_64
kernel-devel-3.10.0-693.el7.x86_64

如果不一致则需要卸载后手动安装,以3.10.0-1160为例
bing搜索关键词site:buildlogs.centos.org kernel-devel-3.10.0-1160

下载后rpm -ivh xxx.rpm安装即可
注:下载链接改成http协议,或者使用curl -L重定向

构建

从驱动网站下载kmod-megaraid_sas-07.719.03.00-1.src.rpm

安装src

[root@centos build]# rpm -ivvh kmod-megaraid_sas-07.719.03.00-1.src.rpm
D: ============== kmod-megaraid_sas-07.719.03.00-1.src.rpm
D: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.key
D: couldn't find any keys in /var/lib/rpm/pubkeys/*.key
D: loading keyring from rpmdb
D: opening  db environment /var/lib/rpm cdb:0x401
D: opening  db index       /var/lib/rpm/Packages 0x400 mode=0x0
D: locked   db index       /var/lib/rpm/Packages
D: opening  db index       /var/lib/rpm/Name 0x400 mode=0x0
D:  read h#     306 头 SHA1 摘要: OK (489efff35e604042709daf46fb78611fe90a75aa)
D: added key gpg-pubkey-f4a80eb5-53a7ff4b to keyring
D: Using legacy gpg-pubkey(s) from rpmdb
D: Expected size:       113245 = lead(96)+sigs(5508)+pad(4)+data(107637)
D:   Actual size:       113245
警告:kmod-megaraid_sas-07.719.03.00-1.src.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID bcb1fc04: NOKEY
D: 	added source package [0]
D: found 1 source and 0 binary packages
D: Expected size:       113245 = lead(96)+sigs(5508)+pad(4)+data(107637)
D:   Actual size:       113245
D: kmod-megaraid_sas-07.719.03.00-1.src.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID bcb1fc04: NOKEY
正在升级/安装...
   1:kmod-megaraid_sas-07.719.03.00-1 ################################# [100%]
D: ========== Directories not explicitly included in package:
D:          0 /root/rpmbuild/SOURCES/
D:          1 /root/rpmbuild/SPECS/
D: ==========
D: unknown    100644  1 (   0,   0)103509 /root/rpmbuild/SOURCES/megaraid_sas-07.719.03.00.tar.bz2;659bbe3f
D: unknown    100644  1 (   0,   0)    68 /root/rpmbuild/SOURCES/megaraid_sas.conf;659bbe3f
D: unknown    100644  1 (   0,   0)  3979 /root/rpmbuild/SPECS/megaraid_sas.spec;659bbe3f
GZDIO:      15 reads,   108084 total bytes in 0.004350 secs
D: closed   db index       /var/lib/rpm/Name
D: closed   db index       /var/lib/rpm/Packages
D: closed   db environment /var/lib/rpm

找到上面输出的spec文件路径,也可以直接去/root/rpmbuild/SPECS/目录下找

开始构建

[root@centos ~]# rpmbuild -ba /root/rpmbuild/SPECS/megaraid_sas.spec
执行(%prep): /bin/sh -e /var/tmp/rpm-tmp.cOlbq7
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd /root/rpmbuild/BUILD
+ rm -rf megaraid_sas-07.719.03.00
+ /usr/bin/bzip2 -dc /root/rpmbuild/SOURCES/megaraid_sas-07.719.03.00.tar.bz2
+ /usr/bin/tar -xvvf -
drwxr-xr-x root/root         0 2021-09-14 16:19 megaraid_sas-07.719.03.00/
-rwxr-xr-x root/root    271130 2021-09-14 16:19 megaraid_sas-07.719.03.00/megaraid_sas_base.c
-rwxr-xr-x root/root      4683 2021-09-14 16:19 megaraid_sas-07.719.03.00/megaraid_sas_debugfs.c
-rwxr-xr-x root/root     44381 2021-09-14 16:19 megaraid_sas-07.719.03.00/megaraid_sas_fp.c
-rwxr-xr-x root/root    163208 2021-09-14 16:19 megaraid_sas-07.719.03.00/megaraid_sas_fusion.c
-rwxr-xr-x root/root     43194 2021-09-14 16:19 megaraid_sas-07.719.03.00/megaraid_sas_fusion.h
-rwxr-xr-x root/root     67537 2021-09-14 16:19 megaraid_sas-07.719.03.00/megaraid_sas.h
-rwxr-xr-x root/root      1439 2021-09-14 16:19 megaraid_sas-07.719.03.00/compile.sh
-rwxr-xr-x root/root       132 2021-09-14 16:19 megaraid_sas-07.719.03.00/Makefile
-rwxr-xr-x root/root      1021 2021-09-14 16:19 megaraid_sas-07.719.03.00/Makefile.standalone
-rwxr-xr-x root/root      1819 2021-09-14 16:19 megaraid_sas-07.719.03.00/dkms.conf
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd megaraid_sas-07.719.03.00
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ set -- Makefile Makefile.standalone compile.sh dkms.conf megaraid_sas.h megaraid_sas_base.c megaraid_sas_debugfs.c megaraid_sas_fp.c megaraid_sas_fusion.c megaraid_sas_fusion.h
+ mkdir source
+ mv Makefile Makefile.standalone compile.sh dkms.conf megaraid_sas.h megaraid_sas_base.c megaraid_sas_debugfs.c megaraid_sas_fp.c megaraid_sas_fusion.c megaraid_sas_fusion.h source/
+ mkdir obj
+ exit 0
执行(%build): /bin/sh -e /var/tmp/rpm-tmp.TAhM57
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd megaraid_sas-07.719.03.00
+ rm -rf obj
+ cp -r source obj
+ make -C /usr/src/kernels/3.10.0-693.el7.x86_64 M=/root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj
make: Entering directory `/usr/src/kernels/3.10.0-693.el7.x86_64'
  LD      /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/built-in.o
  CC [M]  /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas_base.o
  CC [M]  /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas_fusion.o
  CC [M]  /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas_fp.o
  CC [M]  /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas_debugfs.o
  LD [M]  /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas.mod.o
  LD [M]  /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas.ko
make: Leaving directory `/usr/src/kernels/3.10.0-693.el7.x86_64'
+ find obj -name '*.ko' -type f -exec chmod u+x '{}' +
+ whitelist=/lib/modules/kabi-current/kabi_whitelist_x86_64
+ exit 0
执行(%install): /bin/sh -e /var/tmp/rpm-tmp.rqlrFC
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
++ dirname /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
+ cd megaraid_sas-07.719.03.00
+ export INSTALL_MOD_PATH=/root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
+ INSTALL_MOD_PATH=/root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
+ export INSTALL_MOD_DIR=extra/megaraid_sas
+ INSTALL_MOD_DIR=extra/megaraid_sas
+ make -C /usr/src/kernels/3.10.0-693.el7.x86_64 modules_install M=/root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj
make: Entering directory `/usr/src/kernels/3.10.0-693.el7.x86_64'
  INSTALL /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00/obj/megaraid_sas.ko
Can't read private key
  DEPMOD  3.10.0-693.el7.x86_64
depmod: WARNING: could not open /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64/lib/modules/3.10.0-693.el7.x86_64/modules.order: No such file or directory
depmod: WARNING: could not open /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64/lib/modules/3.10.0-693.el7.x86_64/modules.builtin: No such file or directory
make: Leaving directory `/usr/src/kernels/3.10.0-693.el7.x86_64'
+ find /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64/lib/modules -iname 'modules.*' -exec rm '{}' ';'
++ uname -r
++ cut -f1 -d-
+ sed -e s/this_weakupdate/3.10.0/ ../../SOURCES/megaraid_sas.conf
+ mv ../../SOURCES/megaraid_sas.a ../../SOURCES/megaraid_sas.conf
+ install -m 644 -D /root/rpmbuild/SOURCES/megaraid_sas.conf /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64/etc/depmod.d/megaraid_sas.conf
+ /usr/lib/rpm/find-debuginfo.sh --strict-build-id -m --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 110000000 /root/rpmbuild/BUILD/megaraid_sas-07.719.03.00
extracting debug info from /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64/lib/modules/3.10.0-693.el7.x86_64/extra/megaraid_sas/megaraid_sas.ko
dwz: Too few files for multifile optimization
dwz: "./lib/modules/3.10.0-693.el7.x86_64/extra/megaraid_sas/megaraid_sas.ko.debug" is not a shared library
/usr/lib/rpm/sepdebugcrcfix: Updated 0 CRC32s, 1 CRC32s did match.
1184 blocks
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
处理文件:kmod-megaraid_sas-07.719.03.00-1.x86_64
Provides: kernel-modules >= 3.10.0-693.el7.x86_64 kmod-megaraid_sas = 07.719.03.00-1 kmod-megaraid_sas(x86-64) = 07.719.03.00-1
Requires(interp): /bin/sh /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(post): /bin/sh /usr/sbin/depmod /usr/sbin/weak-modules
Requires(preun): /bin/sh
Requires(postun): /bin/sh /usr/sbin/depmod /usr/sbin/weak-modules
处理文件:kmod-megaraid_sas-debuginfo-07.719.03.00-1.x86_64
Provides: kmod-megaraid_sas-debuginfo = 07.719.03.00-1 kmod-megaraid_sas-debuginfo(x86-64) = 07.719.03.00-1
Requires(rpmlib): rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1
检查未打包文件:/usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
写道:/root/rpmbuild/SRPMS/kmod-megaraid_sas-07.719.03.00-1.src.rpm
写道:/root/rpmbuild/RPMS/x86_64/kmod-megaraid_sas-07.719.03.00-1.x86_64.rpm
写道:/root/rpmbuild/RPMS/x86_64/kmod-megaraid_sas-debuginfo-07.719.03.00-1.x86_64.rpm
执行(%clean): /bin/sh -e /var/tmp/rpm-tmp.J5gqL0
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd megaraid_sas-07.719.03.00
+ rm -rf /root/rpmbuild/BUILDROOT/kmod-megaraid_sas-07.719.03.00-1.x86_64
+ exit 0

输出中的rpm路径就是编译后的rpm包
写道:/root/rpmbuild/RPMS/x86_64/kmod-megaraid_sas-07.719.03.00-1.x86_64.rpm

如需提取包中ko内核模块文件,可以将其解压:

[root@centos x86_64]# mkdir files
[root@centos x86_64]# cd files/
[root@centos files]# rpm2cpio ../kmod-megaraid_sas-07.719.03.00-1.x86_64.rpm | cpio -div
./etc/depmod.d/megaraid_sas.conf
./lib/modules/3.10.0-693.el7.x86_64
./lib/modules/3.10.0-693.el7.x86_64/extra
./lib/modules/3.10.0-693.el7.x86_64/extra/megaraid_sas
./lib/modules/3.10.0-693.el7.x86_64/extra/megaraid_sas/megaraid_sas.ko
518 块
[root@centos files]# 

标签:07.719,root,rpmbuild,内核,megaraid,sas,03.00,rpm
From: https://www.cnblogs.com/shn7798/p/17975591/shi-yongrpmbuild-gou-jian-nei-he-qu-dongrpm-bao

相关文章

  • linux内核链表
    linux内核的链表实现定义链表节点和初始化LIST_HEAD_INIT宏通过将next和prev都指向自身,来对节点进行初始化LIST_HEAD宏定义一个structlist_head类型的节点,并使用LIST_HEAD_INIT宏进行初始化点击查看代码structlist_head{ structlist_head*next,*prev;};#defineL......
  • 安装MySql(rpm方式安装)
    下载rpm包地址:https://dev.mysql.com/downloads/mysql/下载这个:mysql-8.0.35-1.el7.x86_64.rpm-bundle.tar解压tar-vxfmysql-8.0.35-1.el7.x86_64.rpm-bundle.tar-C<指定解压路径>进入解压路径执行安装以下程序/依赖,必须依次安装rpm-ivhmysql-community-common-8.0.3......
  • ubuntu22.04回退系统内核
    开机之后突然发现nvidia-smi检查不到驱动了,发现因为内核自动更新导致的,这里介绍一下内核回退的方法。第一步:查看当前内核版本uname-a我的当前内核版本是:6.5.0-14-generic第二步:查看系统现存的内存版本grepmenuentry/boot/grub/grub.cfg我的系统存在两个内核版本:6.5.0-14-......
  • Elasticsearch内核解析 - 数据模型篇【转载】
    原文链接Elasticsearch是一个实时的分布式搜索和分析引擎,它可以帮助我们用很快的速度去处理大规模数据,可以用于全文检索、结构化检索、推荐、分析以及统计聚合等多种场景。Elasticsearch是一个建立在全文搜索引擎库ApacheLucene基础上的分布式搜索引擎,Lucene最早的版本是2......
  • Linux内核API-字符串操作
    Linux的字符串操作API代码路径:头文件:https://github.com/torvalds/linux/blob/master/include/linux/string.h实现:https://github.com/torvalds/linux/blob/master/lib/string.c如果要使用#include<linux/string.h>API列表类别函数定义说明依赖#definetolowe......
  • uboot-5_bootm/bootz启动内核过程
    1images全局变量不管是bootz还是bootm命令,启动kernel都会用到images全局变量。images定义在文件cmd/bootm.c:include/image.h中的定义了bootm_headers_t结构:该结构描述的是bootm启动时的头部信息。该结构又包含了系统镜像头部和系统镜像。1.1bootm头部结构304type......
  • linux 内核和应用层之间的通信方式
    系统调用应用与内核通信的方式中,最常用的就是系统调用。如常见的open、write、read、ioctl等系统调用。当系统调用时,触发一个软中断,处理器进入内核模式。参数传递到内核空间,完成通信过程。内核完成服务之后,将数据返回给应用,并设置处理器为用户模式。copy_to_user()/copy_from_......
  • centos7.9内核升级至6.1.12-1
    载入公钥rpm--importhttps://www.elrepo.org/RPM-GPG-KEY-elrepo.org升级安装ELReporpm-Uvhhttps://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm载入elrepo-kernel元数据yum--disablerepo=*--enablerepo=elrepo-kernelrepolist查看可用的rpm包yum-......
  • [转帖]修改Linux内核参数,减少TCP连接中的TIME-WAIT
    https://www.cnblogs.com/xiaoleiel/p/8340346.html 一台服务器CPU和内存资源额定有限的情况下,如何提高服务器的性能是作为系统运维的重要工作。要提高Linux系统下的负载能力,当网站发展起来之后,web连接数过多的问题就会日益明显。在节省成本的情况下,可以考虑修改Linux的内......
  • 数据库内核那些事|PolarDB查询优化:好好的谓词,为什么要做下推?
    导读 数据库的查询优化器是整个系统的"大脑",一条SQL语句执行是否高效在不同的优化决策下可能会产生几个数量级的性能差异,因此优化器也是数据库系统中最为核心的组件和竞争力之一。阿里云瑶池旗下的云原生数据库PolarDBMySQL版作为领先的云原生数据库,希望能够应对广泛用户场景......