重新加载网卡默认驱动
2021/8/12 6:36:30
本文主要是介绍重新加载网卡默认驱动,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
shell
#!/bin/bash N3=enp134s0f0 N3=0000:86:00.0 N6=enp134s0f3 N6=86:00.3 function get_nic_bdf(){ IFC=$1 # echo "Load driver for interface: $IFC" ls /sys/class/net/$IFC/device > /dev/null if [ $? -ne 0 ]; then echo "No interface: $IFC. Need to provide the PCI address for $IFC."; return 1 fi bdf=`ls /sys/class/net/$IFC/device -l | awk -F'/' '{print $9}'` echo $bdf } function get_nic_bdf(){ IFC=$1 # echo "Load driver for interface: $IFC" ls /sys/class/net/$IFC/device > /dev/null if [ $? -ne 0 ]; then echo "No interface: $IFC. Need to provide the PCI address for $IFC."; return 1 fi bdf=`ls /sys/class/net/$IFC/device -l | awk -F'/' '{print $9}'` echo $bdf } function load_driver(){ addr=$1 bdf="" if [[ $addr =~ ^0{4}:[0-9a-f]{2}:[0-9a-f]{2}\.[0-9]$ ]]; then bdf=$1 echo "load driver for PCI device: $addr" elif [[ $addr =~ ^[0-9a-f]{2}:[0-9a-f]{2}\.[0-9]$ ]]; then bdf=0000:$1 echo "load driver for PCI device: $addr" fi if [ -z "$bdf" ]; then IFC=$1 echo "Load driver for interface: $IFC" ls /sys/class/net/$IFC/device > /dev/null if [ $? -ne 0 ]; then echo "No BDF found for interface: $IFC, let's guess from the name." if [[ $IFC =~ ^.*p[0-9]{1,3}s[0-9]{1,3}f[0-9]$ ]]; then bdf=${IFC#*p} b=${bdf%%s*} b=`printf '%0.2x\n' $b` s=${bdf%%f*} s=${s##*s} s=`printf '%0.2x\n' $s` f=${bdf##*f} bdf="0000:$b:$s.$f" echo "Guess interface: $IFC PCI address is $bdf" else echo "No interface: $IFC. Need to provide the PCI address for $IFC."; return 1 fi else bdf=`ls /sys/class/net/$IFC/device -l | awk -F'/' '{print $9}'` fi fi path=/sys/bus/pci/devices/$bdf VDID=`lspci -nnv |grep ^${bdf#*:} | grep -E -o '[0-9a-f]{4}:[0-9a-f]{4}'` DID=${VDID#*:} VID=${VDID%:*} driver=$(grep "v0000${VID}d0000${DID}" /lib/modules/$(uname -r)/modules.alias |awk '{print $3}') cdriver=`ls /sys/bus/pci/devices/0000:88:00.0/driver -l` if [ $? -eq 0 ]; then cdriver=${cdriver##*/} # if [ "$driver" == "$cdriver" ]; then # echo "Driver is $driver, No need to reload, exit." # return 0 # fi if [ -n "$cdriver" ]; then echo "Unload $bdf driver: $cdriver" echo "echo $bdf | sudo tee /sys/bus/pci/drivers/$cdriver/unbind" echo "$bdf" | sudo tee /sys/bus/pci/drivers/$cdriver/unbind sleep 1 fi fi echo "echo \"$VID $DID\" | sudo tee /sys/bus/pci/drivers/$driver/new_id" echo "$VID $DID" | sudo tee /sys/bus/pci/drivers/$driver/new_id echo "echo \"${bdf}\" > /sys/bus/pci/drivers/$driver/bind" echo ${bdf} > /sys/bus/pci/drivers/$driver/bind ls -d /sys/bus/pci/drivers/$driver/$bdf if [ -f "${path}/driver_override" ]; then echo "echo $driver > ${path}/driver_override" echo "$driver" > ${path}/driver_override fi ls -d /sys/bus/pci/drivers/$driver/$bdf if [ $? -ne 0 ]; then echo "Bind $driver for $bdf failed"; fi cdriver=`ls /sys/bus/pci/devices/0000:88:00.0/driver -l` if [ $? -eq 0 ]; then cdriver=${cdriver##*/} if [ "$driver" == "$cdriver" ]; then echo "Load driver: $driver for $bdf successfully." fi fi echo "$bdf, $driver, $VDID" echo "" } load_driver $N3 load_driver $N6
这篇关于重新加载网卡默认驱动的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南