LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-03-2004, 12:27 PM   #1
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Rep: Reputation: 15
Multiple network configurations at boot time. HOW?


Hi there,

Guys I have done some searching in here and could not find answer to my question. Here is my definition of what I am intend to do:
When my Laptop starts I have this Lilo menu with two choices, Linux and WinXP.
Then I liked to modify it a bit to something like this:
- LinuxWork
- LinuxHome
- LinuxDHCP
- WinXP
no problem so far, I added those options into Lilo menu without any problems.
So next idea was to pass an parameter that is telling my Linux to use different network configuration files.
Before that I created few additional config files:
- rc.inet1.work.conf
- rc.inet1.home.conf
- rc.inet1.dhcp.conf
It can be that names are bit different(i can not see them becouse I am working on WinXP at the moment) but it is idea that I try to explain.
So if I look at rc.inet1.conf, I can see that it calls an external file to get system network configuration. Once again do not try to fix your self on names of files, I am typing out of my head...

so my idea is this:
- LILO promts
- I choose an option (LinuxDHCP)
- My rc.d network configuration files read my boot option and configurates my network.

now... how do I acomplish that??? How can I pass any information to my system?

I hope that I was clear about my explanation and that You can help me. Sorry for my English.

thanks for any hints
Fairy

PS
Pleas do not post anything to switching to GRUB or any other options like that, I like to stick with my Lilo
 
Old 03-03-2004, 02:01 PM   #2
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
This isn't as easy as it maybe should be. The kernel can be told to run a small DHCP client,
but when it does this it also expects the root filesystem to be NFS mounted. . .
The kernel command line doesn't allow for passing parameters on to the rest of the system, but
one option is to abuse this command line.
In your /etc/lilo.conf, for each "image=" section (each section you describe above, LinuxWork, etc.), have an "append=" line with one of the options (If you have a default/global "append=", you need to include all of the options from the global "append=" in your specific "append=" lines) one that you know will be ignored by the kernel, but that describes where you are. For example:
Code:
image = /boot/vmlinuz-2.6.2
  root = /dev/hda1
  label = LinuxWork
  append="idebus=66 ide0=dma Location=Work"
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
In your network set up script, look for your Location in /proc/cmdline:
Code:
#!/bin/sh
Location=`cat /proc/cmdline | awk 'BEGIN {RS = " " } {FS = "="} { if ($1 == "Location") print $2}'`

case "$Location" in

  'Work') 
      Set up network for work
      ;;
  'Home') 
      Set up network for home
      ;;
  'DHCP') 
      Set up network via DHCP
      ;;
  *) 
      Do default stuff
      ;;
esac
Good luck. . .
This may be dangerous if, for example, the kernel developers decide that Location is a reserved word for some reason. . .

Last edited by moses; 03-03-2004 at 02:06 PM.
 
Old 03-03-2004, 02:03 PM   #3
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Compile 3 differents kernel, each time with a different EXTRAVERSION flag. Then you can choose which config to load in function of uname -a output
 
Old 03-03-2004, 02:13 PM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
After reading my post above, I realized that this is essentially already done for you via the "label=" option in /etc/lilo.conf. . .
if you cat /proc/cmdline, you'll notice that the parameter BOOT_IMAGE= has a value that is the label given in your /etc/lilo.conf, so you don't have to abuse the kernel command line, you just change the search for Location= to a search for BOOT_IMAGE=, and the rest is similar to my post above (except that you don't need to use the append= option for each image).
 
Old 03-03-2004, 03:38 PM   #5
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
tnx moses you feel me :-)

but You lost me...
this is my lilo.conf:
...
image = /boot/vmlinuz
root = /dev/hdc4
label = Work
read-only
image = /boot/vmlinuz
root = /dev/hdc4
label = Home
read-only
image = /boot/vmlinuz
root = /dev/hdc4
label = DHCP
read-only
...

so if I understand You well, now I have to look into my /proc/cmdline and find something in it... correct? if so then I have bad news there is nothing in it...
or I am missing something?
 
Old 03-03-2004, 03:50 PM   #6
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
moses, hold a sec...

after reading your post over and over again... I found this out:
I have to write this script into file: /proc/cmdline
am I correct?
 
Old 03-03-2004, 03:57 PM   #7
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
if so... I can not write anything in it... file is 444
so as I am new to Linux; I do not know of I may play with this file just liek that and change promissions...

 
Old 03-03-2004, 04:52 PM   #8
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
No, you add it to your network initialization script. Your network init script currently has one setup procedure (maybe one static and one DHCP) for your network device, and you'll have to change the script to reflect the fact that you want it to do different things depending on where you say you are. So, you'll have to modify the file so that it first checks to see where you are (by looking at /proc/cmdline, pulling out the label of your boot option, and naming that something like "Location"), then does the appropriate thing, which depends on where you say you are.
So, your lilo.conf has the labels, Work, Home, and DHCP. This means that if you
Code:
cat /proc/cmdline
you'll get something like this:
Code:
auto BOOT_IMAGE=Work ro root=301
So, you would want to start the "Work" network setup portion of the network initialization script. This is done using the case statement as described above. Put all the necessary initialization stuff into each of the cases (Work, Home, DHCP). You'll first need to do the bit of arcane magic to give Location the correct value, which is described above. . . You can copy your current network script (make a backup), and just basically make two copies of what it does now (for the static setup), one for Work and one for Home, and then enclose the DHCP setup stuff within the DHCP case. . .

Hope this helps.
 
Old 03-04-2004, 03:16 AM   #9
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
Thumbs up

me bows to moses!!!

Man, You made my day (night actually...). I like to thank You very much for this very helpfully informations and understanding.

As my problem is solved, I like to post my config files that rest of the community can use it too.

Once again the idea:
- by choosing a boot profile in LILO we determine what network configuration will we use.

So here is my lilo.conf:
Code:
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
boot = /dev/hdc
message = /boot/boot_message.txt
prompt
timeout = 1200
# VESA framebuffer console @ 800x600x64k
vga=788
# End LILO global section
# Linux bootable partition config begins
image = /boot/vmlinuz
  root = /dev/hdc4
  label = WorkNetwork
  read-only
image = /boot/vmlinuz 
  root = /dev/hdc4
  label = HomeNetwork
  read-only
image = /boot/vmlinuz
  root = /dev/hdc4
  label = DHCP
  read-only
other=/dev/hdc2
    label = WinXP
    table=/dev/hdc
# Linux bootable partition config end
and my rc.inet1:
Code:
# Get the configuration information from /etc/rc.d/rc.inet1.conf:
# . /etc/rc.d/rc.inet1.conf
BOOT_IMAGE=`cat /proc/cmdline | awk 'BEGIN {FS = "="} { if ($1 == "BOOT_IMAGE") print $2}' | awk 'BEGIN {FS = " "} {print $1}'`
case "$BOOT_IMAGE" in
 'WorkNetwork')
# Config information for eth0:
	IPADDR[0]="193.0.0.101"
	NETMASK[0]="255.255.255.0"
	USE_DHCP[0]=""
	DHCP_HOSTNAME[0]=""
	# Default gateway IP address:
	GATEWAY="193.0.0.50"
	DEBUG_ETH_UP="no"
	;;
 'HomeNetwork')
	IPADDR[0]="192.168.123.201"
	NETMASK[0]="255.255.255.0"
	USE_DHCP[0]=""
	DHCP_HOSTNAME[0]=""
	# Default gateway IP address:
	GATEWAY="192.168.123.201"
	DEBUG_ETH_UP="no"
	;;
 'DHCP')
	IPADDR[0]=""
	NETMASK[0]=""
	USE_DHCP[0]="yes"
	DHCP_HOSTNAME[0]=""
	# Default gateway IP address:
	GATEWAY=""
	DEBUG_ETH_UP="no"
	;;
esac
...
as You can see it is VERY easy to do it!!! Especially if moses is helping you...

I am not saying that this is most clean solution but it is good start to make it work.

moses thank You very much

cheerz
Fairy

Last edited by FairyFighter; 03-04-2004 at 04:36 AM.
 
Old 03-04-2004, 11:23 PM   #10
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Code:
cat /proc/cmdline | awk 'BEGIN {FS = "="} { if ($1 == "BOOT_IMAGE") print $2}' | awk 'BEGIN {FS = " "} {print $1}'
I'm confused about why you chose to do it this way. . . I don't actually get any result from this command. What version of awk are you using?

To explain why I'm confused, here's the result of cat /proc/cmdline on my machine:
Code:
auto BOOT_IMAGE=Slack9_262 ro root=301 idebus=66 ide0=dma ide1=dma
So, using my awk command:
Code:
cat /proc/cmdline | awk 'BEGIN {RS = " "} {FS= "=" } { if ($1 == "BOOT_IMAGE") print $2}'
This first sets the record separator to the space character (so each parameter-value pair is a new, separate record). It then sets the field separator to the "=" character, so that the parameter-value pair is split up. If the parameter is named "BOOT_IMAGE", I print out the value (Slack9_262, in this case).

Your way (using the awk on my machine, GNU Awk version 3.1.1) actually first sets the field separator to "=" (so I have only one record, which is the entire line), this means that my $1 will never actually be equal to "BOOT_IMAGE" because the first field is,
"auto BOOT_IMAGE"
Since the first field doesn't match, the "print $2" never happens, so I get a NULL piped to the second awk. This means that the second awk command doesn't parse anything and all I get is a NULL.

Just curious. . . I assume your command works for you, which really has me wondering what are the differences between our machines. . .

Last edited by moses; 03-04-2004 at 11:26 PM.
 
Old 03-05-2004, 08:30 PM   #11
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
here you go:

Code:
cat /proc/cmdline
BOOT_IMAGE=HomeNetwork ro root=1604
1.my machine with your command:
2. my machine with my command
Code:
cat /proc/cmdline | awk 'BEGIN {FS = "="} { if ($1 == "BOOT_IMAGE") print $2}' | awk 'BEGIN {FS = " "} {print $1}'
HomeNetwork
as You can see output from cat is different...
sorry that I did not explained that before...
 
Old 03-06-2004, 01:26 AM   #12
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Thanks! I screwed up with my awk statement. . . Try this:

Code:
awk 'BEGIN {RS = " "; FS = "=" } {if ($1 == "BOOT_IMAGE") print $2}'
It should work for any format cmdline (well, it works for the format you sent and the format I have, and should work for any where you can separate the records you want by spaces and the fields by "="). The problem was that for your formatted cmdline the FS="=" was only happening on the second record because it wasn't specifically stated as part of the BEGIN statement. . .

My bad. . . Thanks! =-}
 
Old 03-06-2004, 08:10 PM   #13
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
Talking

Actually it is funny... I do not know thing about awk or stuff in /proc/...
But with your help, moses, I have laptop that works great at my work and at home ...
As I sed I am n00b in Linux world, but one thing I have learned about Linux is that it is harder to get it optimized but it is possible to optimized it VERY well.

I have still some things that I will like to improve on my Laptop but one step at the time.
Even more funny is fact that most people that I know are saying that Slack is hard to use... My answer is: Once You Slack You never go back. This laptop of mine I put CD-ROM in it, half hour later Slack was working

moses, thank You for your help.
 
Old 03-07-2004, 12:20 AM   #14
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
Good luck!
Remember to return the favor by helping someone else whenever you can. That's the way (and really, the only way) Linux will stay alive and well. =-}
 
Old 03-10-2004, 06:04 AM   #15
FairyFighter
LQ Newbie
 
Registered: Jul 2003
Location: Antwerp/Belgium
Posts: 22

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by moses
Remember to return the favor by helping someone else whenever you can. That's the way (and really, the only way) Linux will stay alive and well. =-}
That is my next idea ... I was thinking of creating some n00b enabled home page with some basics of what, how and wher can You do with Linux (configurating stuff, upgrading management...)
But this one is a bit far call... But present on my wish list
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing and selecting multiple configurations qscomputing Linux - General 2 09-17-2005 04:00 AM
How do I Managing multiple X configurations using GDM AntWarrior Linux - Software 2 04-22-2005 07:41 PM
nmap finding c++ compiler/ network configurations nanoprobe SUSE / openSUSE 2 04-07-2005 04:32 PM
Two network configurations, dial-up and static IP? sia Linux - Networking 1 05-24-2004 06:31 PM
Multiple networking configurations with RedHat 9? pelakh Linux - Networking 0 05-19-2004 10:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration