Multiple network configurations at boot time. HOW?
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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. . .
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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).
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?
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...
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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. . .
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. . .
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. . .
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
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
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. =-}
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.