Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: funguy on March 11, 2012, 06:03:37 PM

Title: I would like DHCP finished running before I run ghost
Post by: funguy on March 11, 2012, 06:03:37 PM
I noticed that when I boot TCL sometimes udhcpc isn't finished and i have to wait.  After I wait everything is fine.  Is there a kernel boot option to wait for udhcpd before startx continues.  If not what command other than sleep can I run to wait for the udhcpc to complete assigning ips before it runs the next command that needs network up first?
Title: Re: I would like DHCP finished running before I run ghost
Post by: maro on March 11, 2012, 06:38:27 PM
I personally would probably not use an unconditional 'sleep' but rather something like
    while [ -z "$( ifconfig eth0 | grep 'inet addr' )" ] ; do sleep 1 ; done
to wait until the NIC in question shows an IP address. Any call to an application that requires a working NIC can follow afterwards.
Title: Re: I would like DHCP finished running before I run ghost
Post by: funguy on March 11, 2012, 07:02:52 PM
That looks good but imagine a server with say 6 nics and other machines with just 1 nic.  I need to account for all "present" nics.  It isn't always eth0.  Any additional ideas?
Title: Re: I would like DHCP finished running before I run ghost
Post by: Rich on March 11, 2012, 07:24:09 PM
Hi funguy
You could loop through the /sys/class/net directory.
Skip the dummy and lo entries.
Check the carrier file on the remaining entries. When the NIC comes up, it will contain a 1, when it's down, the file is empty.
Title: Re: I would like DHCP finished running before I run ghost
Post by: funguy on March 11, 2012, 11:03:11 PM
do you have code for that loop?  I just wish there was a way to tell by the original process, or undo the seperated dhcp method that allows it to fork to the background if needed.
Title: Re: I would like DHCP finished running before I run ghost
Post by: Rich on March 12, 2012, 02:08:28 AM
Hi funguy
I think this should work:
Code: [Select]
#!/bin/sh

NicCount=0
Timeout=10

for NICS in `ls -1 /sys/class/net`
do
[ "$NICS" = "dummy0" ] && continue
[ "$NICS" = "lo" ] && continue
let "NicCount += 1"
/bin/rm -f /tmp/$NICS.found
done

while [ $Timeout -gt 0 ]
do
for NICS in `ls -1 /sys/class/net`
do
[ "$NICS" = "dummy0" ] && continue
[ "$NICS" = "lo" ] && continue
if [ ! -e /tmp/$NICS.found ]
then
if [ `/bin/grep 1 /sys/class/net/$NICS/carrier` ]
then
touch /tmp/$NICS.found
let "NicCount -= 1"
fi
fi
done
[ $NicCount -le 0 ] && break
sleep 1
let "Timeout -= 1"
done

echo $NicCount
The script will continue to execute until all the network interfaces are brought up. Should any interfaces fail
to come up, there is a 10 second timeout to terminate the loop. If all the interfaces were brought up, it
returns 0, otherwise it returns the number of interfaces that failed to come up.
Title: Re: I would like DHCP finished running before I run ghost
Post by: curaga on March 12, 2012, 11:41:13 AM
It's considered bad practise to have more than one NIC use dhcp, you know ;)
Title: Re: I would like DHCP finished running before I run ghost
Post by: funguy on March 19, 2012, 02:42:16 PM
Tested and minor issues.  Eth0 unplugged and eth1 ready leads to 10 second pause during testing.  Can the script be modded to skip no-link ethernets?
Title: Re: I would like DHCP finished running before I run ghost
Post by: Rich on March 19, 2012, 03:19:42 PM
Hi funguy
I don't know how you would tell the difference between a link that has not yet been brought up and one that
is not connected. You can modify   Timeout=10  to  Timeout=5  or to whatever you want, I just pulled that
number out of thin air.
Title: Re: I would like DHCP finished running before I run ghost
Post by: bmarkus on March 19, 2012, 03:25:20 PM

I don't know how you would tell the difference between a link that has not yet been brought up and one that
is not connected.


You can detect whether line is connected or not with ethtool:

Quote
[root@zero ~]# ethtool eth0
Settings for eth0:
        Supported ports: [ MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 1
        Transceiver: external
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: d
        Link detected: yes
[root@zero ~]#
Title: Re: I would like DHCP finished running before I run ghost
Post by: Rich on March 19, 2012, 04:36:42 PM
Hi bmarkus
All I get is this:
Quote
[tc@box:~$ sudo ethtool eth0
Settings for eth0:
        Supports Wake-on: d
        Wake-on: d
tc@box:~$ /quote]