Auto Linux Installer

for Centos 5.5

by Keith Roberts - keith@karsites.net August 18, 2010

Copyright © Keith Roberts August 2010. All rights reserved. Auto Linux installer bash script code is distributed under the BSD license. Please see the file BSD-LICENSE in the ALI distribution directory. This documentation manual and user guide is NOT distributed under the BSD license, or any other type of open source or ’free to use’ license. You may use this documentation and make copies for YOUR OWN USE only. YOU MAY NOT MAKE ANY DERIVED WORKS OF THIS DOCUMENTATION MANUAL WITHOUT PRIOR WRITTEN PERMISSION.

4

Contents

1 History.  7

2 Introduction and overview.  9

3 Taking a closer look at ALI scripts.  11

4 Customising the ALI scripts  15

5 Using the ALI scripts to do a new Centos installation.  17

6 Configuration File Directory Layout  23

Contents 6

1 History.

Having used Linux since 1999 and done several fresh installations, I started to document things that needed to be set up and configured for each Linux distribution, using an ascii text file. Each time I did a fresh installation I could refer to this text file as a memory jogger. I then added some bash shell snippets and notes on how to configure certain things like email and my custom firewall logs. Having got a system installed and configured I did not look forward to having to go through the whole installation process again for the next OS release. I then hit on the idea of doing a minimal kickstart installation, and instead of sitting at the command line, reading my installation notes and bash shell code snippets and typing that in by hand, I decided to write one post-installation script to automate the rest of the installation process, including restoring my saved configuration files for certain applications, and configuring what system services I wanted to run at boot time. However, using one post-installation script was not practical, as any problems encountered during the running of the script would abort the rest of the installation. I then tried to split the single post-installation script into separate stages. ALI for Centos 5.5 uses 2 stages. Stage 1 configures the new system by building upon a minimal kickstart installation with network connectivity. That’s where most customization work of the scripts needs to be done. When that has finished then it’s safe to run stage2 and install the rest of the system packages. For Centos, stage2 also completes the installation by updating the system packages. Finally, when the system is installed and up and 1 History. running, I check the new configuration files are OK, and make backups of these for the newly installed working Centos system.

2 Introduction and overview.

Auto Linux Installer (ALI) is a set of bash shell scripts to automate a fresh installation of Linux. This version is Currently designed for Centos 5.5 The general idea is to install a new version of the Centos OS with as little user interaction as possible. All the power of shell scripting is involved, so anything you can type as root user in a console will also work in these scripts. It should be possible to convert these scripts to work on any linux system with a shell like bash, and a package manager like YUM.

Once the installation scripts have been setup to run on your system, they will perform an automated installation and re-configuration of your Centos linux system. You can also decide which system services are run at boot time with little user interaction. This is also done with a set bash scripts. This means you can install a newer version of Centos and have it automatically configured and up and running, just like your previous version was, with minimal user interaction and hassle. As each system is different, you need to take care to configure these scripts to work just for your system. Once the scripts have been adjusted to install and configure your system, it is just a simple matter of tweaking them to install newer release of your Centos linux system, or add new applications ans services for subsequent automatic installation.

2 Introduction and overview. 10

3 Taking a closer look at ALI scripts.

The ALI scripts for Centos consist of 2 master bash scripts that call other bash scripts to automate the configuration, package installation and updating of a new Centos system. (There are another set of bash scripts to deal with managing system services. These are explained in a later chapter.) All output from the scripts is written to the display screen, and log files using the ’tee’ command. The master shell scripts for doing a fresh Centos Linux installation are:

• stage1-configure-system.bsh

• stage2-install-packages.bsh

stage1-configure-system.bsh - you need to pay special attention that the scripts called from here are set up according your systems unique requirements. The scripts called here are:

./configure-mc.bsh - copies my saved mc.ini and syntax files to restore my customisations to mc. mc is a norton commander file manager clone, with a nice built in editor.

3 Taking a closer look at ALI scripts.

./configure-resolv.conf.bsh - uninstalls NetworkManager and installs my own custom resolv.conf files. Warning: Comment out the call to this script to keep NetworkManager from being removed, if you want to use NetworkManager and DHCP. Currently, I use static IP4 addresses.

./configure-profile.bsh - copies my own customised file to /etc/profile. ./configure-rc.local.bsh - copies my own customised file to /etc/rc.d/rc.local. The file

rc.local is run last - each time the machine boots up. ./create-users.bsh - creates a couple of new user accounts for me as a single user of this

machine. Multiple user accounts could also be created here if required. ./install-fstab.bsh - installs my own custom /etc/fstab file. Using sed it renames the /

root partition label to match the active root partition for this installation, and then creates matching mount points for entries listed in my custom /etc/fstab. Then it does a test mount of all entries in fstab. The next time the machine is booted this is the active fstab. This script also makes a copy of the default /usr/local/ , to /usr-local.centos5-5.org. This is because I use /usr/local/ as a mountpoint for a partition containing my own programs, and want to keep a record of the default directories and any files in the original /usr/local subdir. You might want to edit the line out that does the copying of /usr/local if you do not need action occuring.

/install-kar-firewall.bsh - uses sed to edit /etc/syslog.conf and change where firewall logs are written to. Shuts down the network service. Turns off Centos ip6tables, and Centos iptables firewall scripts. Installs my own custom iptables firewall script. then restarts network service. Comment this out to continue to use Centos ip6tables, and Centos iptables firewall scripts. Otherwise you will NOT have a firewall running, and be open to all sorts of attacks and hacks from the internet!

./install-RPMforge-repo.bsh - sets up RPMforge repository ./install-ATrpms-repo.bsh - sets up ATrpms repository ./install-EPEL-repo.bsh - sets up EPEL repository ./install-REMI-repo.bsh - sets up REMI repository ./configure-YUM.bsh - installs the yum-priorities plugin, yum-utils package, and my

own custom yum config file used to install all packages in a group. ./get-YUM-repolist.bsh - rebuilds the YUM cache for all available repos. Then outputs

some details about each available repo. It’s all written to the log files for later analysis.

./install-services.bsh - installs some usefull services such as gpm mouse server, proftpd, ssh and others. This is not the same as configuring all the system services that start at boot time. These are some that I needed immediately to configure the Linux installation.

./install-utility-progs.bsh - installs more useful programs that can run without X. Again

used for installing and checking how things are going so far with the installation. stage2-install-packages.bsh - this installs many different packages that are needed

on my system. It also makes copies of the new default Centos config files for certain applications. Then it installs my saved configuration files, hopefully putting the system back to the way it worked previously, on the earlier release of Centos.

3 Taking a closer look at ALI scripts. 14

4 Customising the ALI scripts

A few things need to be setup for the scripts to work correctly. Looking at:

/installer-scripts/stage1-configure-system.bsh
/installer-scripts/stage2-install-packages.bsh

you will notice the following variables:

# -------------------------------------------------- #
# Setup some generic path variables.
# Use these paths from Centos 5.5 root partition.
CONFIG_FILE_PATH="/mnt/F12-home/keith/my-docs/system/Centos/FirstDVDInstall"
ETC_DIR="/etc"
ORG_SUFX=".centos5-5.org"
LOG_FILE="stage1-configure-system.log"
# -------------------------------------------------- #

CONFIG_FILE_PATH - needs to point to where your saved configuration files are. ORG_SUFX - needs to be set to the version number of Centos being installed. This

suffix is appended to any Centos default configuration files, that will be replaced by my own customised config files of the same name.

4 Customising the ALI scripts ETC_DIR and LOG_FILE do not need to be changed.

5 Using the ALI scripts to do a new

Centos installation.

In this chapter we cover how to use the ALI scripts to install Centos from DVD media. It is assumed that you have downloaded the latest Centos DVD iso image, and have burnt it to DVD. I will be using the following partition layout:

Notice that I have two root / partitions. There is a reason for this. Fedora-12-root is a current working system that I can boot into at anytime from the GRUB menu. This 5 Using the ALI scripts to do a new Centos installation.

allows me to retain the previous working Linux system, while installing a newer system over a period of time. If there are any issues with the new system, I still have a working system to fall back on. Also note the /dev/sda13 partition. with the label GrubBoot. This is where I have installed the GRUB boot loader to, instead of the MBR of the hard drive. The procedure to do a fresh Centos installation with the ALI scripts using the above partition layout for me is:

1. Do a minimal Centos installation from the DVD media (either by hand or using a kickstart file in interactive mode). During the installation, select ’Create Custom Layout’ in the partitioner dialogue.

In the partitioner dialogue I select the following partitions for doing a minimal installation:

/dev/sda1   /     Centos-5-root
/dev/sda3         SWAP
/dev/sda12  /tmp  tmp

I purposely do not touch any of the other partitions, to ensure the data on them is not accidently lost during the installation.

Then I only format Centos-5-root and tmp, as ext3 partitions. I Do NOT format SWAP, as it will destroy the existing partition label I have previously set.

However, you may need to format your SWAP partition, if there is not an existing SWAP partition on your system. If you need to set a different label for your swap partition, you can do this later with:

[root]# mkswap -L SWAP /dev/sda3

where SWAP is the partition label name to assign to the swap partition, and /dev/sda3 is the actual swap partition itself. See ’man mkswap’ or ’pinfo mkswap’ for more information.

Just installing the Base package should take ~15 minutes. I also install mc and the bitmap-fonts packages, as these are used for tweaking the rest of the installation. After the intitial minimal installation has finished, you will need to reboot the machine.

If you decide to use mc, and the directory and file colors look a bit odd, you may need to do the following: [root]# setfont lat1-16 To make the change permanent, fire up mc and edit /etc/sysconfig/i18n file to the following value SYSFONT="lat1-16". I have actually configured my kickstart file to do this for me, in the post install part of that script.

Because I have formated /dev/sda1 (Centos-5-root) and /dev/sda12 (tmp) this has erased the partition labels. To recreate these labels after the basic installation has finished, I use the following two commands:

[root]# e2label /dev/sda1 Centos-5-root
[root]# e2label /dev/sda12 tmp

2. When the minimal installation is OK, and the network connection is working, I then reboot the machine and start mc, to create the following mount point;

/mnt/F12-home

3. and mount it with:

5 Using the ALI scripts to do a new Centos installation.

[root]# mount -v -t ext3 -L home /mnt/F12-home

and run /installer-scripts/stage1-configure-system.bsh to setup the system for the rest of the installation process. Then run /services/Get-service-names.bsh to get a list of all currently installed services on the system. Look in the /services/NOTES file for more information on setting up the scripts to configure which services you want run at boot time.

4. Check what’s in stage1-configure-system.log and reboot the system. If you have set up the services-on and services-off text files, you should now be able to boot a minimal system, configured to your specific machine’s requirements. Check the stage1-configure-system.log and if there are any problems, note what needs correcting, fix it and start again at step 1. These first four steps don’t take long, but need to be done correctly, in order for the rest of the installation to proceed successfully.

Once you have made it to step 4, and the minimal system boots OK, you can then proceed with the rest of the installation.

5. Run stage2-install-packages.bsh - this is where the bulk of the packages are installed, after the system has been successfully configured. It consists of calls to other bash shell scripts that perform package installations. Configuration files are also copied where required. The latest versions of Centos default configuration files are saved, if they will be replaced by my own config files. This allows you to compare the latest configuration files to your own customised versions, that you may have installed using the ALI scripts. Output from the scripts is logged to a text file called stage2install-packages.log for later inspection and analysis. You can comment out any subordinate scripts in this master script that you don’t want to run. You can also add your own scripts as required to install more packages, and your own configuration files. Read through this script to get an idea of what it will install by default. I run this script overnight, when there is no download limit from my ISP. Having installed all required packages, I now check the following things are installed and working correctly:

• Apache web server

• PHP

• MySQL in web pages

• MySQL from the CLI monitor

• SQLite in web pages

• Lynx

• pinfo

• Multimedia plugins in Firefox

• Java

• Java man pages

• Java browser plugin

• beanshell

• argouml

• violet-uml

• Centos Eclipse

• phpunit

• phing

• phpdoc

• [email]

• fetchmail

• alpine 5 Using the ALI scripts to do a new Centos installation.

6. Once I’m happy the new system is installed and running OK, I then make backups of all my customised configuration files. These get saved to my home directory, which lives on a separate hard drive partition. The directory layout is explained in the next chapter.

6 Configuration File Directory Layout

This is what my directory layout looks like, where I save my configuration files to. As my /home directory is on a seperate partition, it needs to be mounted before I can access these configuration files.

[root@karsites system]# tree -d -A  -L 7 /home/keith/my-docs/system/Centos/
/home/keith/my-docs/system/Centos/
5.5
FirstDVDInstall
FEDORA-DEFAULT-PACKAGES
apache-2.2.3
    etc-httpd-conf
        original
        tmp-backups
apache-latest -> ./apache-2.2.3
mysql-5.1.48
mysql-latest -> ./mysql-5.1.48
pear
php-5.3.2
php-latest -> ./php-5.3.2
SELF-COMPILED-PKGS
apache-2.2.6
    conf
        extra
        original
            extra

6 Configuration File Directory Layout

        tmp-backups
mysql-5.0.27
    bin
    etc
    server-config
        tmp-backups
php-5.2.4
    tmp-backups
php-5.2.5
    tmp-backups
postgresql-8.2.5
    bin
X11
applnk
fs
rstart
serverconfig
sysconfig
twm
xinit
    Xclients.d
    xinitrc.d
    xinput.d
xsm
alpine-2.00
alpine-latest -> ./alpine-2.00
apcupsd-3.14.3
apcupsd.centos5-5.org
apcupsd-latest -> ./apcupsd-3.14.3
etc-profile
etc-rc.d
etc-resolv
etc-smart

    channels
fetchmail
fstab
grub
init.d
lynx-2.8.5
lynx-latest -> lynx-2.8.5
man
mc
    syntax
        tmp-backups
    syntax.centos5-5.org
mc-keith
mc-root
phing-2.4.1
phpDocumentor-1.4.3
pinfo
postfix-2.3.3
    etc-postfix
syslog
users&groups
usr-local-bin
    tmp-backups
var-lib-smart-1.3
    channels
    packages
vncserver-4.1.3
vncserver-latest -> ./vncserver-4.1.3
yum
    pluginconf.d
yum.repos.d
    tmp-backups
84 directories

6 Configuration File Directory Layout

      [root@karsites system]#