# How to use only r8168 and completely remove r8169?

## klopk

Hello,

I am using old PC with build-in realtek network card.

With r8169 network is very unstable, so I decided to switch to vendor drivers.

After

```
autorun.sh
```

```
#!/bin/sh

# invoke insmod with all arguments we got

# and use a pathname, as insmod doesn't look in . by default

TARGET_PATH=$(find /lib/modules/$(uname -r)/kernel/drivers/net/ethernet -name realtek -type d)

if [ "$TARGET_PATH" = "" ]; then

   TARGET_PATH=$(find /lib/modules/$(uname -r)/kernel/drivers/net -name realtek -type d)

fi

if [ "$TARGET_PATH" = "" ]; then

   TARGET_PATH=/lib/modules/$(uname -r)/kernel/drivers/net

fi

echo

echo "Check old driver and unload it."

check=`lsmod | grep r8169`

if [ "$check" != "" ]; then

        echo "rmmod r8169"

        /sbin/rmmod r8169

fi

check=`lsmod | grep r8168`

if [ "$check" != "" ]; then

        echo "rmmod r8168"

        /sbin/rmmod r8168

fi

echo "Build the module and install"

echo "-------------------------------" >> log.txt

date 1>>log.txt

make $@ all 1>>log.txt || exit 1

module=`ls src/*.ko`

module=${module#src/}

module=${module%.ko}

if [ "$module" = "" ]; then

   echo "No driver exists!!!"

   exit 1

elif [ "$module" != "r8169" ]; then

   if test -e $TARGET_PATH/r8169.ko ; then

      echo "Backup r8169.ko"

      if test -e $TARGET_PATH/r8169.bak ; then

         i=0

         while test -e $TARGET_PATH/r8169.bak$i

         do

            i=$(($i+1))

         done

         echo "rename r8169.ko to r8169.bak$i"

         mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak$i

      else

         echo "rename r8169.ko to r8169.bak"

         mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak

      fi

   fi

fi

echo "DEPMOD $(uname -r)"

depmod `uname -r`

echo "load module $module"

modprobe $module

is_update_initramfs=n

distrib_list="ubuntu debian"

if [ -r /etc/debian_version ]; then

   is_update_initramfs=y

elif [ -r /etc/lsb-release ]; then

   for distrib in $distrib_list

   do

      /bin/grep -i "$distrib" /etc/lsb-release 2>&1 /dev/null && \

         is_update_initramfs=y && break

   done

fi

if [ "$is_update_initramfs" = "y" ]; then

   if which update-initramfs >/dev/null ; then

      echo "Updating initramfs. Please wait."

      update-initramfs -u -k $(uname -r)

   else

      echo "update-initramfs: command not found"

      exit 1

   fi

fi

echo "Completed."

exit 0

```

Everything is ok:

```
        Kernel driver in use: r8168

        Kernel modules: r8168
```

But after reboot I have:

```
        Kernel driver in use: r8169

        Kernel modules: r8168
```

How to completely disable or remove r8169? I tried everything with no luck.

----------

## Jaglover

Disable 8169 in your kernel and 

```
emerge -av net-misc/r8168
```

In case of genkernel I do not know, never used it, blacklisting will work, I guess.

----------

## klopk

 *Jaglover wrote:*   

> Disable 8169 in your kernel and 
> 
> ```
> emerge -av net-misc/r8168
> ```
> ...

 

Yes, I'm using genkernel. Blacklisting doesn't work.

```
cat /etc/modprobe.d/blacklist.conf | grep r81

blacklist r8169

```

```
emerge -av net-misc/r8168
```

It doesn't change anything at all.

----------

## Ant P.

Easiest way to make it stay gone would be to remove it from disk, but moving it should work too:

```
find /lib/modules/ -name r8169.ko -execdir mv -v '{}' '{}.bak' \;
```

It looks like the driver installer should be doing that, but maybe it's detecting the wrong kernel.

Actually - just ignore this post. Neddy's answer looks correct and initrds hadn't even crossed my mind...Last edited by Ant P. on Sat May 19, 2018 3:26 pm; edited 1 time in total

----------

## NeddySeagoon

klopk,

The r8169 module is loaded from the initrd. It needs to be removed from there.

Blacklisting modues in a file on the root filesystem is too late as the file cannot be read until root is mounted.

----------

## klopk

 *Ant P. wrote:*   

> Easiest way to make it stay gone would be to remove it from disk, but moving it should work too:
> 
> ```
> find /lib/modules/ -name r8169.ko -execdir mv -v '{}' '{}.bak' \;
> ```
> ...

 

I can't find the file anymore, but it's still loading.

 *NeddySeagoon wrote:*   

> klopk,
> 
> The r8169 module is loaded from the initrd. It needs to be removed from there.
> 
> Blacklisting modues in a file on the root filesystem is too late as the file cannot be read until root is mounted.

 

So, is r8169 in this file

```
initramfs-genkernel-x86_64-4.9.76-gentoo-r1
```

?

Do I need to rebuild it like:

```
genkernel initramfs
```

Will this work or I need to tell it about new r8168?

I really don't want to break stable system, but it's useless without proper network.

----------

## NeddySeagoon

klopk,

With the r8169 module removed from the initrd, you should be good.

The automatic kernel module loading may not load the r8168 module, so you may need to add it to /etc/cont.d/modules

There is a bit of a hack until you update your kernel.

Reboot, so the r8169 is loaded. Run

```
/etc/init.d/net.eth0 stop

modprobe -r r8169

modprobe  r8168

/etc/init.d/net.eth0 start
```

use your interface name.

If that works create the file /etc/local.d/fixnet.start containing

```
#!/bin/bash

/etc/init.d/net.eth0 stop

modprobe -r r8169

modprobe  r8168

/etc/init.d/net.eth0 start
```

and chmod +x. Again, use your interface name.

This will do the module swap right at the end of the boot process, which is too late for ntp-client

Everything else that depends on the net service will be stopped and restared.

----------

## klopk

After reboot:

```
/etc/init.d/net.eth0 stop
```

gives:

```
 * Bringing down interface eth0

 *   Stopping dhcpcd on eth0 ...

sending signal TERM to pid

waiting for pid to exit

RTNETLINK answers: No such file or directory

Error talking to the kernel

```

```
modprobe -r r8169
```

gives:

```
modprobe: FATAL: Module r8169 not found.
```

```
modprobe r8168
```

gives nothing and

```
/etc/init.d/net.eth0 start
```

starts as usual, no errors - I have network.

```
lspci -k
```

```
        Kernel driver in use: r8169

        Kernel modules: r8168

```

----------

## Tyrus

I don't know what vendor specific script that is.

I have Realtek Ethernet with r8168 also. I am using net-misc/r8168. That's a driver in the portage tree. It builds a module for you. 

You just have to deactivate r8169 in the kernel and rebuild that kernel again. If you want a clean list of modules delete /lib/modules/#kernelversion# before you rebuild. Then install the modules fresh. Then emerge net-misc/r8168. It will build the required kernel module for you.

----------

## NeddySeagoon

klopk,

```
modprobe: FATAL: Module r8169 not found.
```

lells that the r8169 module is not loaded.

What does 

```
lsmod
```

 show?

----------

## klopk

 *Tyrus wrote:*   

> I don't know what vendor specific script that is.
> 
> I have Realtek Ethernet with r8168 also. I am using net-misc/r8168. That's a driver in the portage tree. It builds a module for you. 
> 
> You just have to deactivate r8169 in the kernel and rebuild that kernel again. If you want a clean list of modules delete /lib/modules/#kernelversion# before you rebuild. Then install the modules fresh. Then emerge net-misc/r8168. It will build the required kernel module for you.

 

This script is provided by Realtek. Seems like incompatible with Gentoo.

 *NeddySeagoon wrote:*   

> klopk,
> 
> ```
> modprobe: FATAL: Module r8169 not found.
> ```
> ...

 

This is after autorun.sh without rebooting:

```
Module                  Size  Used by

r8168                 524288  0

cfg80211              581632  0

rfkill                 24576  1 cfg80211

8021q                  24576  0

garp                   16384  1 8021q

stp                    16384  1 garp

llc                    16384  2 garp,stp

nouveau              1568768  1

mxm_wmi                16384  1 nouveau

wmi                    16384  2 mxm_wmi,nouveau

video                  40960  1 nouveau

ttm                    98304  1 nouveau

drm_kms_helper        155648  1 nouveau

drm                   360448  4 nouveau,ttm,drm_kms_helper

snd_hda_codec_realtek    90112  1

snd_hda_codec_generic    69632  1 snd_hda_codec_realtek

snd_hda_intel          36864  0

snd_hda_codec         126976  3 snd_hda_intel,snd_hda_codec_generic,snd_hda_codec_realtek

syscopyarea            16384  1 drm_kms_helper

kvm_intel             196608  0

sysfillrect            16384  1 drm_kms_helper

sysimgblt              16384  1 drm_kms_helper

snd_hda_core           81920  4 snd_hda_intel,snd_hda_codec,snd_hda_codec_generic,snd_hda_codec_realtek

fb_sys_fops            16384  1 drm_kms_helper

kvm                   581632  1 kvm_intel

snd_hwdep              16384  1 snd_hda_codec

nvidiafb               49152  0

it87                   57344  0

snd_pcm               102400  3 snd_hda_intel,snd_hda_codec,snd_hda_core

iTCO_wdt               16384  0

ppdev                  20480  0

iTCO_vendor_support    16384  1 iTCO_wdt

coretemp               16384  0

adt7475                32768  0

snd_timer              32768  1 snd_pcm

hwmon_vid              16384  2 it87,adt7475

fb_ddc                 16384  1 nvidiafb

vgastate               20480  1 nvidiafb

snd                    86016  7 snd_hda_intel,snd_hwdep,snd_hda_codec,snd_timer,snd_hda_codec_generic,snd_hda_codec_realtek,snd_pcm

i2c_i801               24576  0

irqbypass              16384  1 kvm

serio_raw              16384  0

pcspkr                 16384  0

i2c_smbus              16384  1 i2c_i801

lpc_ich                24576  0

ata_generic            16384  0

floppy                 69632  0

mfd_core               16384  1 lpc_ich

pata_acpi              16384  0

soundcore              16384  1 snd

parport_pc             28672  0

xts                    16384  0

gf128mul               16384  1 xts

cbc                    16384  0

sha256_generic         20480  0

iscsi_tcp              20480  0

libiscsi_tcp           24576  1 iscsi_tcp

libiscsi               53248  2 libiscsi_tcp,iscsi_tcp

scsi_transport_iscsi    98304  2 libiscsi,iscsi_tcp

vmxnet3                57344  0

virtio_net             28672  0

virtio_ring            24576  1 virtio_net

virtio                 16384  1 virtio_net

tg3                   163840  0

sky2                   61440  0

pcnet32                45056  0

mii                    16384  1 pcnet32

igb                   200704  0

ptp                    20480  2 tg3,igb

pps_core               20480  1 ptp

dca                    16384  1 igb

i2c_algo_bit           16384  3 nvidiafb,igb,nouveau

i2c_core               65536  10 fb_ddc,nvidiafb,i2c_algo_bit,igb,i2c_i801,nouveau,i2c_smbus,adt7475,drm_kms_helper,drm

e1000                 143360  0

bnx2                   81920  0

atl1c                  49152  0

fuse                   98304  1

xfs                  1175552  0

nfs                   233472  0

lockd                  73728  1 nfs

grace                  16384  1 lockd

sunrpc                303104  2 lockd,nfs

fscache                61440  1 nfs

jfs                   172032  0

reiserfs              233472  0

btrfs                1028096  0

ext4                  565248  1

jbd2                  102400  1 ext4

ext2                   73728  1

mbcache                16384  4 ext4,ext2

linear                 16384  0

raid10                 49152  0

raid1                  36864  0

raid0                  20480  0

dm_raid                40960  0

raid456               102400  1 dm_raid

async_raid6_recov      20480  1 raid456

async_memcpy           16384  2 raid456,async_raid6_recov

libcrc32c              16384  2 xfs,raid456

async_pq               16384  2 raid456,async_raid6_recov

async_xor              16384  3 async_pq,raid456,async_raid6_recov

xor                    24576  2 async_xor,btrfs

async_tx               16384  5 async_xor,async_pq,raid456,async_memcpy,async_raid6_recov

raid6_pq              110592  4 async_pq,btrfs,raid456,async_raid6_recov

dm_snapshot            40960  0

dm_bufio               28672  1 dm_snapshot

dm_crypt               28672  0

dm_mirror              24576  0

dm_region_hash         20480  1 dm_mirror

dm_log                 20480  2 dm_mirror,dm_region_hash

dm_mod                114688  6 dm_raid,dm_mirror,dm_log,dm_bufio,dm_crypt,dm_snapshot

firewire_core          65536  0

crc_itu_t              16384  1 firewire_core

sl811_hcd              24576  0

xhci_pci               16384  0

xhci_hcd              192512  1 xhci_pci

usb_storage            69632  0

aic94xx                81920  0

libsas                 73728  1 aic94xx

lpfc                  647168  0

qla2xxx               630784  0

megaraid_sas          131072  0

megaraid_mbox          36864  0

megaraid_mm            20480  1 megaraid_mbox

aacraid               102400  0

sx8                    24576  0

hpsa                  102400  0

cciss                 118784  0

3w_9xxx                45056  0

3w_xxxx                36864  0

3w_sas                 28672  0

mptsas                 61440  0

scsi_transport_sas     45056  4 libsas,hpsa,mptsas,aic94xx

mptfc                  24576  0

scsi_transport_fc      57344  3 lpfc,qla2xxx,mptfc

mptspi                 24576  0

mptscsih               40960  3 mptfc,mptsas,mptspi

mptbase               102400  4 mptscsih,mptfc,mptsas,mptspi

imm                    20480  0

parport                49152  3 imm,parport_pc,ppdev

sym53c8xx              81920  0

initio                 28672  0

arcmsr                 45056  0

aic7xxx               122880  0

aic79xx               135168  0

scsi_transport_spi     32768  4 aic79xx,aic7xxx,sym53c8xx,mptspi

sr_mod                 24576  0

cdrom                  61440  1 sr_mod

sg                     36864  0

sd_mod                 49152  4

pdc_adma               16384  0

sata_inic162x          16384  0

sata_mv                32768  0

ata_piix               36864  0

ahci                   36864  3

libahci                32768  1 ahci

sata_qstor             16384  0

sata_vsc               16384  0

sata_uli               16384  0

sata_sis               16384  0

sata_sx4               20480  0

sata_nv                28672  0

sata_via               20480  0

sata_svw               16384  0

sata_sil24             20480  0

sata_sil               16384  0

sata_promise           20480  0

pata_via               16384  0

pata_jmicron           16384  0

pata_marvell           16384  0

pata_sis               20480  1 sata_sis

pata_netcell           16384  0

pata_pdc202xx_old      16384  0

pata_atiixp            16384  0

pata_amd               20480  0

pata_ali               16384  0

pata_it8213            16384  0

pata_pcmcia            20480  0

pata_serverworks       16384  0

pata_oldpiix           16384  0

pata_artop             16384  0

pata_it821x            20480  0

pata_hpt3x2n           16384  0

pata_hpt3x3            16384  0

pata_hpt37x            20480  0

pata_hpt366            16384  0

pata_cmd64x            16384  0

pata_sil680            16384  0

pata_pdc2027x          16384  0

```

----------

## NeddySeagoon

klopk,

r8168 is loaded so r8169 cannot be. Two drivers for the same hardware is a very bad thing.

Its harmless but the hardware won't work.

----------

## Jaglover

You really should not run this autorun.sh in your Gentoo box. In Gentoo portage controls everything that is installed, installing anything outside of portage can lead to hard to diagnose failures in future. (Unless you really know what you are doing, that is.)

----------

## klopk

 *Jaglover wrote:*   

> You really should not run this autorun.sh in your Gentoo box. In Gentoo portage controls everything that is installed, installing anything outside of portage can lead to hard to diagnose failures in future. (Unless you really know what you are doing, that is.)

 

I know and I don't like it too.

But it just doesn't work by default.

----------

## Jaglover

There is ebuild for r8168, as suggested a few times in this thread. It will install the module. If you really want to use genkernel use it with menuconfig option and disable r8169. IMHO genkernel is a monster, look at all those unnecessary modules you have loaded.

----------

## 1clue

Observations:

For every hardware module in the kernel, the kernel .config should only enable that module if you have the hardware on your system or have a portable device which is likely to be plugged in at some time.

Software modules are harder to quantify, but if you know a software module to be unnecessary to your system that should be turned off too.

If your system is broken and a funky script you downloaded from somewhere on the net does NOT fix it, you should throw out the script and fix your system correctly.

Scripts you downloaded from "somewhere" are likely to be written for an older version of some random distro, which will likely use components and services which are incompatible with your system. In other words they're likely to be broken. Even if they're not broken, they likely will be when the software components you use are upgraded again. In other words, those scripts are likely to either compound the problem or they are likely to become the primary broken feature.

I understand that in this case "somewhere" is Realtek, but probably they're testing this script on a variant of Redhat or Debian. Neither of which are Gentoo. And given how Realtek cards offload so much of the networking task to the CPU, which is in my mind lazy, I am tempted to recommend you go get an Intel nic that uses the "igb" module (i210 for example), and things will be much happier on your system. But I won't recommend that because I'm trying to not be an opinionated asshole about it.

Best luck.

----------

## klopk

 *Jaglover wrote:*   

> There is ebuild for r8168, as suggested a few times in this thread. It will install the module. If you really want to use genkernel use it with menuconfig option and disable r8169. IMHO genkernel is a monster, look at all those unnecessary modules you have loaded.

 

I agree but how to understand what you need?

People complaining in manuals about broken resolution, not working mouse, sound, etc.

This is my first install.

 *1clue wrote:*   

> 
> 
> And given how Realtek cards offload so much of the networking task to the CPU, which is in my mind lazy, I am tempted to recommend you go get an Intel nic that uses the "igb" module (i210 for example), and things will be much happier on your system. But I won't recommend that because I'm trying to not be an opinionated asshole about it.
> 
> 

 

I will try few server NICs. Might be hardware related problem.

----------

## Tony0945

 *Jaglover wrote:*   

> There is ebuild for r8168, as suggested a few times in this thread. It will install the module. If you really want to use genkernel use it with menuconfig option and disable r8169. IMHO genkernel is a monster, look at all those unnecessary modules you have loaded.

 

Exactly. I used to run r8168 until my mobo's r8169 version was supported by the kernel. Unfortunately, I seem to have scrubbed it from my buildscript.

I do remember that you have to re-emerge it every time you rebuild the kernel. I don't use an intramfs so I'm not sure what steps to take for that.

As a first step run "genkernel --menuconfig" and remove r8169 from the kernel, even as a module. I think that will remove it from the intramfs. Then, after genkernel is done", emerge r8168. I don't think it needs to be in the iniramfs unless OpenRC is loading it very early. If OpenRC is loading net.eth0 (or whatever) at default level, I think you will be OK.

```
MSI ~ # rc-update|grep net.eth0

             net.eth0 | boot

```

 OK, I'm loading at boot level without any initramfs at all.

Consider moving off genkernel.

----------

## Tony0945

 *klopk wrote:*   

> 
> 
> I agree but how to understand what you need?
> 
> People complaining in manuals about broken resolution, not working mouse, sound, etc.
> ...

 

In menuconfig, go to "General setup" then enable "kernel .config support"  and  "Enable access to .config through /proc/config.gz"

Then you can extract your working config with "zcat /proc/config.gz > .config".

Start by removing hardware that you are certain you do not have like AMD chipsets if you have an Intel board and vice-versa.

That will remove quite a bit. You can also remove filesystems you don't want to support like jfs, xfs, ... (unless of course you are using jfs or xfs).

That's a start.

EDIT:

Do it in stages, always saving the last known good config. Use zcat /proc/config.gz It nevers gets confused as to which config is running.

----------

## 1clue

 *klopk wrote:*   

>  *Jaglover wrote:*   There is ebuild for r8168, as suggested a few times in this thread. It will install the module. If you really want to use genkernel use it with menuconfig option and disable r8169. IMHO genkernel is a monster, look at all those unnecessary modules you have loaded. 
> 
> I agree but how to understand what you need?
> 
> People complaining in manuals about broken resolution, not working mouse, sound, etc.
> ...

 

You need drivers built-in when the device or protocol or filesystem or <noun> is necessary for booting up to the point of mounting /.

You need drivers built-in or as modules where the <noun> is necessary for the system to run the software you intend to use.

From system rescue CD, I do this:

lspci, lsusb, lshw as described already in this thread. That tells you the hardware you have hooked up to the system.

In your kernel sources, make oldconfig. 

Ensure that all your hardware drivers are enabled. Make sure that all your early boot drivers are built-in. My rule of thumb is that if you are always going to use it, it is built in. If it's an occasional thing then it can be a module.

Leave your software drivers alone unless you know what you're doing.

Decide what major apps your system must support. Find the dependency tree, and look at the kernel settings necessary for them. Determine your USE flags and your kernel settings, and go about setting that up.

You will surely get bored before all that gets done. Try to get to the point where you have all the hardware drivers you need, and build a kernel, install and test it. Then start pruning hardware drivers you don't need, they just take up space anyway, and technically expose the system to unnecessary software exploits. It's not possible to exploit software which is not there, so any drivers you don't need can't be exploited if they're not on your system right?

At any rate, the whole software end of it is a sort of evolutionary process. First get your system running, then start trimming out the excess garbage a little bit at a time. Keep track of the USE flags and kernel modules you KNOW about and the rest are targets for future research.

 *Quote:*   

> 
> 
>  *1clue wrote:*   
> 
> And given how Realtek cards offload so much of the networking task to the CPU, which is in my mind lazy, I am tempted to recommend you go get an Intel nic that uses the "igb" module (i210 for example), and things will be much happier on your system. But I won't recommend that because I'm trying to not be an opinionated asshole about it.
> ...

 

You probably don't need to switch NICs unless you're just sick of trying. Lots of people, including myself, have used them successfully for years. They suck, but they work.

----------

## NeddySeagoon

klopk,

The short explanation is here.

The method is valid even 13 years on.

The longer, worked example is at Pappys Seeds. That's no longer maintained but it goes into a lot more detail.  The Seed Config files are now published in the Pappys Preconfigs thread on the forums.

If you decide to use one of Pappys Preconfigs as a starting point, be aware that it designed to not work as is. You need to add your own hardware support.

Building your own kernel for the first time is like eating an elephant. Do it one plateful at a time.

The good news is that you don't need to do it all in one go and you can use the error messages as pointers to what to fix next.

If you don't understand the error messages, many of your helpers in this thread will.

----------

## 1clue

@NeddySeagoon,

Aren't we still supposed to use -fno-stack-check on the kernel? Your link makes no mention of it.

I have a script "kmake":

```
#!/bin/bash

KCFLAGS=-fno-stack-check make -j12 V=1 $1 | egrep --color -E '(no-stack-check|stack-check|$)'

```

I use this for kernel builds, the same exact way that we have been using make all these years.Last edited by 1clue on Tue May 22, 2018 4:53 pm; edited 1 time in total

----------

## NeddySeagoon

1clue,

```
 $ grep no-stack-check /usr/src/linux/Makefile 

KBUILD_CFLAGS  += $(call cc-option,-fno-stack-check,)
```

It looks like the kernel does that for you.

----------

## 1clue

OK that's cool. I never heard about that, only that the option needed to be selected for kernels.

```
#!/bin/bash

make -j12 V=1 $1 | egrep --color -E '(no-stack-check|stack-check|$)'

```

It appears that it works, I see -fno-stack-check highlighted in the output.

----------

