iso镜像替换megaraid_sas驱动
一、问题分析
服务器ThtinkSystem SR650,RAID适配器为ThinkSystem RAID930-16i 4G。安装Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso系统失败,显示未探测到磁盘驱动器。
Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso的内核版本为4.4.58-20171113.kylin.5.all-generic
安装centos7.6或者使用具有live的光盘进入系统,执行
$ lspci -knn | grep -i raid -A 10
RAID bus controller [0104]: LSI Logic / Symbios Logic MegaRAID SAS-3 3106 [Invader] [1000:0014] (rev 02)
Kernel modules: megaraid_sas
可知使用megaraid_sas作为驱动,VendorID为 1000,DeviceID为0014。
而Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso的内核版本为4.4.58-20171113.kylin.5.all-generic,中的megaraid_sas不支持该设备。
二、驱动编译
2.1 下载内核
从网站https://mirrors.edge.kernel.org/pub/linux/kernel/,下载如下内核
内核版本 |
---|
linux-4.4.58.tar.gz |
linux-4.4.98.tar.xz |
linux-4.5.1.tar.xz |
linux-4.8.tar.xz |
linux-4.9.237.tar.xz |
linux-4.10.1.tar.xz |
linux-4.12.tar.xz |
linux-4.20.tar.xz |
linux-5.4.58.tar.xz |
2.2 查找各个内核megaraid_sas驱动代码
查找内核中的megaraid驱动代码是否VendorID为 1000,DeviceID为0014的设备
grep -rin "0014" ./linux-4.4.58/drivers/scsi/megaraid
查看是否支持设备号。
说明linux-4.12
,linux-4.20
,linux-5.4.58
中的megaraid代码支持deviceID:0014。
2.3 搭建编译环境
安装Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso虚拟机,挂载镜像,linux系统安装linux-headers,麒麟系统安装kylin-headers
dpkg -i kylin-headers-all_4.4.58-20171113.kylin.5_all.deb
dpkg -i kylin-headers-all-generic_4.4.58-20171113.kylin.5_amd64.deb
2.4 编译驱动
进入Kylin-4.0.2-server-sp2-18011911虚拟机,将各个内核版本的megaraid代码拷到虚拟机的/opt目录下。
root@Kylin:/opt# scp -r lmz@192.168.2.1:~/download/linux-4.12/drivers/scsi/megaraid megaraid_4.12
root@Kylin:/opt# scp -r lmz@192.168.2.1:~/download/linux-4.20/drivers/scsi/megaraid megaraid_4.20
root@Kylin:/opt# scp -r lmz@192.168.2.1:~/download/linux-5.4.58/drivers/scsi/megaraid megaraid_5.4.58
使用make -C 内核头文件目录 M=驱动源码的makefile目录 modules进行编译。
- 编译megaraid_4.12:编译成功
root@Kylin:/opt/megaraid_4.12# make -C /usr/src/kylin-headers-all-generic/ M=`pwd` modules
make: Entering directory '/usr/src/kylin-headers-all-generic'
CC [M] /opt/megaraid_4.12/megaraid_mm.o
CC [M] /opt/megaraid_4.12/megaraid_mbox.o
CC [M] /opt/megaraid_4.12/megaraid_sas_base.o
CC [M] /opt/megaraid_4.12/megaraid_sas_fusion.o
CC [M] /opt/megaraid_4.12/megaraid_sas_fp.o
LD [M] /opt/megaraid_4.12/megaraid_sas.o
Building modules, stage 2.
MODPOST 3 modules
CC /opt/megaraid_4.12/megaraid_mbox.mod.o
LD [M] /opt/megaraid_4.12/megaraid_mbox.ko
CC /opt/megaraid_4.12/megaraid_mm.mod.o
LD [M] /opt/megaraid_4.12/megaraid_mm.ko
CC /opt/megaraid_4.12/megaraid_sas.mod.o
LD [M] /opt/megaraid_4.12/megaraid_sas.ko
make: Leaving directory '/usr/src/kylin-headers-all-generic'
- 编译megaraid_4.20:编译失败
root@Kylin:/opt/megaraid_4.20# make -C /usr/src/kylin-headers-all-generic/ M=`pwd` modules
make: Entering directory '/usr/src/kylin-headers-all-generic'
CC [M] /opt/megaraid_4.20/megaraid_mm.o
/opt/megaraid_4.20/megaraid_mm.c: In function ‘lld_ioctl’:
/opt/megaraid_4.20/megaraid_mm.c:701:3: error: implicit declaration of function ‘timer_setup_on_stack’ [-Werror=implicit-function-declaration]
timer_setup_on_stack(&timeout.timer, lld_timedout, 0);
^
/opt/megaraid_4.20/megaraid_mm.c: In function ‘lld_timedout’:
/opt/megaraid_4.20/megaraid_mm.c:789:33: error: implicit declaration of function ‘from_timer’ [-Werror=implicit-function-declaration]
struct uioc_timeout *timeout = from_timer(timeout, t, timer);
^
/opt/megaraid_4.20/megaraid_mm.c:789:56: error: ‘timer’ undeclared (first use in this function)
struct uioc_timeout *timeout = from_timer(timeout, t, timer);
^
/opt/megaraid_4.20/megaraid_mm.c:789:56: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
scripts/Makefile.build:272: recipe for target '/opt/megaraid_4.20/megaraid_mm.o' failed
make[1]: *** [/opt/megaraid_4.20/megaraid_mm.o] Error 1
Makefile:1462: recipe for target '_module_/opt/megaraid_4.20' failed
make: *** [_module_/opt/megaraid_4.20] Error 2
make: Leaving directory '/usr/src/kylin-headers-all-generic'
- 编译megaraid_5.4.58:编译失败
root@Kylin:/opt/megaraid_5.4.58# make -C /usr/src/kylin-headers-all-generic/ M=`pwd` modules
make: Entering directory '/usr/src/kylin-headers-all-generic'
CC [M] /opt/megaraid_5.4.58/megaraid_mm.o
/opt/megaraid_5.4.58/megaraid_mm.c: In function ‘lld_ioctl’:
/opt/megaraid_5.4.58/megaraid_mm.c:697:3: error: implicit declaration of function ‘timer_setup_on_stack’ [-Werror=implicit-function-declaration]
timer_setup_on_stack(&timeout.timer, lld_timedout, 0);
^
/opt/megaraid_5.4.58/megaraid_mm.c: In function ‘lld_timedout’:
/opt/megaraid_5.4.58/megaraid_mm.c:785:33: error: implicit declaration of function ‘from_timer’ [-Werror=implicit-function-declaration]
struct uioc_timeout *timeout = from_timer(timeout, t, timer);
^
/opt/megaraid_5.4.58/megaraid_mm.c:785:56: error: ‘timer’ undeclared (first use in this function)
struct uioc_timeout *timeout = from_timer(timeout, t, timer);
^
/opt/megaraid_5.4.58/megaraid_mm.c:785:56: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
scripts/Makefile.build:272: recipe for target '/opt/megaraid_5.4.58/megaraid_mm.o' failed
make[1]: *** [/opt/megaraid_5.4.58/megaraid_mm.o] Error 1
Makefile:1462: recipe for target '_module_/opt/megaraid_5.4.58' failed
make: *** [_module_/opt/megaraid_5.4.58] Error 2
make: Leaving directory '/usr/src/kylin-headers-all-generic'
内核版本 | 是否支持[1000:0014] | 在内核4.4.58是否能编译通过 |
---|---|---|
linux-4.4.58 | x | × |
linux-4.4.98 | x | × |
linux-4.5.1 | x | x |
linux-4.8 | x | x |
linux-4.9.237 | x | x |
linux-4.10.1 | x | x |
linux-4.12 | √ | √ |
linux-4.20 | √ | x |
linux-5.4.58 | √ | x |
从上述分只有linux-4.12的megaraid代码支持[1000:0014],且能在内核4.4.58编译通过。并最终得到/opt/megaraid_4.12/megaraid_sas.ko
三、iso镜像替换驱动
initrd.lz为安装时使用的系统,ilesystem.squashfs为需要安装的系统。
3.1 挂载镜像
root@X280-1:/# mount /home/lmz/download/Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
root@X280-1:/# rsync -a /mnt /tmp
3.2 将megaraid_sas.ko 放入initrd.lz中
- 进入initrd.lz目录,创建initrd目录
root@X280-1:/# cd /tmp/mnt/casper/
root@X280-1:/tmp/mnt/casper# mkdir initrd
root@X280-1:/tmp/mnt/casper# ll
总用量 411124
dr-xr-xr-x 3 root root 4096 9月 29 16:11 ./
dr-xr-xr-x 11 root root 4096 1月 19 2018 ../
-r--r--r-- 1 root root 7802 1月 19 2018 filesystem.manifest
-r--r--r-- 1 root root 23 1月 19 2018 filesystem.manifest-remove
-r--r--r-- 1 root root 10 1月 19 2018 filesystem.size
-r--r--r-- 1 root root 321155072 1月 19 2018 filesystem.squashfs
drwxr-xr-x 2 root root 4096 9月 29 16:11 initrd/
-r--r--r-- 1 root root 31948660 1月 19 2018 initrd.img-4.4.58-20171113.kylin.5.all-generic
-r--r--r-- 1 root root 52155452 1月 19 2018 initrd.lz
-r--r--r-- 1 root root 577 12月 21 2017 initrd_readme
-r--r--r-- 1 root root 182704 1月 19 2018 memtest
-r--r--r-- 1 root root 2324 1月 19 2018 TRANS.TBL
-r--r--r-- 1 root root 7752912 1月 19 2018 vmlinuz
-r--r--r-- 1 root root 7752912 1月 19 2018 vmlinuz-4.4.58-20171113.kylin.5.all-generic
root@X280-1:/tmp/mnt/casper# cd initrd
root@X280-1:/tmp/mnt/casper/initrd#
- 解压initrd.lz
root@X280-1:/tmp/mnt/casper/initrd# zcat -d ../initrd.lz | cpio -idum
root@X280-1:/tmp/mnt/casper/initrd# ll
总用量 80
drwxr-xr-x 17 root root 4096 9月 29 16:13 ./
dr-xr-xr-x 3 root root 4096 9月 29 16:11 ../
drwxr-xr-x 2 lmz lmz 4096 9月 29 16:13 bin/
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 dev/
drwxr-xr-x 15 lmz lmz 4096 9月 29 16:13 etc/
-rwxr-xr-x 1 lmz lmz 456 1月 19 2018 init*
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 initrd/
drwxr-xr-x 15 lmz lmz 4096 9月 29 16:13 lib/
drwxr-xr-x 2 lmz lmz 4096 9月 29 16:13 lib64/
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 media/
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 mnt/
-rwxr--r-- 1 lmz lmz 6891 1月 19 2018 preseed.cfg*
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 proc/
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 run/
drwxr-xr-x 2 lmz lmz 4096 9月 29 16:13 sbin/
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 sys/
drwxr-xr-x 2 lmz lmz 4096 1月 19 2018 tmp/
drwxr-xr-x 7 lmz lmz 4096 9月 29 16:13 usr/
drwxr-xr-x 7 lmz lmz 4096 9月 29 16:13 var/
root@X280-1:/tmp/mnt/casper/initrd# cd lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid
root@X280-1:/tmp/mnt/casper/initrd/lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid# ll
总用量 296
drwxr-xr-x 2 root root 4096 9月 29 16:13 ./
drwxr-xr-x 31 root root 4096 9月 29 16:13 ../
-rw-r--r-- 1 root root 61462 1月 19 2018 megaraid_mbox.ko
-rw-r--r-- 1 root root 23150 1月 19 2018 megaraid_mm.ko
-rw-r--r-- 1 root root 203366 1月 19 2018 megaraid_sas.ko
- 拷贝新的megaraid_sas.ko
root@X280-1:/tmp/mnt/casper/initrd/lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid# cp /home/lmz/desktop/megaraid_sas.ko .
root@X280-1:/tmp/mnt/casper/initrd/lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid# cd /tmp/mnt/casper/initrd/
- 压缩成新的initrd.lz
root@X280-1:/tmp/mnt/casper/initrd# find . | cpio -oH newc | gzip -9 >../initrd.lz
root@X280-1:/tmp/mnt/casper/initrd# cd ..
root@X280-1:/tmp/mnt/casper# ll
总用量 411148
dr-xr-xr-x 3 root root 4096 9月 29 16:11 ./
dr-xr-xr-x 11 root root 4096 1月 19 2018 ../
-r--r--r-- 1 root root 7802 1月 19 2018 filesystem.manifest
-r--r--r-- 1 root root 23 1月 19 2018 filesystem.manifest-remove
-r--r--r-- 1 root root 10 1月 19 2018 filesystem.size
-r--r--r-- 1 root root 321155072 1月 19 2018 filesystem.squashfs
drwxr-xr-x 17 root root 4096 9月 29 16:13 initrd/
-r--r--r-- 1 root root 31948660 1月 19 2018 initrd.img-4.4.58-20171113.kylin.5.all-generic
-r--r--r-- 1 root root 52178586 9月 29 16:22 initrd.lz
-r--r--r-- 1 root root 577 12月 21 2017 initrd_readme
-r--r--r-- 1 root root 182704 1月 19 2018 memtest
-r--r--r-- 1 root root 2324 1月 19 2018 TRANS.TBL
-r--r--r-- 1 root root 7752912 1月 19 2018 vmlinuz
-r--r--r-- 1 root root 7752912 1月 19 2018 vmlinuz-4.4.58-20171113.kylin.5.all-generic
root@X280-1:/tmp/mnt/casper# rm -rf initrd
3.3 将megaraid_sas.ko放入filesystem.squashfs中
- 解压filesystem.squashfs
root@X280-1:/tmp/mnt/casper# unsquashfs filesystem.squashfs
Parallel unsquashfs: Using 8 processors
20097 inodes (24114 blocks) to write
[=========================================================================================================-] 24114/24114 100%
created 17927 files
created 2604 directories
created 2088 symlinks
created 79 devices
created 0 fifos
root@X280-1:/tmp/mnt/casper#
root@X280-1:/tmp/mnt/casper# ll
总用量 411148
dr-xr-xr-x 3 root root 4096 9月 29 16:25 ./
dr-xr-xr-x 11 root root 4096 1月 19 2018 ../
-r--r--r-- 1 root root 7802 1月 19 2018 filesystem.manifest
-r--r--r-- 1 root root 23 1月 19 2018 filesystem.manifest-remove
-r--r--r-- 1 root root 10 1月 19 2018 filesystem.size
-r--r--r-- 1 root root 321155072 1月 19 2018 filesystem.squashfs
-r--r--r-- 1 root root 31948660 1月 19 2018 initrd.img-4.4.58-20171113.kylin.5.all-generic
-r--r--r-- 1 root root 52178586 9月 29 16:22 initrd.lz
-r--r--r-- 1 root root 577 12月 21 2017 initrd_readme
-r--r--r-- 1 root root 182704 1月 19 2018 memtest
drwxr-xr-x 22 root root 4096 1月 19 2018 squashfs-root/
-r--r--r-- 1 root root 2324 1月 19 2018 TRANS.TBL
-r--r--r-- 1 root root 7752912 1月 19 2018 vmlinuz
-r--r--r-- 1 root root 7752912 1月 19 2018 vmlinuz-4.4.58-20171113.kylin.5.all-generic
root@X280-1:/tmp/mnt/casper# cd squashfs-root/
root@X280-1:/tmp/mnt/casper/squashfs-root#
- 拷贝新的megaraid_sas.ko
root@X280-1:/tmp/mnt/casper/squashfs-root# cd lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid
root@X280-1:/tmp/mnt/casper/squashfs-root/lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid# cp /home/lmz/desktop/megaraid_sas.ko .
root@X280-1:/tmp/mnt/casper/squashfs-root/lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid# ll
总用量 300
drwxr-xr-x 2 root root 4096 1月 19 2018 ./
drwxr-xr-x 31 root root 4096 1月 19 2018 ../
-rw-r--r-- 1 root root 61462 11月 17 2017 megaraid_mbox.ko
-rw-r--r-- 1 root root 23150 11月 17 2017 megaraid_mm.ko
-rw-r--r-- 1 root root 208848 9月 29 16:27 megaraid_sas.ko
- 生成新的filesystem.size
root@X280-1:/tmp/mnt/casper/squashfs-root/lib/modules/4.4.58-20171113.kylin.5.all-generic/kernel/drivers/scsi/megaraid# cd /tmp/mnt/casper/
root@X280-1:/tmp/mnt/casper# du -B 1 -s squashfs-root/ | cut -f1 > filesystem.size
- 生成新的filesystem.manifest
root@X280-1:/tmp/mnt/casper# chroot squashfs-root/ dpkg-query -W > filesystem.manifest
- 压缩成新的filesystem.squashfs
root@X280-1:/tmp/mnt/casper# rm -rf filesystem.squashfs
root@X280-1:/tmp/mnt/casper# mksquashfs squashfs-root/ filesystem.squashfs
Parallel mksquashfs: Using 8 processors
Creating 4.0 filesystem on filesystem.squashfs, block size 131072.
[=========================================================================================================-] 21947/21947 100%
root@X280-1:/tmp/mnt/casper# rm -rf squashfs-root/
3.4 制作成iso镜像文件
-
生成iso文件
命令
mkisofs -quiet -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -R -J -o /tmp/Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso .
,/tmp/Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso为新的iso目录及文件名,.
表示当前目录/tmp/mnt
root@X280-1:/tmp/mnt/casper# cd ..
root@X280-1:/tmp/mnt# ll
总用量 980
dr-xr-xr-x 11 root root 4096 1月 19 2018 ./
drwxrwxrwt 28 root root 114688 9月 29 16:36 ../
-r--r--r-- 1 root root 27 7月 12 2017 AUTORUN.INF
dr-xr-xr-x 3 root root 4096 7月 12 2017 boot/
dr-xr-xr-x 2 root root 4096 9月 29 16:36 casper/
dr-xr-xr-x 4 root root 4096 1月 19 2018 data_info/
lrwxrwxrwx 1 root root 1 1月 19 2018 debian -> ./
dr-xr-xr-x 2 root root 4096 1月 19 2018 .disk/
dr-xr-xr-x 3 root root 4096 1月 19 2018 dists/
dr-xr-xr-x 2 root root 4096 1月 19 2018 isolinux/
-r--r--r-- 1 root root 269 1月 19 2018 .kyinfo
-r--r--r-- 1 root root 67646 11月 29 2016 kylin.ico
-r--r--r-- 1 root root 1577 1月 18 2018 .kylin-post-actions
-r--r--r-- 1 root root 464 1月 19 2018 LICENSE
-r--r--r-- 1 root root 321081 1月 19 2018 md5sum.txt
dr-xr-xr-x 4 root root 4096 7月 14 2017 netboot/
dr-xr-xr-x 6 root root 4096 1月 19 2018 pool/
dr-xr-xr-x 2 root root 4096 1月 19 2018 preseed/
-r--r--r-- 1 root root 427396 1月 19 2018 SHA256SUMS
-r--r--r-- 1 root root 3740 1月 19 2018 TRANS.TBL
root@X280-1:/tmp/mnt# mkisofs -quiet -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -R -J -o /tmp/Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso .
root@X280-1:/tmp/mnt# cd /tmp
root@X280-1:/tmp# ll Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso
-rw-r--r-- 1 root root 3315623936 9月 29 16:40 Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso
- 向iso中写入md5
root@X280-1:/tmp# implantisomd5 /tmp/Kylin-4.0.2-server-sp2-18011911.J1-x86_64.iso
Inserting md5sum into iso image...
md5 = 60440a694438e084faad6d0a214fb0dd
Inserting fragment md5sums into iso image...
fragmd5 = 4e7fb5b7c3bfd79f017d2fd37d3ebb49385f3e4692dffb8291117456fffe
frags = 20
Setting supported flag to 0