Last Updated: Oct, 17 2002
Suggestions/Comments to: rajeev@rajeevnet.com



Bootprofile for Linux
Booting Linux for desired networked environment selected at boot time.


DISCLAIMER:

THIS SOFTWARE RUNS AS A ROOT AT A VERY EARLY STAGE OF LINUX BOOT. IMPROPER USE OF THIS SOFTWARE MAY CAUSE BOOT PROBLEMS OR OTHER POSSIBLE DAMAGES TO YOUR SYSTEM. USE THIS SOFTWARE AT YOUR OWN RISK. AUTHOR ASSUMES NO RESPONSIBILITY FOR ANY DAMAGE(S) CAUSED BY THE USE OF THIS SOFTWARE.


Sections:



Download latest Version (0.2.3):

Released Under GNU GPL. Download latest version : (bootprofile-0.2.3.tar.gz)
      
    Quick Usage:
    /sbin/bootprofile --test
   /sbin/bootprofile --execute [--noverbose]
 
Also Al Tobey wrote a shell version of bootprofile. Nice if you want to use shell script instead of Perl script. Please refer to his site if you are interested in his version also.

Motivation:

I was using Linux on Laptop in last several years.  Using laptop for office networked environment (with DHCP, NIS, NFS etc.) and for home environment (without DHCP, NIS, NFS but with dialup) was quite a setup task. First I singled out what configuration files have to be changed in different networked environment and the next task was how? Being a sole owner of my laptop with root access I wrote simple shell scripts  for onsite and offsite networked environment and run onsite or offsite script before rebooting  my laptop for next mode (offsite or onsite). This was easy for me but when we started deploying laptops for common users I started searching for better tools for this easy task.  I found few but not satisfying our needs. Few tools like ( Mobile IP from Sun ) , (Dynamic HUT Mobile IP ),  ( NetEnv ) , (divine ) are either in early stage of development or they are mainly centered around  just changing IP address. Our motivation is to change IP address as well as many configuration files those are different based on selected networked environment. Bootprofile achieve this  task by manipulating configuration files at early boot stage of  Linux   before configuring IP address of machine. Bootprofile is written in perl, since this is mainly scripting task so I found perl better than shell script for this project.


How does it work?

Currently bootprofile is tested on RedHat 6.x and RedHat 7.x.  But idea is simple enough to apply to other Linux distributions also. We modify boot script (in Redhat /etc/rc.d/rc.sysinit) such that it will mount root file system in read write mode as a very first steps. THIS IS A VERY CRITICAL AND RISKY STEP SO ONLY EXPERIENCED USERS ARE ENCOURAGED TO DO THIS. IF YOU DO NOT UNDERSTAND WHAT YOU ARE DOING PLEASE STOP NOW . (Normal Redhat rc.sysinit script mounts root file system in read/write mode very late, I don't find any reason why?).  We put /sbin/bootprofile (Perl Script)  just after mounting root  / in read/write mode.  At boot time just  after mounting root in read/write mode bootprofile present user a dialog box to select desired bootprofiles (already setup earlier). Based on user selection it takes action for particular bootprofile (like running commands, copying config files etc.)  and after that it starts booting up machine based for selected bootprofile. There are four actions defined in bootprofile configuration file.
[chkconfig]  :: Will run chkconfig command to activate/deactivate services registered under chkconfig. See chkconfig(1) on how to register your service under chkconfig.
[files] :: Will copy(overwrite) files from source -> target defined.
[links] :: Will create symbolic links based on defined_target  symlink.
[remove] :: Remove any mentioned file/dir/link
[scripts] :: Run your scripts defined under this section.


Example: (/etc/bootprofile/homenet/homenet.profile)
[chkconfig]
2345    ypbind          off
2345    sendmail        off
2345    amd             off
[files]
fstab                   /etc/fstab
syslog.conf             /etc/syslog.conf
resolv.conf             /etc/resolv.conf
static-routes           /etc/sysconfig/static-routes
network                 /etc/sysconfig/network
ifcfg-eth0              /etc/sysconfig/network-scripts/ifcfg-eth0
 
[links]
/usr/local.offsite              /usr/local
 
[remove]
/etc/rc.d/rc3.d/S98networker
/etc/rc.d/rc5.d/S98networker
[scripts]
 /root/myscript


When bootprofile got executed at boot time  based on above example configuration it takes following actions:
############################################################
/sbin/chkconfig --level 2345    ypbind          off
/sbin/chkconfig --level 2345    sendmail        off
/sbin/chkconfig --level 2345    amd             off
/bin/cp /etc/bootprofile/homenet/fstab                  /etc/fstab
/bin/cp /etc/bootprofile/homenet/syslog.conf            /etc/syslog.conf
/bin/cp /etc/bootprofile/homenet/resolv.conf            /etc/resolv.conf
/bin/cp /etc/bootprofile/homenet/static-routes          /etc/sysconfig/static-routes
/bin/cp /etc/bootprofile/homenet/network                        /etc/sysconfig/network
/bin/cp /etc/bootprofile/homenet/ifcfg-eth0             /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/rm -f /usr/local
/bin/ln -s /usr/local.offsite           /usr/local
/bin/rm -f /etc/rc.d/rc3.d/S98networker
/bin/rm -f /etc/rc.d/rc5.d/S98networker
/root/myscript
############################################################
after that it runs remaining boot process based on changes made above by boot profile.
 
 


Screen Shots:

Following Screen shows bootprofile dialog box  with 2 profiles (1)onsite  (2)homenet after these profiles have been set under /etc/bootprofile/{onsite,homenet}/<{onsite,homenet}>.profile and running command /sbin/bootprofile --execute
bootprofile screen shot


 


Prerequisite:

[1] perl binary located in /usr/bin/perl . If you have other location for perl, it is recommended to copy atleast perl binary to this location. bootprofile uses simple perl interpreter, it doesn't require any perl module. If you have /usr as separate partition it may not be mounted at very early stage of boot process, in such cases put perl in  /bin/perl (and modify bootprofile script for your perl path). Idea is perl must be available on / root file system at very early stage of boot.
[2] Linux dialog(1) command must  present on Linux distribution by default. Run command
           dialog --msgbox  "Hello World" 20 60
    if it shows dialog box to you  that's  a good sign.
[3] chkconfig(1): RedHat uses this program  to switch off/on services from various run levels. It is good to have this.
[3] You need to modify initial boot script  and make sure you mount root (and other system partition) file system at very early stage and put /sbin/bootprofile just after that. See example modified boot script ( /etc/rc.d/rc.sysinit )  for RedHat 7.0.
 
 


Installation and Setup Steps: (RedHat 6.x, 7.x)
 

BOOTPROFILE="ON"
TIMEOUT="0

(OFF : if you don't want bootprofile to be active even if it is installed)
(Not implemented yet)


TODO:

Very much dependent upon the usage of bootprofile. If it could generate enough interest I may add following features in future release. So if you find bootprofile useful,  drop me a note and I will get motivated to add and document new features. Your suggestions/corrections are most welcome.


BUGS:

    Since it is a first release and a very quick hack it may not fit according to your requirements,  so you may call this software buggy in such cases do mention that to me and I will try to make this program less buggy. Some  other bugs I could anticipate.



Version Logs:



Copyright © 2002 Rajeev Kumar (rajeev@rajeevnet.com)