Score:1

Unbind and bind driver during startup 20.04.3 LTS

id flag

My system is running 20.04.3 LTS, and I am using it as a Plex Media Server (amongst other services). I am using a bonded network for adaptive load balancing on the system. I am bumping into an issue with the system when it receives a new kernel update.

There are 2 network cards in the system. One is in a slot (RTL8169 PCI Gigabit Ethernet Controller) and the other is onboard (RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller). The issue I am bumping into is that the RTL8111/8168/8411 does not like the r8169 driver (unpredictable things will happen like not being able to communicate with the internet) so I have to run the following commands to unbind the r8169 driver and bind the r8168 driver:

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

After running these commands the driver shows up correctly in the lshw command and I don't have any issues when the right driver is set for the right card:

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

This lasts through reboots just fine until the next kernel update. But, if I run those exact same commands in a script it tells me "No such device"

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

What would be the best way that I can make this permanent so either it makes this change during startup or it changes only when a kernel update happens?

Thanks!

Score:0
id flag

I was able to resolve my issue by creating a file for udev that performs the unbind and bind during start up.

I created a file called /etc/udev/rules.d/99-mydriver.rules and I added the following lines to the file:

SUBSYSTEM=="net", ACTION=="unbind", KERNELS=="0000:02:00.0" RUN+="/bin/bash -c 'echo 0000:02:00.0 > /sys/bus/pci/drivers/r8169/unbind'"
SUBSYSTEM=="net", ACTION=="bind", KERNELS=="0000:02:00.0" RUN+="/bin/bash -c 'echo 0000:02:00.0 > /sys/bus/pci/drivers/r8168/bind'"

Now, every time the system boots up it appears to set the proper driver to the proper NIC.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.