我的系统运行的是 20.04.3 LTS,我将其用作 Plex 媒体服务器(以及其他服务)。我使用绑定网络在系统上实现自适应负载平衡。当系统收到新的内核更新时,我遇到了问题。
系统中有 2 个网卡。一个在插槽中(RTL8169 PCI 千兆以太网控制器),另一个在板载(RTL8111/8168/8411 PCI Express 千兆以太网控制器)。我遇到的问题是 RTL8111/8168/8411 不喜欢 r8169 驱动程序(会发生不可预测的事情,例如无法与互联网通信),所以我必须运行以下命令来解除 r8169 驱动程序的绑定并绑定 r8168 驱动程序:
address=$(lspci | awk '/8168/ {print "0000:"$1}')
echo $address | sudo tee /sys/bus/pci/drivers/r8169/unbind
echo $address | sudo tee /sys/bus/pci/drivers/r8168/bind
运行这些命令后,驱动程序会在命令中正确显示lshw
,并且当为正确的卡设置正确的驱动程序时,我没有遇到任何问题:
terrance@Intrepid:~$ sudo lshw -C network
*-network
description: Ethernet interface
product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 0
bus info: pci@0000:02:00.0
logical name: eth0
version: 03
serial: c8:3a:35:d6:ec:a0
size: 1Gbit/s
capacity: 1Gbit/s
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8168 driverversion=8.048.00-NAPI duplex=full latency=0 link=yes multicast=yes port=twisted pair slave=yes speed=1Gbit/s
resources: irq:25 ioport:d800(size=256) memory:fdfff000-fdffffff memory:fdff8000-fdffbfff
*-network
description: Ethernet interface
product: RTL8169 PCI Gigabit Ethernet Controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 5
bus info: pci@0000:03:05.0
logical name: eth1
version: 10
serial: bc:5f:f4:79:66:fe
size: 1Gbit/s
capacity: 1Gbit/s
width: 32 bits
clock: 66MHz
capabilities: pm bus_master cap_list rom ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=5.13.0-30-generic duplex=full latency=64 link=yes maxlatency=64 mingnt=32 multicast=yes port=twisted pair slave=yes speed=1Gbit/s
resources: irq:20 ioport:e800(size=256) memory:febffc00-febffcff memory:febc0000-febdffff
*-network
description: Ethernet interface
physical id: 1
logical name: bond0
serial: bc:5f:f4:79:66:fe
capabilities: ethernet physical
configuration: autonegotiation=off broadcast=yes driver=bonding driverversion=5.13.0-30-generic duplex=full firmware=2 ip=10.0.0.220 link=yes master=yes multicast=yes
这在下次内核更新之前一直有效。但是,如果我在脚本中运行这些完全相同的命令,它会告诉我“没有这样的设备”
terrance@Intrepid:~/bin$ sudo ./driver_fix.bsh
0000:02:00.0
tee: /sys/bus/pci/drivers/r8169/unbind: No such device
0000:02:00.0
tee: /sys/bus/pci/drivers/r8168/bind: No such device
使它永久生效的最佳方法是什么,以便它在启动期间进行此更改,或者仅在内核更新时更改?
谢谢!
答案1
事实证明,您需要unbind
在运行该bind
行之前创建。您可以将其添加到脚本中,然后在重新启动时使用 cron 或其他程序(例如 systemd)运行。
我在脚本文件中添加了以下几行:
address=$(/usr/bin/lspci | awk '/8168/ {print "0000:"$1}')
sh -c "echo $address > /sys/bus/pci/drivers/r8169/unbind"
sh -c "echo $address > /sys/bus/pci/drivers/r8168/bind"
然后将以下行添加到/etc/crontab
:
@reboot root /home/terrance/bin/fix_rtl.bsh
现在,当系统重新启动时,正确的驱动程序就会连接到正确的 NIC。
terrance@Intrepid:~$ sudo lshw -C network
*-network
description: Ethernet interface
product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 0
bus info: pci@0000:02:00.0
logical name: eth0
version: 03
serial: bc:5f:f4:79:66:fe
size: 1Gbit/s
capacity: 1Gbit/s
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8168 driverversion=8.049.02-NAPI duplex=full latency=0 link=yes multicast=yes port=twisted pair slave=yes speed=1Gbit/s
resources: irq:25 ioport:d800(size=256) memory:fdfff000-fdffffff memory:fdff8000-fdffbfff
*-network
description: Ethernet interface
product: RTL8169 PCI Gigabit Ethernet Controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 5
bus info: pci@0000:03:05.0
logical name: eth1
version: 10
serial: c8:3a:35:d6:ec:a0
size: 1Gbit/s
capacity: 1Gbit/s
width: 32 bits
clock: 66MHz
capabilities: pm bus_master cap_list rom ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=5.13.0-35-generic duplex=full latency=64 link=yes maxlatency=64 mingnt=32 multicast=yes port=twisted pair slave=yes speed=1Gbit/s
resources: irq:20 ioport:e800(size=256) memory:febffc00-febffcff memory:febc0000-febdffff
*-network
description: Ethernet interface
physical id: 1
logical name: bond0
serial: c8:3a:35:d6:ec:a0
capabilities: ethernet physical
configuration: autonegotiation=off broadcast=yes driver=bonding driverversion=5.13.0-35-generic duplex=full firmware=2 ip=10.0.0.220 link=yes master=yes multicast=yes