View previous topic :: View next topic |
Author |
Message |
FlipFlop n00b
Joined: 03 Mar 2003 Posts: 47 Location: DTU, Denmark
|
Posted: Thu Sep 04, 2003 10:09 pm Post subject: laptops and net.eth0 in the boot or default runlevel |
|
|
It's a PITA !!
when starting the system with no network attached the boot process is delayed while dhcp times out .. on the other hand you have to start the net.eth0 service manually when you do have a network attached and the net.eth0 script is not in the runlevels..
WindowsXP seems to be able to tell whether there's a network cable attached to the computer .. Is Linux able to do this too ?
Wouldn't it be nice if the net.eth0 script checked for a connection before it tried to start dhcpd ? _________________ Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages. |
|
Back to top |
|
|
ScubaStreb Tux's lil' helper
Joined: 01 Jul 2002 Posts: 118
|
Posted: Fri Sep 05, 2003 2:41 am Post subject: |
|
|
Just hit Crtl + C when it is looking for the network and it stops looking. _________________ "Without question, the greatest invention in the history of mankind is beer. Oh, I grant you that the wheel was also a fine invention, but the wheel does not go nearly as well with pizza." --Dave Barry |
|
Back to top |
|
|
smiler.se Tux's lil' helper
Joined: 18 Aug 2003 Posts: 115 Location: Sweden - Europe - Earth
|
Posted: Fri Sep 05, 2003 7:22 am Post subject: |
|
|
I would like something similar.. check if the network cable is in _or_ is it possible somehow via grub to make two different entires - one loading net.eth0 and one loading net.eth1 (wireless) _________________ Christian
Sig out of date. Please upgrade to a newer one. |
|
Back to top |
|
|
FlipFlop n00b
Joined: 03 Mar 2003 Posts: 47 Location: DTU, Denmark
|
Posted: Fri Sep 05, 2003 7:49 am Post subject: |
|
|
ScubaStreb wrote: | Just hit Crtl + C when it is looking for the network and it stops looking. |
I thought all keyboard input was ignored during startup .. i'll try it.. _________________ Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages. |
|
Back to top |
|
|
smiler.se Tux's lil' helper
Joined: 18 Aug 2003 Posts: 115 Location: Sweden - Europe - Earth
|
Posted: Fri Sep 05, 2003 10:29 am Post subject: |
|
|
Hitting CTRL + C wont help me, also, all services depending on networking fails because of net.eth0 wont get up (no cable) but if I could choose at boot all these problems would be gone. _________________ Christian
Sig out of date. Please upgrade to a newer one. |
|
Back to top |
|
|
Salze n00b
Joined: 17 Oct 2002 Posts: 52 Location: Germany
|
Posted: Fri Sep 05, 2003 12:07 pm Post subject: Re: laptops and net.eth0 in the boot or default runlevel |
|
|
Hi FlipFlop!
Have a look at mitt-tool and swatch and write (yourself) a small script.
bye
Salze |
|
Back to top |
|
|
petardi Tux's lil' helper
Joined: 29 Mar 2003 Posts: 79 Location: SI
|
Posted: Fri Sep 05, 2003 12:46 pm Post subject: |
|
|
Try ifplugd. It can start a network interface when a cable is plugged in, and stop it when it's plugged out. |
|
Back to top |
|
|
ronmon Veteran
Joined: 15 Apr 2002 Posts: 1043 Location: Key West, FL
|
Posted: Fri Sep 05, 2003 2:16 pm Post subject: |
|
|
If you use dhcp you can set a short timeout option in /etc/conf.d/net.
dhcpcd_eth0="-t 15"
The default is 60 seconds, way too long. That will at least speed things up a bit. It's how I have my laptop set since I usually use a wireless card which is often inserted after startup. |
|
Back to top |
|
|
jaloha n00b
Joined: 07 Apr 2003 Posts: 35 Location: Honolulu, Hawai'i
|
Posted: Fri Oct 03, 2003 8:08 am Post subject: I agree |
|
|
Dude, I'm with you, this sucks. Fortunately, for you (and me) I wrote something to prevent this problem.
Modify your /etc/init.d/net.eth? as follows:
Change your setup_env functions as follows:
Code: |
setup_env() {
# No reason to check these multiple times in the file
iface="${1/\./_}"
iface_IFACE="$(eval echo \$\{iface_${iface}\})"
dhcpcd_IFACE="$(eval echo \$\{dhcpcd_${iface}\})"
inet6_IFACE="$(eval echo \$\{inet6_${iface}\})"
alias_IFACE="$(eval echo \$\{alias_${iface}\})"
status_IFACE="$(ifconfig | gawk -v IFACE="${iface}" '/Link/ { if ($1 == IFACE) print "up" }')"
vlans="$(eval echo \$\{iface_${IFACE}_vlans\})"
mii_IFACE="$(eval echo \$\{mii_${iface}\})"
}
|
Then modify iface_start to read:
Code: |
iface_start() {
local retval=0
setup_env ${1}
checkconfig || return 1
if [ "${mii_IFACE}" != "false" ]
then
cable_check=`mii-tool ${IFACE} | grep 'link ok'`
if [ -z "${cable_check}" ]
then
eend 1 "Cable not connected, not starting Adapter"
return 1
fi
fi
local IFACE="${1}"
ebegin "Bringing ${IFACE} up"
if [ "${iface_IFACE}" != "dhcp" ]
then
/sbin/ifconfig ${IFACE} ${iface_IFACE} >/dev/null || {
retval=$?
eend ${retval} "Failed to bring ${IFACE} up"
return ${retval}
}
# ifconfig do not always return failure ..
/sbin/ifconfig ${IFACE} &> /dev/null || {
retval=$?
eend ${retval} "Failed to bring ${IFACE} up"
return ${retval}
}
else
# Check that eth0 was not brough up by the kernel ...
if [ "${status_IFACE}" != "up" ]
then
/sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >/dev/null || {
retval=$?
eend ${retval} "Failed to bring ${IFACE} up"
return ${retval}
}
fi
fi
eend 0
if [ -n "${alias_IFACE}" ]
then
local x=""
local num=0
local aliasbcast=""
local aliasnmask=""
ebegin " Adding aliases"
for x in ${alias_IFACE}
do
aliasbcast="$(eval echo \$\{broadcast_${iface}\} \| awk \'\{ print \$$((num + 1)) \}\')"
if [ -n "${aliasbcast}" ]
then
aliasbcast="broadcast ${aliasbcast}"
fi
aliasnmask="$(eval echo \$\{netmask_${iface}\} \| awk \'\{ print \$$((num + 1)) \}\')"
if [ -n "${aliasnmask}" ]
then
aliasnmask="netmask ${aliasnmask}"
fi
ebegin " ${IFACE}:${num}"
/sbin/ifconfig ${IFACE}:${num} ${x} \
${aliasbcast} ${aliasnmask} >/dev/null
num=$((num + 1))
eend 0
done
save_options "alias" "${alias_IFACE}"
fi
if [ -n "${inet6_IFACE}" ]
then
local x=""
ebegin " Adding inet6 addresses"
for x in ${inet6_IFACE}
do
ebegin " ${IFACE} inet6 add ${x}"
/sbin/ifconfig ${IFACE} inet6 add ${x} >/dev/null
eend 0
done
save_options "inet6" "${inet6_IFACE}"
fi
if [ -n "${gateway}" ] && [ "${gateway%/*}" = "${IFACE}" ]
then
ebegin " Setting default gateway"
# First delete any existing routes if it was setup by kernel ..
/sbin/route del default dev ${gateway%/*} &>/dev/null
/sbin/route add default gw ${gateway#*/} dev ${gateway%/*} \
netmask 0.0.0.0 metric 1 >/dev/null || {
local error=$?
ifconfig ${IFACE} down &>/dev/null
eend ${error} "Failed to bring ${IFACE} up"
stop
return ${error}
}
eend 0
fi
# Enabling rp_filter causes wacky packets to be auto-dropped by
# the kernel. Note that we only do this if it is not set via
# /etc/sysctl.conf ...
if [ -e /proc/sys/net/ipv4/conf/${IFACE}/rp_filter ] && \
[ -z "$(egrep '^[^#]*rp_filter' /etc/sysctl.conf 2>/dev/null)" ]
then
echo 1 > /proc/sys/net/ipv4/conf/${IFACE}/rp_filter
fi
}
|
Then add:
or
to your /etc/conf.d/net file according (false to turn checking off and true to turn it on). Of course, change the ? to 0,1,2,etc as appropriate. |
|
Back to top |
|
|
xr31Daisy Guru
Joined: 19 Jul 2002 Posts: 326 Location: Paris, France
|
Posted: Fri Oct 03, 2003 3:32 pm Post subject: |
|
|
I've created different runlevels : - default ( for wireless ),
- cable ( for wired ethernet ), and
- nonetwork
And I've mapped them to different init levels in inittab ( 3, 4 and 5 )
I've created grub entries to boot with the appropriate init level ( a simple integer in the kernel parameters).
It's not exactly what you asked for, since the user selects his favorite network interface, instead of relying on some auto-detection. |
|
Back to top |
|
|
Pinto n00b
Joined: 14 Sep 2003 Posts: 25 Location: Cary, NC
|
Posted: Fri Oct 03, 2003 3:36 pm Post subject: |
|
|
On my system it is setup so I have to dhcpcd for an ip each time so it brings the network card up but doesn't look for it. Some people might call it a pain but it boots quick then all I hav eto do is dhcpcd eth0 and bam I am on. |
|
Back to top |
|
|
jaloha n00b
Joined: 07 Apr 2003 Posts: 35 Location: Honolulu, Hawai'i
|
Posted: Fri Oct 03, 2003 6:58 pm Post subject: Another way |
|
|
As petardi said, ifplugd is also a great solution to this problem. However, I had to hack my ifplugd.action file to make it work with DHCP. I don't know if this is required. If someone else knows a better solution to make it work, please tell me. Also, note that I might have had to do this since I modified the /etc/init.d/net.eth0 file. However, when I removed the code I added to net.eth0, it still failed for me (but I might not have done that perfectly).
cat ifplugd.action :
Code: |
!/bin/sh
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-x86/sys-apps/ifplugd/files/ifplugd.action,v 1.2 2003/03/21 15:58:05 wmertens Exp $
#
# Gentoo-specific ifplugd.action
#
# This file gets called by ifplugd when it wants to bring an interface
# up or down.
#
case "$2" in
up)
state=start
dhcpcd $1
;;
down)
state=stop
kill `cat /var/run/dhcpcd-$1.pid`
;;
*)
echo "$0: wrong arguments"
echo "Call with <interface> <up|down>"
exit 1
;;
esac
# [ -x /etc/init.d/net.$1 ] && /etc/init.d/net.$1 --quiet $state
exit 0
|
|
|
Back to top |
|
|
cephlen n00b
Joined: 14 Jan 2003 Posts: 40 Location: Seattle, WA
|
Posted: Wed Oct 08, 2003 1:08 am Post subject: |
|
|
jaloha's fix works great for me. |
|
Back to top |
|
|
dan2003 Apprentice
Joined: 11 May 2003 Posts: 258 Location: somewhere near london, UK
|
Posted: Sat Oct 25, 2003 8:40 pm Post subject: |
|
|
me too, wicked hack |
|
Back to top |
|
|
MyZelF Bodhisattva
Joined: 25 Feb 2003 Posts: 2010 Location: Venice, Italy
|
Posted: Mon Nov 03, 2003 11:34 pm Post subject: Re: Another way |
|
|
jaloha wrote: | As petardi said, ifplugd is also a great solution to this problem. However, I had to hack my ifplugd.action file to make it work with DHCP.
|
Here's the solution I used:
1) add in the config file /etc/conf.d/ifplugd the options "-a -mm" to ARGS:
Code: | ARGS="-f -u0 -d5 -w -a -mm" |
(you can find here more infos about these options)
2) edit /usr/sbin/ifplugd.action and make it shut down the interface when the cable is unplugged:
Code: | case "$2" in
up)
state=start
;;
down)
state=stop
/sbin/ifconfig $1 down
;;
*)
echo "$0: wrong arguments"
echo "Call with <interface> <up|down>"
exit 1
;;
esac
[ -x /etc/init.d/net.$1 ] && /etc/init.d/net.$1 --quiet $state
exit 0
|
|
|
Back to top |
|
|
Garbz Apprentice
Joined: 02 Jul 2003 Posts: 260 Location: Brisbane, Australia
|
Posted: Tue Nov 04, 2003 12:54 pm Post subject: |
|
|
just to note:
Documentation tips and tricks forum has the following:
1) instuctions for ifplugd
2) a script that allows u to select the desired runlevel from grub so u can choose if eth0 gets loaded depending on it.
3) a script which asks you if you want to enable eth0 when the time comes on boot.
I used to use choice 2 (still do depending if i want to start x or not) i even wrote it : but the best option is to use ifplugd. I've had no problems and it works like a charm. _________________ Every begining is another begining's end. |
|
Back to top |
|
|
MyZelF Bodhisattva
Joined: 25 Feb 2003 Posts: 2010 Location: Venice, Italy
|
Posted: Tue Nov 04, 2003 1:47 pm Post subject: |
|
|
I read those posts! I even created a link to one of them:
MyZelF wrote: |
(you can find here more infos about these options)
|
However, my solution is a little bit different from the one already posted because you don't need to edit /etc/init.d/net.ethX and the interface is brought down by ifplugd.action |
|
Back to top |
|
|
swordsaintzero n00b
Joined: 21 Sep 2003 Posts: 32
|
Posted: Mon Dec 22, 2003 10:58 pm Post subject: For all the n00bs who have copy/pasted jalohas code |
|
|
If the above code failed its because it was missing the "she" of the shebang. In other words !/bin/sh should read #!/bin/sh at the top..
Hope that helps anyone whos not a bash head. _________________ when we do right noone remembers,
when we do wrong noone forgets
-sonny barger |
|
Back to top |
|
|
optilude Apprentice
Joined: 29 May 2002 Posts: 248 Location: England
|
Posted: Tue Dec 23, 2003 4:06 pm Post subject: |
|
|
For those who want different network profiles (e.g. "home" and "work"), and start different network services or configure different options (e.g. wireless WEP keys) for each one, this is exactly the kind of problem I wrote hprofile (http://hprofile.sf.net) to solve!
The tarball, available on the above web site, also comes with example init scripts and profiles for Gentoo linux (including network profiles for wireless and ethernet network connections), so it should be extremely simple to set it up. Have a look at the FAQ and the exaples, and you should be in business. If you do use it, I'd appreciate any feedback, too.
Martin _________________ --
"Life is both a major and a minor key" -- Travis |
|
Back to top |
|
|
|