字体:  

Kickstart Installation on Red Hat/Fedora Core Linux

ELM 发表于: 2008-4-16 21:48 来源: 榆树社区

http://www.spy-hill.com/~myers/linux/kickstart/

        Kickstart is a system for automated installation of Red Hat Linux or Fedora Core Linux. Instead of answering all the installation questions manually, one can put configuation information and packages selection into a file which is read and executed by the installation program. This page provides general information, links and some tools for creating or manipulating kickstart configuration files and boot images.

        A separate page describes the "Kick Me" boot configuration disks in more detail.
        Last updated: Sunday, 03-Apr-2005 11:27:20 EDT

    Red Hat Linux comes with a system for automatic installation called Kickstart. Instead of answering all the installation questions manually, including all the details of package selection, you can put your answers and list of packages into a file which will automatically be read by the installation program at startup. This can be very useful for installing a specific known configuration on a collection of machines, such as a grid cluster or a Beowulf cluster. It is also fairly easy to copy files or run shell scripts non-interactively to customize the installation.

    Listed below are:

        * A link to the Kick Me disk
        * Kickstart boot disk images
        * Sample Kickstart configuration file (ks.cfg)
        * Information on alternate consoles
        * Post-installation processing - files and scripts
        * Rachael script to "clone" a machine
        * Randy script to help edit a custom initial RAM disk

    The scripts Rachael and Randy are pretty rough and should only be used as guides for helping you make your own Kickstart configurations. This is not highly automated or easy or clean. Good luck (you'll need it).

    Documentation about Kickstart is available from Red Hat at:

        http://www.redhat.com/docs/manua ... /ch-kickstart2.html

    Note that there have been some changes to the configuration files commands between RH 6.x and RH 7.x. Most notably, an FTP installation used to be done with the ftp command but is now performed using the url command. The current examples are for RH 7.3, but I plan to update them to Fedora Core 3 when I can.

    Kick Me disks
    "Kick Me" is a floppy disk image created to perform a custom installation of Red Hat or Fedora Core Linux over the network using Kickstart. Details of the "Kick Me" disk can be found here

    Kickstart Disk Images
    The disk images at the link below are slightly modified version of the standard Red Hat or CERN boot disks. They include a ks.cfg configuration file, but you can also replace this with your own modified version if you like. Here is how to use these images.

       1. Download one of these disk images as a binary file (you'll probably need to right-click on the link to download):

              "Kick-Me" Kickstart Boot Disk Image 1.11 for Red Hat Linux 7.3 (as of 5 October 2003)
              Kickstart Boot Disk Image for CERN Red Hat Linux 7.2.1 (as of 1 July 2002)
              Kickstart Boot Disk Image for Red Hat Linux 6.2 (as of 18 December 2001)

       2. Copy it to a floppy, as with:

              dd if=kick-me-X.X.img of=/dev/fd0 bs=1k

       3. Mount the floppy disk (it's in FAT format) and edit the file ks.cfg to your liking. Comments are included to help. You should at least change your NFS or FTP server IP address and the path to the RedHat directory, or you'll end up trying to load from mine (which probably won't work).

       4. Boot from that flopppy, and at the boot prompt enter

              linux ks=floppy

    Sample Configuration File
    A copy of this file, or something close to it, is already on the boot disk image, but I've put a copy here so that you can look through it without having to get the disk image.

        ks.cfg

    This file is for the CERN/Red Hat Linux 7.2.1 installations for our ATLAS Grid Testbed site.

    You should consider this as just a starting point for building your own ks.cfg file. In the least, you should edit it to change the networking and server information.

    Alternate Consoles
    A lot of information is made available during the installation process on alternate consoles. Press ALT and a function key to switch to a different console. This is especially useful if the installation fails, because you can get more detailed error messages this way, or even a shell.

    Console 1 (ALT-F1): graphical installation status (what's normally shown during installation).

    Console 2 (ALT-F2): bash shell (once the installation has progressed far enough).

    Console 3 (ALT-F3): Installation progress log, including module insertion. The cause of an error can often be found here.

    Console 4 (ALT-F4): Appears to be a log of raw device/SCSI information.

    Console 5 (ALT-F5): Appears to be a log of filesystem operations.

    Post-installation processing
    It is possible to run shell commands after package installation. It is even possible to copy over files via FTP and install them, and to run shell scripts that have been copied over. Here is an outline of how our installation system works at U-M:

       1. First, a few simple commands are executed from the ks.cfg file to copy over other files via FTP. (See the example ks.cfg file for an example of how this is done non-interactively. Look for the commands at the end of the file, after the %post directive.)
       2. One of the files is linatX-install.tar which is unpacked under / to put configuration files in place.
       3. Another file is a script called ks.sh which is copied to /root and then run to finish the configuration process.
       4. The file /etc/rc.d/rc.local is also run once to finish configuration (and then it replaces itself with a simpler version of itself).

    Rachael - creating a custom configuration file
    This script will copy the configuration of a Red Hat Linux machine into a kickstart configuration file ks.cfg so that you can use it for a kickstart installation to make a replica of the original machine. The main thing it does is create a list of installed packages. It tries to verify that they are actually available from the installation source, which may or may not be too restrictive. (A Kickstart installation will fail if a package in the list of those to install is not available.)

        Rachael

    The name comes from the Rachael character from Blade Runner. She was was a "replicant". (Whether Deckard was a replicant is debatable.)

    The current version of Rachael creates a Kickstart file for RH 6.2, but I will probably update it for RH 7.2 soon.

    Randy - creating a custom initial RAM disk
    The original point of this script was to make a copy of an initial RAM disk (initrd) from one of the RedHat installation bootdisks while making it possible to remove unneeded modules to make space on the disk for a Kickstart configuration file. But you can also use it to add modules for devices that are not included in the original boot disk.

    Note: This is not an automatic tool, it just provides a lot of assistance. You still have to know what the hell you are doing.

        Randy

    If you are at the point of digging into this kind of thing in earnest then you may want to read the script /sbin/mkinitrd (and the man page for it) for a better idea of how an initrd is constructed.

    Eric Myers <myers@vassar.edu>         5 August 2003

最新回复

ELM at 2008-4-16 21:55:06
#!/bin/sh
#
# One-Shot installation customization via the rc.local file

# This script will be executed *after* all the other init scripts.
# This version gets run ONCE and then replaces itself with something else,
# if it exists
#
# @(#) Last changed: -EAM 23Jul2003

sleep 1            
clear
echo "  "
echo "  Kick-Me: ONE TIME ONLY rc.local INITIALIZATION..."
echo "  "


####################
## Hostname and Network:

X=`egrep "^HOSTNAME=" /etc/sysconfig/network`
if [ "$X" = "" -o "`hostname`" = "kick-me" ]; then
  echo "  "
  echo "  "
  echo -n "  Enter new hostname: "
  read HOSTNAME
  echo $HOSTNAME
  echo "HOSTNAME=$HOSTNAME" >> /etc/sysconfig/network
  hostname $HOSTNAME
  echo "  "

  # check for fixed IP address for linux-install.vassar.edu
  # and reconfig if not found

  X=`egrep "^IPADDR  /etc/sysconf/network-scripts/ifcfg-eth0`
  if [ "$X" = ""  -o   "$X" = "IPADDR=143.229.45.104" ]; then
    netconfig
  else
    echo "  You will have to reconfigure the IP address yourself"
    echo "  To do so, give the command \`netconfig\` "
  fi

  # restart services to use new setting

  killall dhcpcd

  service network restart
  service syslog restart
  service portmap condrestart
  service nfslock condrestart
  service ypserv  condrestart
  service ypbind  condrestart
fi

##
# record disk size, etc

grep MHz /proc/cpuinfo > /tmp/cpu
logger -s  -p user.notice -f /tmp/cpu

grep MemTotal /proc/meminfo > /tmp/mem
logger -s  -p user.notice -f /tmp/mem

fdisk -l /dev/hda | grep cylind > /tmp/cyls
logger -s  -p user.notice -f /tmp/cyls

cat /tmp/cpu /tmp/mem /tmp/cyls |   mail -s `hostname` root


####################
## Make an emergency boot disk (just in case...)  NOT FOR LINUX 2.6 ?

clear
echo "  "
echo "  MAKING AN EMERGENCY BOOT DISK."
echo "  "

mkbootdisk `uname -r`

echo "  "
echo "  PLEASE REMOVE THE DISK BEFORE THE NEXT REBOOT."
echo "  "


####################
## Update the tripwire (if we can)

TWDIR=/var/spool/lpd/czech

if [ -d $TWDIR ]; then
  cd $TWDIR
  if [ -d databases ]; then
    cd databases
    mv -f tw.db_`hostname`  tw.db_`hostname`.old
    cd ..
  fi
  echo " * Initializing Tripwire 1.2L...   "
  ./tripwire -q -c ./tw.config  -initialize
fi

if [ -x /usr/local/adm/Nigel ]; then
  cd /usr/local/adm
  ./Nigel -reset
fi


####################
## The real rc.local (or none at all)

rm /etc/rc.d/rc.local
if [ -f /etc/rc.d/rc.local.new ]; then
  mv -f /etc/rc.d/rc.local.new /etc/rc.d/rc.local
#  cd /etc/rc.d
#  . rc.local
fi


####################

clear
echo "  "
echo "  ONE-TIME INITIALIZATION FINISHED.  Thank You for Your PATIENCE. "
echo "  "
echo "  Please remove the emergency boot disk and press ENTER to reboot..."
echo "  "
read X

shutdown -h now

exit 0

##EOF
ELM at 2008-4-16 21:56:18
#!/bin/sh
#
# Kick-start post-configuration script, to do the configuration things
# that need to be done.  See also /etc/rc.d/rc.local which may do
# one-time configuration at first reboot, before it replaces itself.
#
# This file is loaded by ks.cfg from the ftp server, not from the floppy.
# The TARBALL specified below is also loaded via ftp, as is rc.local.
#
# Eric Myers <myers@umich.edu> - 14 December 2001
# #(@) $Id: ks.sh,v 1.3 2003/06/26 19:13:50 myers Exp myers $
######################################################################
# @(#) Last changed: -EAM 03Apr2005

TARBALL=kick-me-install.tar

# Be sure no mail daemons are running

service sendmail stop
service postfix stop


####################
# Make custom directories and mount points:

mkdir -p /root/rpm/updates
mkdir -p /floppy/
mkdir -p /cdrom

############
# Configuration changes/cleanup:

cd /etc/cron.daily
  rm 00-logwatch
  chmod -x logrotate

cd /var/spool/rwho
  rm -f *-gig
  rm -f *localhost


####################
# Services (init scripts) for boot time:

chkconfig ypbind off
chkconfig portmap off
chkconfig nfslock off
chkconfig nfs off
chkconfig netfs off
chkconfig amd off

chkconfig ipchains off
chkconfig sendmail off
chkconfig postfix  off

chkconfig wine   off
chkconfig pcmcia off

chkconfig rwhod on
chkconfig ntpd  on

chkconfig condor   off
chkconfig afs      off


####################
# Install and configure autorpm, to use it now, and always

cd /root/rpm
X=`ls -1 autorpm*rpm`
if [ "$X" != "" ]; then
  echo " * Installing autorpm..."
  rpm -Uhv $X
else
  echo " ! Cannot find autorpm package :-( "
fi
echo "  "


##############
# Unpack the tar file (copied by ks.cfg) to quickly configure the system

if [ -f /root/$TARBALL.gz ]; then
  echo " * Unpacking the tar file $TARBALL ..."
  gunzip /root/$TARBALL
  cd /  
  tar -xvf /root/$TARBALL
else
  echo " ! Cannot find configuration tarball $TARBALL :-( "
fi
echo "  "


##############
# Put newer rc.local (copied by ks.cfg) in place for first reboot

cd /root
echo "  "
if [ -f rc.local ]; then
  /bin/mv -f rc.local /etc/rc.d/rc.local
  chmod +x /etc/rc.d/rc.local
  echo " * Installed one-shot rc.local from /root"
fi


####################
# Install locally selected package and update RH/FC packages with autorpm
# (Assumes untar'd Otto-rpm-?.conf files already in place.)

if [  -f /etc/autorpm.d/Otto-rpm.conf  ]; then
  echo " * Updating packages via autrpm..."
  cd /etc/autorpm.d
  cp autorpm.conf autorpm.conf,ORIG

  # Replace main config file with our own, which uses #'s 5 & 6
  cat <<EOF > autorpm.conf
# /etc/autorpm.d/autorpm.conf created by ks.sh on `date`
# UPDATE FROM PACKAGES COPIED VIA FTP DURING INSTALLATION
Set_Var("ReportDest", "root");
Set_Var("Arch", "i686|i586|i386|noarch");
Set_Var("Lang", "en");
Eval_Var("RHVersion", "sed 's/\(Red Hat Linux \)\?release \([^ ]*\) (.*)/\2/' /etc/redhat-release");
Eval_Var("FedoraVersion", "rpm -q fedora-release | awk -F'-' {'print $3'}");
Report_Queues_To ("\${ReportDest}");

Config_File("/etc/autorpm.d/Otto-rpm-5.conf");       
Config_File("/etc/autorpm.d/Otto-rpm-6.conf");       
Config_File("/etc/autorpm.d/autorpm-updates.conf");       
Config_File("/etc/autorpm.d/openafs.conf");       

#EOF autorpm.conf
EOF

# Invoke autorpm to do the work

  autorpm "auto --print "

# Now put in place the network version for later

  cp Otto-rpm.conf autorpm.conf

fi

##########
# Add nsf:/usr/local to the filesystem table to join the club

X=`grep /usr/local /etc/fstab`
if [ "$X" = "" ]; then
   cat <<EOF >>/etc/fstab
# added by ks.sh on `date`
santiam:/usr/local       /usr/local         nfs     defaults 0 0
EOF
fi


####################
# Prepare for reversible kernel upgrade later by saving this one

KVERS=2.6

cd /boot
mkdir -p Save
/bin/cp -f *${KVERS}* Save/

cd /lib/modules
mkdir -p Save
/bin/cp -rp ${KVERS}* Save/


####################
# Change LILO boot message & #read-only  (though we now use GRUB)

if [ -f /boot/boot.txt ]; then
  cd /etc
  cp lilo.conf lilo.conf.ORIG
  sed -e "s%^message=.*$%message=/boot/boot.txt%" \
      -e "s/[ \t]*read-only/        read-only/" \
      < lilo.conf.ORIG > lilo.conf
  echo " * Modified /etc/lilo.conf, now calling lilo..."
  if [ ! -z /etc/lilo.conf ]; then
    lilo
  fi
fi



####################
# We are done

chmod -x /root/ks.sh

echo " * ks.sh finished."

exit 0

# EOF