|
Linux Multi-locality Boot Profiles |
Shawn Bakker, sbakker@tscnet.com |
When I bought my first laptop computer one of the first things I did was run fips and create a couple partitions to install Slackware 4.0 Linux on it. Once I got every thing running including the PCMCIA network card I had also purchased I thought "This is it, it can't get any better" Then I took my laptop to the office and plugged it into the lan there and ran netconfig to install the right network setting to work at the office. Realizing I would have to do this again when I got home and plugged back into my LAN there I started wondering if there wasn't an easier way. I looked around the web for a while and didn't find what I really wanted so I pretty much figured OK I will just live with it for the time being. Then one day when I was poking around in the /proc filesystem I noticed something that looked really usefull. I noticed that the file /proc/1/environ listed the lilo boot image label that I had used to boot my computer. What follows is the way I came up with to exploit this information.
![]()
When I had first installed the PCMCIA modules on my computer I had to edit the /etc/pcmcia/network.opts file and now I decided this was the place to start. I made several copies of the file, one for each place I might plug into a network and named them accordingly...
network.opts.hostname1
network.opts.hostname2
etc...
Next I edited each file with the proper network information for that network connection so that is looked something like this (network addresses changed).
# Use DHCP? [y/n] DHCP="n" # Host's IP address, netmask, network address, broadcast address IPADDR="192.168.1.1" NETMASK="255.255.255.0" NETWORK="192.168.1.0" BROADCAST="192.168.1.255" # Gateway address for static routing GATEWAY="192.168.128.1" # Things to add to /etc/resolv.conf for this interface DOMAIN="mynet.com" SEARCH="mynet.com" DNS_1="192.168.128.10" DNS_2="" DNS_3=""
Next I modified my /boot/lilo.message file
so that it would display a menu of choices of my hostnames and I
created matching entries in my /etc/lilo.conf file as shown below.
/boot/lilo.message
^L #clears screen Welcome to my laptop Please choose your poison from the options below. 1 - Win98 ------------------------------LINUX IDENTITIES -------------------------------- 2 - Hostname1 3 - Hostname2 4 - Hostname3
/etc/lilo.conf
Notice I used the same boot image
(/vmlinuz} for all the linux options. The only thing I changed was
the label to make it correspond to the menu in the lilo.message file.
Then I re-ran lilo to set the changes.
That done all that remained was to get the
information from /proc and utilize it during the boot process. I
decided the best place to do this would be the rc.pcmcia script in
the /etc/rc.d directory. I added my code just under the "#
Source PCMCIA configuration, if available" section after the fi
command. Here is what I added.
Trying 207.227.252.197...
message=/boot/lilo.message
delay = 300
prompt
vga = 6
other = /dev/hda1
label = 1
table = /dev/hda
image = /vmlinuz
root = /dev/hda2
label = 2
read-only
image = /vmlinuz
root = /dev/hda2
label = 3
read-only
image = /vmlinuz
root = /dev/hda2
label = 4
read-only
#set up network options
BOOT_IMG=`/bin/cut -d= -f4 /proc/1/environ` # parses the boot image label
case "$BOOT_IMG" in
2) echo "Setting up Hostname1"
cp /etc/pcmcia/network.opts.hostname1
/etc/pcmcia/network.opts
echo "hostname1.mynet.com" > /etc/HOSTNAME
;;
3) echo "Setting up Hostname2"
cp /etc/pcmcia/network.opts.hostname2
/etc/pcmcia/network.opts
echo "hostname2.mynet.com" > /etc/HOSTNAME
;;
4)
echo "Setting up Hostname3"
cp /etc/pcmcia/network.opts.hostname3
/etc/pcmcia/network.opts
echo "hostname3.othernet.com" > /etc/HOSTNAME
;;
esac
/bin/hostname -F /etc/HOSTNAME
Now all I have to do when I go to the
office and plug into the lan there is select the proper boot profile
from the lilo menu and away I go!
This page produced
Aug. 18 1999 Using Star Office and Slackware Linux