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
通过U盘或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