How to install Realtek's proprietary r8168.ko module driver

We have 20 HP laptops with the integrated Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15). The default option in Linux is to use kernel’s r8169.ko, which was very unstable in our case. Network disappeared often with transmit queue 0 timed out in dmesg, followed by stack trace.

The Internet has a plenty of reports of this issue, and there are several solutions exist regarding the kernel’s driver, none of which helped in our case. Another recommendation is to compile and install the Realtek’s proprietary driver from their website. This might be tricky in Endless OS, so here is how we did it:

First, check your kernel version with uname -a. In my case it was 4.15.0-15-generic. Fortunately, Endless OS uses patched Ubuntu kernels, so we can use an Ubuntu box to compile the module. Install Ubuntu 18.04 somewhere, I used VirtualBox and the server edition of Ubuntu. Then you need to install the corresponding version of the kernel. You can use something like http://packages.ubuntu.com/linux-image-4.15.0-15-generic to search it. Then install it, we will need image and headers packages, e.g. linux-image-4.15.0-15-generic, linux-headers-4.15.0-15-generic and linux-headers-4.15.0-15 in my case. Then install r8168-dkms Ubuntu package. The module will be built and placed in /lib/modules/4.15.0-15-generic/updates/dkms/. If it is not, run dkms install -m r8168 -v 8.045.08 -k 4.15.0-15-generic (replace driver and kernel versions with yours).

Then you have to copy the resulting r8168.ko and /etc/modprobe.d/r8168-dkms.conf to their respective places on the Endless OS box. To unlock the OSTree, execute ostree admin unlock --hotfix, after that you’ll be able to copy files and execute depmod -a. The r8168 module then will be used after the reboot.

Bear in mind, however, that you should repeat this procedure after each upgrade. If it’s not what you want, you should disable automatic updates. Hope this helps somebody struggling with the similar issue.