LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Multiple network configurations at boot time. HOW? (https://www.linuxquestions.org/questions/linux-general-1/multiple-network-configurations-at-boot-time-how-153043/)

FairyFighter 03-03-2004 11:27 AM

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 :Pengy:

moses 03-03-2004 01:01 PM

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. . .

Oliv' 03-03-2004 01:03 PM

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 ;)

moses 03-03-2004 01:13 PM

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).

FairyFighter 03-03-2004 02:38 PM

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?

FairyFighter 03-03-2004 02:50 PM

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?

FairyFighter 03-03-2004 02:57 PM

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...

:newbie:

moses 03-03-2004 03:52 PM

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.

FairyFighter 03-04-2004 02:16 AM

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... :rolleyes:

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

moses 03-04-2004 10:23 PM

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. . .

FairyFighter 03-05-2004 07:30 PM

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...

moses 03-06-2004 12:26 AM

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! =-}

FairyFighter 03-06-2004 07:10 PM

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 :p ...
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.

moses 03-06-2004 11:20 PM

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. =-}

FairyFighter 03-10-2004 05:04 AM

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 ;)


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