# Broken eth0 coldplugging config, maybe. [SOLVED]

## peenie

I had wanted to prevent net.eth0 from initializing on boot. Removing net.eth0 from the runlevel didn't work, something else still initialized eth0 ("device initiated services: eth0"). I ended up setting config_eth0 to null in /etc/conf.d/net, but as an experiment, I edited /etc/conf.d/rc and added "!net.eth0" to RC_PLUG_SERVICES.

I also have a wireless adapter which is normally eth1. When I used !net.eth0, the wireless adapter became eth0, which makes sense I guess.

Later, I wanted to undo the change so I removed the !net.eth0 from RC_PLUG_SERVICES. But for some reason it's still behaving (and somewhat randomly) like !net.eth0 is present.

The current state of things is that RC_PLUG_SERVICES is empty (""), and when I boot the machine, eth0 is sometimes the wireless adapter (and eth1 doesn't exist; the wired adapter isn't initialized at all). By "sometimes" I mean on soft reboots. A full power off and back on again and it works correctly every time (eth0 is wired, eth1 is wireless), but a soft reboot (like the reboot command) and the wired adapter is broken. At least, I think this is the case, I've done a hard restart 3 times and soft reboots 9 or 10 and every time it behaved like that, so I'm assuming there's a connection there.

Everything worked perfectly before I changed RC_PLUG_SERVICES. I'm at a loss since I've restored /etc/conf.d/rc to it's original state but things are broken now.

Is there some sort of other config file somewhere that information is placed in automatically that I perhaps have to reset to restore the original behavior? Or something?

Thanks,

JasonLast edited by peenie on Wed Sep 20, 2006 2:10 am; edited 1 time in total

----------

## wynn

NeddySeagoon says that you can't be sure which device the kernel chooses as eth0.

There is a post (NIC switch order problem) in which Corona688 (https://forums.gentoo.org/viewtopic-p-3478191.html#3478191) shows how to set udev rules so you get eth0 and eth1 to be the same devices every time.

----------

## peenie

Thanks for digging that up; I'll try it on Monday and post the results. I haven't been able to figure it out on my own yet; it still kind of bothers me that it -used- to work just fine, 100% of the time.

----------

## wynn

 *Quote:*   

> it still kind of bothers me that it -used- to work just fine, 100% of the time.

 Computers are deterministic devices with non-deterministic behaviour   :Very Happy: 

----------

## peenie

 *wynn wrote:*   

> Computers are deterministic devices with non-deterministic behaviour  

 

That's how I like my women, too. I have no idea what that means, but in any case, I seemed to have solved the problem using udev rules (thanks). Here are the steps I think I took:

1.

Write the udev rules to map hardware addresses (or whatever sysfs info) to some specific interface names, as mentioned in the above link. Google for "udev rules", the first result is a nice page with lots of information about what you can do with the rules. If you are using the mac address you'll need to figure out what they are first. I couldn't figure out how to get the hardware address without having the devices configured so I just ended up having to reboot my computer a lot until both eth0 and eth1 randomly decided to initialize. Annoying. Udev rules go in /etc/udev/rules.d/. You can append to an existing file or make a new one, I don't know much about the naming scheme but I made a new file named "01-nic.rules" containing the following rules:

 *Quote:*   

> KERNEL=="eth*" SYSFS{address}=="00:16:41:59:fa:91" NAME="lan"
> 
> KERNEL=="eth*" SYSFS{address}=="00:13:02:85:13:0a" NAME="wlan"

 

You can pick any names you want, I picked lan and wlan as per that suggestion. Note that those are curly braces {}, not parens, god dammit. Also mind your = and =='s.

2.

Be sure to remove the net.* init.d scripts for the interfaces you are configuring here, such as:

 *Quote:*   

> rc-update del net.eth0
> 
> rc-update del net.eth1

 

3.

Create and add some new init.d scripts for the new device names, such as:

 *Quote:*   

> cd /etc/init.d
> 
> ln -s net.lo net.lan
> 
> ln -s net.lo net.wlan
> ...

 

I put net.lan in default, not in boot. I don't really know what the implications are of putting it in the boot runlevel, but it's working fine.

4.

Disable coldplugging for these devices. If you read around about everybody's various annoying eth0 problems (yes, it's been decades and the kernel devs still can't seem to get this right I guess, perhaps they need more/less coffee), at some point, somewhere on the internet, somebody had said something about udev doing coldplugging and coldplug being obsolete. But also, you don't want to disable coldplug entirely because I guess it messes with USB keyboards and mice; which I guess udev doesn't handle? I have no idea. Don't ask me. But go edit your /etc/conf.d/rc file and add "!net.lan !net.wlan" to RC_PLUG_SERVICES. Make sure you remove, say, "net.eth0" if you put it in there at some point. Alternatively you could just do "!net.*" to cover them all.

5.

Oops almost forgot; update your /etc/conf.d/net file to reflect any device name changes (e.g. "config_eth0 becomes config_lan").

6.

If you use a text editor that creates temporary files in the directory that the file you saved is in, make sure you get rid of those temporary files. I don't know exactly what files the system scans for things but I didn't really want "01-nic.rules~" laying around.

7.

Run modules-update out of paranoia. I have no idea if this is relevant but I'm sick of things randomly breaking. You may also want to run env-update, cfg-update, emerge --sync ; emerge -NDu world, source /etc/profile, eselect cblas set threaded-atlas, and gnibbles. I don't know. However, I do know that gnibbles is an awesome game which I totally rock at (although new versions of Gnome seem to have dropped the g from the front of the names, which is a travesty, IMO).

Restart computer and cross fingers. It worked for me.

Thanks again for finding that,

Jason

----------

## wynn

Thanks for your very helpful post and for taking the time to write it all up. I will make sure I have a link to it so I can quote at in the future and appear wise   :Smile: 

The MAC address: I'm not sure if ethtool works when the device isn't configured but

```
# ethtool -d eth0

RealTek RTL-8169s registers:

------------------------------

0x00: MAC Address                      00:50:8d:ed:9f:96
```

plus a whole lot of other stuff. ethtool seems quite a remarkable instrument, "ethtool --help" fills a screen and I don't know what half of it means.

 *Quote:*   

> You may also want to run env-update, cfg-update, emerge --sync ; emerge -NDu world, source /etc/profile, eselect cblas set threaded-atlas, and gnibbles.

 You could file a bug report and suggest adding all these to the next version of baselayout   :Very Happy: 

----------

## Haakon

Just wanted to add something where I messed up in the helpful instructions that Peenie has provided.

I might be the only one that had this problem, but make sure you keep it all lowercase for the MAC   :Very Happy: 

Thanks Peenie!

----------

