#!/usr/bin/env perl # # Rachael, the replicator -- a kickstart config file generator # # 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. # # Think of this as generating a template ks.cfg file which you can # edit and tweak once you have it. # # The name comes from the Rachael character from Blade Runner. # Rachael was a "replicant". (Whether Deckard was a replicant is # debatable, the "director's cut" notwithstanding. :-) # # The original version of this script was developed for work on the # ATLAS Grid Testbed cluster at the University of Michigan. - 15 March 2001 # Further development took place to suport the ROBOT Beowulf cluster # in the Physics Departmet at Vassar College. - 3 April 2004 # # Eric Myers # Spy Hill Research, Poughkeepsie, New York 12603 # Copyright (C) 2001-2007 by Eric Myers, all rights reserved. # @(#) $Id: Rachael,v 2.3 2004/04/03 15:41:54 myers Exp myers $ ####################################################################### ## # CONFIGURATION: # If installation is via NFS then these parameters are used: # $NFSserver="143.229.45.111"; # host serving RedHat CD $NFSdir="/home/ftp/pub/linux/redhat/7.3/"; # Where it is $NFSroot="/net/robot"; # How WE get to it for verification # If installation is via FTP then these parameters are used: # $FTPserver="143.229.45.111"; # host serving RedHat CD $FTPdir="/pub/linux/redhat/7.3/"; # Where it is there. # If installation is via CDROM then these parameters are used: # $CDkspath="/isolinux/ks.cfg"; $CDFileList="FC6_packages.txt"; # For static network parameters (no DHCP available) these are used: # $IPaddr="192.168.1.86"; $NetMask="255.255.255.0"; $Gateway="192.168.1.1"; $NameServer="192.168.1.1"; #############################################################33 # BEGIN: # Set the path just to what is needed nothing else. $ENV{"PATH"}="/usr/local/adm:/usr/local/bin:/bin:/usr/bin:/usr/etc "; ## # Process command line options use Getopt::Long; GetOptions('nfs' => \$opt_nfs, 'ftp' => \$opt_ftp, 'cdrom' => \$opt_cdrom, 'dhcp' => \$opt_dhcp, 'static' => \$opt_static, 'verbose' => \$opt_verbose, 'with-part' => \$opt_with_part, 'package-list=s' => \$CDFileList); # Defaults if nothing specified. if( !$opt_cdrom && !$opt_nfs && !$opt_ftp ) { $opt_cdrom=1; } if( !$opt_dhcp && !$opt_static ) { $opt_static=1; } if( $opt_cdrom && ! -f $CDFileList ){ print "! Cannot find list of packages $CDFileList \n"; exit 2; } ## # Start the Kickstart configuration file print "* Creating ks.cfg... \n"; open(OUT,">ks.cfg"); $USER= $ENV{'USER'}; chop( $Date = `date` ); chop( $hostname = `uname -n` ); chop( $kernel = `uname -r -m` ); print OUT <<"EOF_HEAD" # ks.cfg - kickstart configuration file for Fedora/Red Hat Linux # Generated on $Date by $USER # from $hostname (kernel $kernel) ####################################################################### # Kickstart commands: # Install or Upgrade? install text # Interactive will ask to verify; good for debugging, but omit otherwise #interactive ### Language/Localization Specifications: lang en_US langsupport en_US keyboard us mouse generic3ps/2 --device psaux timezone US/Eastern ### Authorization/Authentication: shadow passwords and MD5 are good authconfig --enableshadow --enablemd5 # (since this is publicly known you must CHANGE THE ROOT PASSWORD soon!) rootpw pASSword firewall --disabled ### X Configuration is optional ### Will set up system for minimal resolution and color depth; ### may wish to run Xconfigurator manually after system installation #xconfig --card "Matrox G450" --videoram 32MB --hsync .0 --vsync 60 --resolution 1600x1200 --depth 24 #xconfig --server "SVGA" --monitor "Sun 17-inch 447Z" #skipx xconfig --startxonboot # Bootloader is GRUB unless you say --useLilo bootloader --location=mbr zerombr yes EOF_HEAD ; ## # Installation method: print OUT "\n### Installation Method: nfs, url(ftp), or cdrom\n"; if( $opt_cdrom ) { if( $opt_verbose ) { print "* CDROM installation. \n"; } print OUT "cdrom \n"; } elsif ( $opt_nfs ) { if( $opt_verbose ) { print "* NFS installation. \n"; } print OUT "nfs --server $NFSserver --dir $NFSdir \n"; } elsif ( $opt_ftp ){ if( $opt_verbose ) { print "* FTP installation. \n"; } print OUT "url --url ftp://$FTPserver$FTPdir \n"; } ## # Network configuration: print OUT "\n### Network Configuration: static or dhcp? \n"; if( $opt_static ) { if( $opt_verbose ) { print "* Network configuration: static. \n"; } print OUT "network --bootproto static --ip $IPaddr --netmask $NetMask --gateway $Gateway --nameserver $NameServer --hostname kick-me\n"; } elsif ( $opt_dhcp ) { if( $opt_verbose ) { print "* Network configuration: dynamic. \n"; } print OUT "network --bootproto dhcp --hostname kick-me \n"; } ## # Disk Partitions: print OUT << "EOF_PART" ## # Partitioning Information # Which partitions to format (--linux/--all) # --linux - only format existing linux partitions # --all - format ALL existing partitions (including Windows!) # clearpart --linux # Which partitions to set up on new system as well as sizes. # These are samples we have used for RH7.3, edit to your own taste. # (should code it to replicate disk partitions someday...) # partition /boot --size 112 --fstype=ext3 --asprimary partition swap --recommended --asprimary partition / --size 512 --fstype=ext3 partition /usr --size 4096 --fstype=ext3 partition /tmp --size 512 --fstype=ext3 partition /var --size 512 --fstype=ext3 partition /home --size 1024 --fstype=ext3 EOF_PART ; ## # Packages: print OUT <<"EOF_PACKAGES" ####################################################################### # Packages: # ### The package names, as well as the groups they are a part of ### can be found on the first CD in /cdrom/repodata/comps.xml. ### Individual packages can be specified by entering their names one per line; ### Groups (e.g. 'base-x') can be specified by appending a "\@" in front ### of the group name; e.g. '\@ base-x' %packages EOF_PACKAGES ; ## # Core packages we want on just about any system. # (You can, of course, edit ks.cfg by hand after it is generated.) print OUT <<"EOF_GROUPS" @ core @ base @ base-x @ admin-tools @ system-tools @ emacs @ mail-server @ mysql @ engineering-and-scientific @ network-server -telnet-server -rsh-server @ printing @ server-cfg @ web-server EOF_GROUPS ; print "* Creating package list... \n"; $N_pkg=0; $N_pkg_parse=0; $N_pkg_err=0; $N_pkg_ok=0; # start with list of all installed packages # chop( @pkg_list = `rpm -qa` ); # Verify each is actually both installed and available # foreach $pkg ( @pkg_list ) { $N_pkg++; ( $pkg_name, $pkg_vers ) = $pkg =~ /([-+\w]+)-(\d+[-_\.a-zA-Z\d]+)$/; if ( ! $pkg_name ) { print "ERROR: cannot parse \"$pkg\" \n"; $N_pkg_parse++; next; } # Is the package really on the system (or parse error?) # $RC = system "rpm -q $pkg_name >/dev/null 2>&1"; if ( $RC != 0 ) { print OUT "## Cannot verify that $pkg is actually installed.\n"; $N_pkg_err++; next; } # Is this package in the repository? if( $opt_nfs ){ $Repository="$NFSroot$NFSdir/RedHat/RPMS/"; $search_command="ls $NFSroot$NFSdir/RedHat/RPMS/$pkg_name* "; } elsif( $opt_cdrom ){ $Repository="$CDFileList "; # TODO: THIS IS CRUDE AND HAS FALSE POSITIVES. FIX IT. $search_command="grep -q -s $pkg_name $CDFileList "; } $RC = system "$search_command >/dev/null 2>&1"; if ( $RC != 0 ) { if( $opt_verbose ){ print OUT "## Cannot find $pkg_name ($pkg ?) in $Repository \n"; } print "Unvavailable: $pkg_name ($pkg ?) not in $Repository \n"; $N_pkg_err++; next; } print OUT "$pkg_name \n"; if( $opt_verbose ) { print "$pkg_name \n"; } $N_pkg_ok++; } ## # Pre-installation script print "* Adding pre-processing commands... \n"; print OUT << "EOF_PRE" ####################################################################### # Pre-installation commands # Processed after ks.cfg has been parsed, but before it's executed. # This is NOT run in the chroot environment. # This is where you would copy scripts or files from the installation media. %pre df > /root/ks-pre-df.txt %end EOF_PRE ; ## # Post-Processing script print "* Adding post-processing commands... \n"; print OUT <<"EOF_POST" ####################################################################### # Post processing: # This IS run in the chroot environment. # You therefore do not have access here to the installation media. %post --nochroot echo "Linux installation still in progress..." > /mnt/sysimage/etc/motd df > /mnt/sysimage/root/ks-post-df.txt %end EOF_POST ; print "$N_pkg packages considered from this host ($hostname) . \n"; print "$N_pkg_ok packages could be installed. \n"; if( $N_pkg_parse > 0) { print "$N_pkg_parse package names could not be parsed. \n"; } if( $N_pkg_err > 0) { print "$N_pkg_err packages could not be found in repository. \n"; } print OUT "###END###\n"; print "Done. \n"; exit;