WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Network adapters sometimes not available after boot  (Read 6206 times)

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Network adapters sometimes not available after boot
« on: August 07, 2017, 10:57:25 PM »
I've noticed an intermittent problem with both x86 and x86_64 during tc-config. If using PXE and httplist with nodhcp, the ethernet adapters (using e1000 module) are sometimes not available, so the boot fails. Fail means no extensions are loaded so no services are running. Usually eth0 has the IP address assigned to it from the bootp server. I don't see where in tc-config the ethernet device status is checked if not using DHCP before trying httplist. At some point either the ethernet adapter has to become available, or reboot and see if that fixes it. This is using 8.1rc2 for what it's worth, but I've noticed it on 8.0 and 7.x before.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Network adapters sometimes not available after boot
« Reply #1 on: August 08, 2017, 03:17:03 AM »
This is the first I've heard of this, but you're probably right. Patches welcome.
The only barriers that can stop you are the ones you create yourself.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Network adapters sometimes not available after boot
« Reply #2 on: August 08, 2017, 10:29:25 AM »
/etc/init.d/dhcp.sh runs whether or not nodhcp is given on the boot command line if httplist is used. In fact I don't see anywhere a method of using static IP addresses. Currently I do that in /opt/bootlocal.sh, but it should happen sooner if httplist is going to work consistently. If I'm going to write a patch, it would be something like "if nodhcp then do static IP config, and don't run dhcp.sh." The appropriate place looks like where the loopback address is set, since it's the first static IP. There are lots of ways to do this. What would a TC way look like? Unless a configuration file is in a supplemental initrd, how could addresses be available? Cluttering up the boot command line doesn't seem like my first choice, but I don't see another way.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Network adapters sometimes not available after boot
« Reply #3 on: August 08, 2017, 11:20:06 AM »
How do you intend to PXE boot without dhcp?
Why not set a reservation in your dhcp server?

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Network adapters sometimes not available after boot
« Reply #4 on: August 08, 2017, 01:44:35 PM »
The IP address that the bootp server gives the PXE boot environment is usually the one the system will use after boot, but it doesn't have to be. It only has to work for the PXE boot loader to find the TFTP server. The kernel doesn't know anything of the PXE environment, and so has to start over via init.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Network adapters sometimes not available after boot
« Reply #5 on: August 09, 2017, 03:29:39 AM »
Hm, I have to think that's a rare corner case, dynamic IP for PXE and a static one after that. As we don't have a unified method for static IPs (we don't force the GUI-generated eth0.sh/etc), I don't think that would belong in tc-config at all.

So, I'd think it would be best for you to handle it all in bootsync; set the IP, wait for it to become available, and load httplist/etc.
The only barriers that can stop you are the ones you create yourself.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Network adapters sometimes not available after boot
« Reply #6 on: August 09, 2017, 11:44:12 AM »
The real problem is in dhcp.sh. "/sbin/udevadm settle" doesn't work, which is what initiated my debugging spree.

I added this to /etc/init.d/rcS (and commented out the same parts in tc-config):

Code: [Select]
/sbin/udevd --daemon 2>&1 >/dev/null
/sbin/udevadm trigger --action=add 2>&1 >/dev/null &
/sbin/udevadm settle --timeout=5

/sbin/ifconfig lo 127.0.0.1 up
/sbin/route add 127.0.0.1 lo &

for i in $(/usr/bin/seq 1 99); do
        /bin/echo "network config loop $i"
        /bin/grep -q eth1 /proc/net/dev && break || /bin/usleep 200000
done

/sbin/ifconfig eth0 192.168.3.6 netmask 255.255.255.0
/sbin/ifconfig eth1 w.x.y.196 netmask 255.255.255.248
/sbin/route add -net default gateway w.x.y.198
/sbin/route add -net 192.168.2.0/24 gateway 192.168.3.75

The result is this:

Code: [Select]
Decompressing Linux... Parsing ELF... No relocation needed... done.
Booting the kernel.
[    0.522453] intel_powerclamp: CPU does not support MWAIT
init started: BusyBox v1.27.1 (2017-07-31 12:19:44 UTC)
network config loop 1
network config loop 2
network config loop 3
network config loop 4
network config loop 5
network config loop 6
Booting Core 8.1rc2
Running Linux Kernel 4.8.17-tinycore.
Checking boot options... Done.
Starting udev daemon for hotplug support... Done.
Skipping compressed swap in ram as requested from the boot command line.
Scanning hard disk partitions to create /etc/fstab
Setting Language to en_US.UTF-8 Done.
...

As you can see "/sbin/udevadm settle" isn't waiting for the ethernet interfaces to be available, and I have to loop over /proc/net/dev for a bit before the interfaces can be configured. This is just a demonstration case, not a proposed solution. /etc/init.d/rcS is meant to be customizeable like /opt/bootlocal.sh, it's just a little farther up the learning curve. Modifying tc-config locks me into a version, which I would like to avoid. In tc-config httplist and tftplist both assume (require?) DHCP is being used. In /etc/init.d/rcS /etc/init.d/tc-config is run in a separate shell. If it was sourced instead, tc-config would be able to access some variables or functions defined in rcS to do the static config when it was ready.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Network adapters sometimes not available after boot
« Reply #7 on: August 09, 2017, 12:58:22 PM »
Udevadm should wait for it; if you run "udevadm trigger --dry-run --action=add --verbose", your eth card will be included in the output. Though it's possible it waits for a different condition than "up and running", maybe something like "module has been successfully loaded and registered", but that's just a guess.
The only barriers that can stop you are the ones you create yourself.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Network adapters sometimes not available after boot
« Reply #8 on: August 09, 2017, 03:16:22 PM »
I tried getting more info about "udevadm settle", but it seemed like the pages should have had some tap dance audio to go along with them. In other words not real helpful. Maybe this might be more helpful:

Code: [Select]
--- /home/andy/tc-config
+++ etc/init.d/tc-config
@@ -223,7 +223,11 @@
 
 # dhcp.sh runs udhcpc async, so it exits before network is up
 wait4Server() {
-       /etc/init.d/dhcp.sh
+       if [ -n "$NODHCP" -a "$(type -t static_ip)" == "static_ip" ]; then
+               static_ip
+       else
+               /etc/init.d/dhcp.sh
+       fi
        SERVER=$1 ; NOPING=$2 ; CNT=0
        if [ "$NOPING" == "1" ] ; then
                until ifconfig | grep -q Bcast

Then in rcS define static_ip and source tc-config:

Code: [Select]
#!/bin/sh
# RC Script for Tiny Core Linux
# (c) Robert Shingledecker 2004-2012

# Mount /proc.
[ -f /proc/cmdline ] || /bin/mount /proc

# Remount rootfs rw.
/bin/mount -o remount,rw /

# Mount system devices from /etc/fstab.
/bin/mount -a

static_ip(){
for i in $(/usr/bin/seq 1 99); do
        /bin/grep -q eth1 /proc/net/dev && break || /bin/usleep 200000
done

/sbin/ifconfig eth0 192.168.3.6 netmask 255.255.255.0
/sbin/ifconfig eth1 w.x.y.196 netmask 255.255.255.248
/sbin/route add -net default gateway w.x.y.198
/sbin/route add -net 192.168.2.0/24 gateway 192.168.3.75
}

. /etc/init.d/tc-config

This works for me consistently now, so something to consider. Did someone say patch?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: Network adapters sometimes not available after boot
« Reply #9 on: August 10, 2017, 05:27:11 AM »
Please post it on any hosting service, including patches.tinycorelinux.net. Copypasting from the forum always whitespace-damages them.
The only barriers that can stop you are the ones you create yourself.

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Network adapters sometimes not available after boot
« Reply #10 on: August 10, 2017, 09:25:36 AM »
Static IP patch to tc-config uploaded to patches.tinycorelinux.net.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14851
Re: Network adapters sometimes not available after boot
« Reply #11 on: August 10, 2017, 09:58:42 AM »
thanks - pushed to tinycore git

Offline MSumulong

  • Newbie
  • *
  • Posts: 25
Re: Network adapters sometimes not available after boot
« Reply #12 on: March 09, 2018, 04:37:54 PM »
I am having the same exact issue where the extensions do not get loaded sometimes but I am using the tftplist option and I am using dhcp to obtain an IP address (all to PXE boot TinyCore).

I might try this patch but I think the changes to the rcS file need to be patched in too (ie. the static_ip() function).