IPA加驅動的一種方式,未驗證

Aisino罗sir發表於2024-04-15

How add nic driver to initrd
SimonZM.Wang
https://blog.csdn.net/weixin_45547360/article/details/127330048
How to add nic driver to pxe boot initrd
1. 概述
2. 準備工作
3. 如何新增nic驅動
3.1 Redhat/CentOS 7系列新增Mellaxon CX6 NIC Driver
3.2 Debian9系列新增Broadcom NIC Driver

1.概述
initrd (initial ramdisk) 是一種臨時根檔案系統,它可以透過BootLoader引導載入到記憶體中的作為臨時根檔案系統,並執行不同的程式,它可以用作 Linux 啟動過程的一部分。
在pxe裝機過程中,BootLoader 引導載入vmlinuz及initrd後,將initrd做為初始化檔案系統,並從網路檔案共享伺服器(nfs/http/vsftp)中載入檔案系統進行裝機,但舊的Linux發行版的initrd由於缺少一些新的NIC驅動,無法正確識別NIC裝置,這時候如果要正確透過PXE安裝OS,需要將該⽹卡的驅動程式打包到initrd的映象file中。
此文件分別以centos/redhat 7系列新增Mellaxon CX6 NIC Driver、debian9.9新增Boadcom NIC Driver為例,其他型號網路卡驅動新增也可參考此文件進行。
2. 準備工作
ISO映象包
NIC Driver package

1.如何新增nic驅動
3.1 Redhat/CentOS 7系列新增Mellaxon CX6 NIC Driver
透過隨身碟或webUI安裝OS到SUT

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
1
2

在SUT安裝網路卡驅動

[root@localhost ~]# ls MLNX_OFED_LINUX-5.7-1.0.2.0-rhel7.6-x86_64.tgz
MLNX_OFED_LINUX-5.7-1.0.2.0-rhel7.6-x86_64.tgz
[root@localhost ~]# tar zxvf MLNX_OFED_LINUX-5.7-1.0.2.0-rhel7.6-x86_64.tgz
[root@localhost ~]# cd MLNX_OFED_LINUX-5.7-1.0.2.0-rhel7.6-x86_64/
[root@localhost MLNX_OFED_LINUX-5.7-1.0.2.0-rhel7.6-x86_64]# ls
common_installers.pl distro LICENSE RPM-GPG-KEY-Mellanox uninstall.sh
common.pl docs mlnx_add_kernel_support.sh RPMS
create_mlnx_ofed_installers.pl is_kmp_compat.sh mlnxofedinstall src
[root@localhost MLNX_OFED_LINUX-5.7-1.0.2.0-rhel7.6-x86_64]# ./mlnxofedinstall --force
1
2
3
4
5
6
7
8
9

解壓原始initrd
將OS映象掛載到本地

[root@localhost ~]# mount -o loop -t iso9660 CentOS-7.6-x86_64-DVD-1810.iso /mnt/
    1

為新的initrd建立掛載點

[root@localhost ~]# mkdir initrd_mlx5
    1

拷⻉ISO映象⾥原始的initrd.img

[root@localhost ~]# cp /mnt/images/pxeboot/initrd.img /root/initrd_mlx5/
    1

解壓原始的initrd.img

[root@localhost ~]# cd /root/initrd-mlx5/
[root@localhost initrd_mlx5]# mkdir tmp #建立tmp是為了將解壓後的files暫時存放這⾥
[root@localhost initrd_mlx5]# cd tmp
[root@localhost tmp]# xz -dc ../initrd.img | cpio -id
271820 blocks
[root@localhost tmp]# ls
bin  dev  etc  init  lib  lib64  proc  root  run  sbin  shutdown  sys  sysroot  tmp  usr  var
    1
    2
    3
    4
    5
    6
    7

複製網路卡驅動到解壓後的initrd中
檢視驅動檔案路徑及依賴驅動資訊

[root@localhost tmp]# modinfo mlx5_core | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko
depends:        mlx_compat,auxiliary,devlink,ptp,mlxfw,psample
[root@localhost tmp]# modinfo mlx_compat | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/compat/mlx_compat.ko
depends:
[root@localhost tmp]# modinfo auxiliary | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/base/auxiliary.ko
depends:        mlx_compat
[root@localhost tmp]# modinfo devlink | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/net/core/devlink.ko.xz
depends:
[root@localhost tmp]# modinfo ptp | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/ptp/ptp.ko.xz
depends:        pps_core
[root@localhost tmp]# modinfo pps_core | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/pps/pps_core.ko.xz
depends:
[root@localhost tmp]# modinfo mlxfw | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlxfw/mlxfw.ko
depends:
[root@localhost tmp]# modinfo psample | egrep "filename|depends"
filename:       /lib/modules/3.10.0-957.el7.x86_64/kernel/net/psample/psample.ko.xz
depends:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24

將上面所有需要的驅動拷⻉到 /root/initrd-mlx5/tmp/lib/modules/3.10.0-
862.el7.x86_64,注意位置需要⼀⼀對應。

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlx5/core
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlx5/core/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/compat/
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/compat/mlx_compat.ko lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/compat/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/base/
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/base/auxiliary.ko lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/base/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/kernel/net/core
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/kernel/net/core/devlink.ko.xz lib/modules/3.10.0-957.el7.x86_64/kernel/net/core/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/ptp/ 
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/ptp/ptp.ko.xz lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/ptp/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/pps/
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/pps/pps_core.ko.xz lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/pps/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlxfw/
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlxfw/mlxfw.ko lib/modules/3.10.0-957.el7.x86_64/extra/mlnx-ofa_kernel/drivers/net/ethernet/mellanox/mlxfw/

[root@localhost tmp]# mkdir -p lib/modules/3.10.0-957.el7.x86_64/kernel/net/psample/
[root@localhost tmp]# cp /lib/modules/3.10.0-957.el7.x86_64/kernel/net/psample/psample.ko.xz lib/modules/3.10.0-957.el7.x86_64/kernel/net/psample/
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

更新驅動資訊模組modules.symbol/modules.alias/modules.dep

[root@localhost tmp]# cat /lib/modules/3.10.0-957.el7.x86_64/modules.symbols | egrep "mlx5_core$|mlx_compat$|devlink$|ptp$|mlxfw$|psample$|pps_core$" >> lib/modules/3.10.0-957.el7.x86_64/modules.symbols
[root@localhost tmp]# cat /lib/modules/3.10.0-957.el7.x86_64/modules.alias | egrep "mlx5_core$|mlx_compat$|devlink$|ptp$|mlxfw$|psample$|pps_core$" >> lib/modules/3.10.0-957.el7.x86_64/modules.alias
[root@localhost tmp]# depmod -b /root/initrd_mlx5/tmp -a -v * 建立依賴列表並重新對映
1
2
3

重新打包initrd 映象file

[root@localhost ~]# cd /root/initrd_mlx5/tmp/
[root@localhost tmp]# find . -print | cpio -o -H newc | xz --format=lzma > ../initrd-cx6.img
276695 blocks
[root@localhost tmp]# cd ..
[root@localhost initrd_mlx5]# ls
initrd-cx6.img initrd.img tmp
1
2
3
4
5
6

將打包好的initrd-cx6.img 複製到pxe server, 並修改引導選單

[root@simonlinux ~]# vim /var/lib/tftpboot/uefi/grub.cfg
set default="0"
set timeout=60
menuentry '1.Install CentOS 7.6 via http[With 100G CX6]' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /boot/ctos/7.6/vmlinuz inst.repo=http://www.httpboot.local/pxeimg/centos/7.6/os/x86_64 ipv6only=1 quiet
#linuxefi /images/pxeboot/vmlinuz inst.repo=http://[2001:db8:ffff💯:10]/pxeimg/centos/8.5/os/x86_64
initrdefi /boot/ctos/7.6/initrd-cx6.img
#initrdefi /boot/ctos/7.6/initrd.img
}
1
2
3
4
5
6
7
8
9

3.2 Debian9系列新增Broadcom NIC Driver
透過隨身碟或webUI安裝OS到SUT

root@debian:~# cat /etc/issue
Debian GNU/Linux 9 \n \l

root@debian:~# uname -a
Linux debian 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1 (2019-04-12) x86_64 GNU/Linux
root@debian:~#
1
2
3
4
5
6

在SUT安裝網路卡驅動

root@debian:~# ls -l bnxt_en-1.10.2-221.0.114.0.tar.gz
-rw-r--r-- 1 root root 603657 Oct 21 21:47 bnxt_en-1.10.2-221.0.114.0.tar.gz
root@debian:~# tar zxvf bnxt_en-1.10.2-221.0.114.0.tar.gz
root@debian:~# cd bnxt_en-1.10.2-221.0.114.0/
root@debian:~/bnxt_en-1.10.2-221.0.114.0# ls
bnxt.c bnxt_debugfs_cpt.c bnxt_ethtool_compat.c bnxt_lfc.h bnxt_tc.c ChangeLog
bnxt_compat.h bnxt_debugfs.h bnxt_ethtool.h bnxt_lfc_ioctl.h bnxt_tc_compat.h COPYING
bnxt_compat_link_modes.c bnxt_devlink.c bnxt_extra_ver.h bnxt_netlink.c bnxt_tc.h find_src.awk
bnxt_compat_link_modes.h bnxt_devlink.h bnxt_fw_hdr.h bnxt_netlink.h bnxt_ulp.c Makefile
bnxt_coredump.c bnxt_dim.c bnxt.h bnxt_nvm_defs.h bnxt_ulp.h MANIFEST
bnxt_coredump.h bnxt_dim.h bnxt_hsi.h bnxt_ptp.c bnxt_vfr.c README.TXT
bnxt_dcb.c bnxt_eem.c bnxt_hwrm.c bnxt_ptp.h bnxt_vfr.h
bnxt_dcb.h bnxt_eem.h bnxt_hwrm.h bnxt_sriov.c bnxt_xdp.c
bnxt_debugfs.c bnxt_ethtool.c bnxt_lfc.c bnxt_sriov.h bnxt_xdp.h
root@debian:~/bnxt_en-1.10.2-221.0.114.0# make;make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

解壓原始initrd
下載對應版本的netboot到SUT

root@debian:~# ls netboot.tar.gz
root@debian:~# cd debian-installer/
root@debian:~# tree -L 2
.
└── amd64
    ├── bootnetx64.efi
    ├── boot-screens
    ├── grub
    ├── initrd.gz
    ├── linux
    ├── pxelinux.0
    └── pxelinux.cfg
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

為新的initrd建立掛載點

root@debian:~# mkdir initrd_bnxt
    1

拷⻉netboot⾥原始的initrd.gz

root@debian:~# mkdir initrd_bnxt
root@debian:~# cp debian-installer/amd64/initrd.gz initrd_bnxt/
root@debian:~# cd initrd_bnxt/
root@debian:~/initrd_bnxt# ls
initrd.gz
    1
    2
    3
    4
    5

解壓原始的initrd.gz

root@debian:~# cd /root/initrd_bnxt/
root@debian:~/initrd_bnxt# gunzip initrd.gz
root@debian:~/initrd_bnxt# mkdir tmp #建立tmp是為了將解壓後的files暫時存放這⾥
root@debian:~/initrd_bnxt# cd tmp
root@debian:~/initrd_bnxt/tmp# cpio -i -F ../initrd
139458 blocks
root@debian:~/initrd_bnxt/tmp# ls
bin  dev  etc  init  lib  lib64  proc  root  run  sbin  shutdown  sys  sysroot  tmp  usr  var
    1
    2
    3
    4
    5
    6
    7
    8

複製網路卡驅動到解壓後的initrd中
檢視驅動檔案路徑及依賴驅動資訊

root@debian:~/initrd_bnxt/tmp# modinfo bnxt_en | egrep "filename|depends"
filename:       /lib/modules/4.9.0-9-amd64/updates/bnxt_en.ko
depends:        ptp
root@debian:~/initrd_bnxt/tmp# modinfo ptp | egrep "filename|depends"
filename:       /lib/modules/4.9.0-9-amd64/kernel/drivers/ptp/ptp.ko
depends:        pps_core
root@debian:~/initrd_bnxt/tmp# modinfo pps_core | egrep "filename|depends"
filename:       /lib/modules/4.9.0-9-amd64/kernel/drivers/pps/pps_core.ko
depends:
    1
    2
    3
    4
    5
    6
    7
    8
    9

將上面所有需要的驅動拷⻉到 /root/initrd_bnxt/tmp/ib/modules/4.9.0-9-amd64/,注意位置需要⼀⼀對應。

# copy bnxt_en
root@debian:~/initrd_bnxt/tmp# mkdir lib/modules/4.9.0-9-amd64/updates
root@debian:~/initrd_bnxt/tmp# cp /lib/modules/4.9.0-9-amd64/updates/bnxt_en.ko lib/modules/4.9.0-9-amd64/updates/.
# copy ptp
root@debian:~/initrd_bnxt/tmp# cp /lib/modules/4.9.0-9-amd64/kernel/drivers/ptp/ptp.ko lib/modules/4.9.0-9-amd64/kernel/drivers/ptp/ptp.ko
# copy pps_core.ko
root@debian:~/initrd_bnxt/tmp# cp /lib/modules/4.9.0-9-amd64/kernel/drivers/pps/pps_core.ko lib/modules/4.9.0-9-amd64/kernel/drivers/pps/pps_core.ko
    1
    2
    3
    4
    5
    6
    7

更新驅動資訊模組modules.symbol/modules.alias/modules.dep

root@debian:~/initrd_bnxt/tmp# cd lib/modules/4.9.0-9-amd64/
root@debian:~/initrd_bnxt/tmp/lib/modules/4.9.0-9-amd64# cat /lib/modules/4.9.0-9-amd64/modules.symbols | grep "bnxt_en$" >> modules.symbols
root@debian:~/initrd_bnxt/tmp/lib/modules/4.9.0-9-amd64# cat /lib/modules/4.9.0-9-amd64/modules.alias | grep -i bnxt_en >> modules.alias
root@debian:~/initrd_bnxt/tmp/lib/modules/4.9.0-9-amd64# depmod -b /root/initrd_bnxt/tmp -a -v * 建立依賴列表並重新對映
1
2
3
4

重新打包initrd 映象file

root@debian:~# cd /root/initrd_bnxt/tmp/
root@debian:~/initrd_bnxt/tmp# find . -print | cpio -o -H newc -O ../initrd-bnxt
159523 blocks
root@debian:~/initrd_bnxt/tmp# gzip -c ../initrd-bnxt > ../initrd-bnxt.gz
root@debian:~/initrd_bnxt# ls
initrd initrd-bnxt initrd-bnxt.gz tmp
root@debian:~/initrd_bnxt#

1
2
3
4
5
6
7
8

將打包好的initrd-bnxt.gz 複製到pxe server, 並修改引導選單

[root@simonlinux ~]# vim /var/lib/tftpboot/uefi/grub.cfg
set default="0"
set timeout=60
submenu '03 Debian os Install'{
menuentry 'Install Debian9.9 under UEFI mode via Preseed' {
set background_color=black
linuxefi /debian9/debian-installer/amd64/linux vga=788 debian-installer/allow_unauthenticated=true url=http://192.168.15.10/ks_cfg/preseed-uefi.cfg auto=true priority=critical interface=auto ---quiet
initrdefi /debian9/debian-installer/amd64/initrd-bnxt.gz
#initrdefi /debian9/debian-installer/amd64/initrd.gz
}
}

————————————————
版權宣告:本文為博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連結和本宣告。

原文連結:https://blog.csdn.net/weixin_45547360/article/details/127330048

相關文章