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.
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.
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
[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)
Login as root.
Download latest version of bootprofile from 'bootprofile' home page http://www.rajeevnet.com/linux/bootprofile/index.html . This mainly include 'bootprofile' perl script. contrib section includes rc.sysinit for tested platforms and documentation. Untar it and copy bootprofile perl script as /sbin/bootprofile.
Backup your current /etc/rc.d/rc.sysinit as
/etc/rc.d/rc.sysinit.orig. Replace with downloded or edit
manually file /etc/rc.d/rc.sysinit, such that you mount
root filesystem as read/write at very early stage of Linux boot.
At first time it is wise to comment out bootprofie line.
Reboot system and
make sure you didn't break your boot process.
THIS IS VERY IMPORTANT AND RISKY STEP SO BE
CAREFUL!!
Create bootprofile configuration file /etc/sysconfig/bootprofile. with following parameters.
|
BOOTPROFILE="ON" |
(OFF : if you don't want
bootprofile to be active even if it is installed) |
Create a directory /etc/bootprofile
Now create directory for each <profilename>. Also create configuration file for each <profilename> as <profilename>.profile . For example if you want to create <profilename> as " onsite " do following steps. As a first and safe step create profile based on your current setup.
#mkdir -p /etc/bootprofile/onsite
#vi
/etc/bootprofile/onsite/onsite.profile
# Extenstion must be .profile
Put following four sections lines in "onsite.profile " file. Add actions for each sections based on your requirement for this boot profile. See Example above section.
[chkconfig]
[files]
[links]
[remove]
[scripts]
[chkconfig] ::
Purpose: Switch OFF/ON services registered under
chkconfig. See chkconfig(1) for more details.
Syntax:
(One action perl line)
run_levels
service_name on/off
Example:
2345
ypbind
off
bootprofile will run command
/sbin/chkconfig
--level 2345 ypbind
off
[files] ::
Purpose: Copy(Overwrite) critical configuration files for
this bootprofile.
Syntax: (One action per line)
Source_file(relative to bootprofile directory)
Dest_file(full path)
Example :
fstab
/etc/fstab
bootprofile assumes
source in /etc/bootprofile/<profilename>/
directory. (Example: /etc/bootprofile/onsite/fstab ). This
file /etc/bootprofile/onsite/fstab is a desired /etc/fstab
for bootprofile <onsite> . bootprofile will
run corresponding command:
/bin/cp
/etc/bootprofile/homenet/fstab
/etc/fstab
[links] ::
Purpose: Create Symbolic links (Will delete existing
symbolic link if present)
Syntax:
(One Action perl Line)
target_file/dir(full path)
symbolic_link(full path)
Example:
/usr/local.onsite
/usr/local
bootprofile will run corresponding command as:
/bin/rm -f /usr/local
/bin/ln -s /usr/local.offsite /usr/local
[remove] ::
Purpose:: Remove file/directory.
Syntax: (One Action perl line)
file/dir(to be removed)
Example:
/etc/rc.d/rc3.d/S98networker
bootprofile will run command like:
/bin/rm -f /etc/rc.d/rc3.d/S98networker
[scripts] ::
Purpose: Run Userdefined scripts.
Syntax: (One script path per line)
script_full_path (script must reside on system
partition like / (root)
Example:
/home/myscript
bootprofile will simply execute above
script.
After creating bootprofile, test (dry run) profile and make sure commands shown as an output were desired commands for bootprofile.
#/sbin/bootprofile --test
(Select desired
profile and hit OK).
Once you are satisfied with bootprofile setup, it is time to run bootprofile in execute mode. THIS WILL ACTUALLY CHANGE FILES AND CONFIGURATION ON RUNNING SYSTEMS BASED ON BOOTPROFILE. It is advisable to keep backup copy of any files you are overwriting because of bootprofile in case you want to restore old files.
#/sbin/bootprofile --execute.
Reboot system and check if next reboot will bring you as per new profile. If not just figure out what extra needs to be changed. If reboot was okay, then it is time to put/uncomment bootprofile entry in rc.sysinit script.
Put/Uncomment bootprofile entry ( /sbin/bootprofile --execute ) in /etc/rc.d/rc.sysinit script. See this Example.
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.
Better Error checks.
TIMEOUT implementation.
Faisafe bootprofile.
Clear screen at boot time after bootprofile
Your suggestions :-)
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.
Your Linux installation may have different filesystems for / , /usr in such cases make sure your bootprofile actions(configuration file for profiles) are not referencing/manipulating on filesystems(area) that is not available at very early stage of boot as read/write. Al Tobey wrote a shell version of bootprofile which overcomes the limitation of separate /usr partition. Check his website.
dialog(1) program used in bootprofile, may behave different for your Linux distribution.
Actions taken by particular bootprofile are permanent. Example: Suppose you have two boot profiles (1)onsite (2)homenet. <homenet> has ypbind turned off. So if you go in <homenet> profile it will turn off ypbind service. After that you go in <onsite> profile at next reboot, ypbind will remain turned off unless you already added an action to turn on ypbind in <onsite> bootprofile. So you need to be careful when you are using many bootprofiles any action defined in any profile must have corresponding entry in all other profiles also.
First Release (ver 0.1) : Jan 18,2001
Released (ver 0.2): Mar 26, 2002
Released (ver 0.2.1): Jun 11 2002
Released (ver 0.2.2): Oct 15 2002
Released (ver 0.2.3): Oct 17 2002
Copyright © 2002 Rajeev Kumar (rajeev@rajeevnet.com)