在安装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