View previous topic :: View next topic |
Author |
Message |
mrness Retired Dev
Joined: 17 Feb 2004 Posts: 375 Location: bucharest.ro
|
Posted: Mon Aug 16, 2004 4:14 pm Post subject: HOWTO: switch laptop network configuration from boot params |
|
|
This article describe how to make your laptop to boot with parameterized network configs.
I've wanted to make my laptop boot with various configurations, depending on the location, so I've looked at quickswitch package but it felt too non-gentooish so I've taked a peek in /sbin/rc and /sbin/functions.sh from which I've drawn following conclusions:
runlevel/bootlevel could be changed by adding "softlevel=$level"/"bootlevel=$level" to boot params. Granted, bootlevel isn't likely to be changed since all runlevels should have a common boot part, but softlevel is interesting - its nice to boot in other runlevel than default. rc could read boot params set by "gentoo=$params". For example, if you have devfsd & udev installed but don't want to use neither of these, just add "gentoo=nodevfs,noudev". However, no one says we couldn't create our own flags, like "dhcp". in /etc/conf.d/net we could define 4 functions that /etc/init.d/net.ethx executes when the time comes: preup, postup, predown, postdown. All these functions have as first (and only) parameter the name of the interface.
Having this knowledge, a person with reasonable experience in bash scripting could easily customize /etc/conf.d/net after his needs. In case of a laptop which has static IP setup at home and DHCP configuration at other places, this file will look like:
Code: |
if get_bootparam dhcp; then
iface_eth0="dhcp"
else
iface_eth0="a.b.c.d broadcast a.b.c.0 netmask 255.255.255.0"
gateway="eth0/a.b.c.254"
fi
function preup() {
if [ $1 = "eth0" ]; then
if [ "$iface_eth0" = "dhcp" ]; then
ln -sf fstab.dhcp /etc/fstab
ln -sf resolv.conf.dhcp /etc/resolv.conf
else
ln -sf fstab.home /etc/fstab
ln -sf resolv.conf.home /etc/resolv.conf
fi
fi
}
|
All you have to do is duplicate your GRUB/LILO entry and add "gentoo=dhcp" to boot parameters! |
|
Back to top |
|
|
Cuardin l33t
Joined: 06 Feb 2003 Posts: 713 Location: vasastaden.stockholm.se
|
Posted: Wed Aug 18, 2004 10:58 am Post subject: |
|
|
This could actually prove very helpful. Not that I need different network settings as I only use stationary comp, but with this one could perhaps implement cascading runlevels. _________________ Part of "The adopt an unanswered post initiative" |
|
Back to top |
|
|
depontius Advocate
Joined: 05 May 2004 Posts: 3509
|
Posted: Thu Dec 09, 2004 3:04 am Post subject: cascading runlevels |
|
|
Cuardin wrote: | This could actually prove very helpful. Not that I need different network settings as I only use stationary comp, but with this one could perhaps implement cascading runlevels. |
I want cascading runlevels.
I want to bring up eth0, and check what IP it got. It's a piece of cake to tell if it's my home lan, the lan at work, or a lan somewhere else, or no network at all. (I've got a way to eliminate, not reduce, the dhcp timeout, too. Use mii-diag to look for a link-beat before even trying dhcpcd.)
I don't want to do this with a boot option, because I want to be getting coffee while the computer boots, not waiting to get through BIOS and the grub prompt. This is machine work, not human work. "/sbin/ifconfig eth0 | grep -q -e "inet addr:(work or home subnet)" is most of what it takes, plus a little wrapped logic.
The ideal thing would be to use local.start to do the ip checking, and then something like "rc netHome" or "rc netWork" to chain "default" into the appropriate new runlevel.
But I've read enought /sbin/rc to know that that's not really how things work. There's a PILE of scanning, preprocessing, and caching done in /var/lib/init.d, and the real work is done there, not in /etc/runlevels. The initscript documentation in sys-apps/baselayout looks like it's just SysV, instead of the dependency stuff in Gentoo. So I'm not sure where the Gentoo scripts are documented.
Offhand, it looks to me as if in order to cascade runlevels you'd have to re-run the caching stuff at the cascade point, and the other problem would be keeping the old stuff in place for shutdown. Maybe it would be easier to change {svcdir} to /var/lib/cascade, or rename the original /var/lib/init.d, and recognize that the new runlevel would have to swizzle things back in order to shut down.
Is there any serious discussion of cascading runlevels going on?
Can someone point me to more detailed documentation, or is it UTSL? _________________ .sigs waste space and bandwidth |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|